From 63e2ce175069bac5a18cda79c59265fb0515338c Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 29 Dec 2017 14:25:34 +0000 Subject: [PATCH] python: Implement comparison of ASes Signed-off-by: Michael Tremer --- src/libloc.sym | 1 + src/python/as.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/libloc.sym b/src/libloc.sym index 47e8f69..25fe5f5 100644 --- a/src/libloc.sym +++ b/src/libloc.sym @@ -1,6 +1,7 @@ LIBLOC_PRIVATE { global: # AS + loc_as_cmp; loc_as_get_name; loc_as_get_number; loc_as_new; diff --git a/src/python/as.c b/src/python/as.c index 3c74f9e..ca0af47 100644 --- a/src/python/as.c +++ b/src/python/as.c @@ -80,6 +80,29 @@ static PyObject* AS_get_name(ASObject* self) { return PyUnicode_FromString(name); } +static PyObject* AS_richcompare(ASObject* self, ASObject* other, int op) { + int r = loc_as_cmp(self->as, other->as); + + switch (op) { + case Py_EQ: + if (r == 0) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; + + case Py_LT: + if (r < 0) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; + + default: + break; + } + + Py_RETURN_NOTIMPLEMENTED; +} + static struct PyGetSetDef AS_getsetters[] = { { "name", @@ -109,4 +132,5 @@ PyTypeObject ASType = { tp_doc: "AS object", tp_getset: AS_getsetters, tp_repr: (reprfunc)AS_repr, + tp_richcompare: (richcmpfunc)AS_richcompare, }; -- 2.39.2