]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
python: Make AS objects hashable
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Jan 2024 18:08:14 +0000 (18:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Jan 2024 18:08:14 +0000 (18:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/as.c

index 4cf99874e4c40a111d5e919dffae622224f797a0..06ba5db305eba4f0f2ea795f2dd9cb31fc921c8d 100644 (file)
@@ -125,6 +125,12 @@ static PyObject* AS_richcompare(ASObject* self, ASObject* other, int op) {
        Py_RETURN_NOTIMPLEMENTED;
 }
 
+static Py_hash_t AS_hash(ASObject* self) {
+       uint32_t number = loc_as_get_number(self->as);
+
+       return number;
+}
+
 static struct PyGetSetDef AS_getsetters[] = {
        {
                "name",
@@ -156,4 +162,5 @@ PyTypeObject ASType = {
        .tp_repr =               (reprfunc)AS_repr,
        .tp_str =                (reprfunc)AS_str,
        .tp_richcompare =        (richcmpfunc)AS_richcompare,
+       .tp_hash =               (hashfunc)AS_hash,
 };