summaryrefslogtreecommitdiff
path: root/gi/pygi-info.c
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2013-10-04 13:41:08 -0700
committerSimon Feltman <sfeltman@src.gnome.org>2013-10-07 14:41:28 -0700
commitc86b2fe8d01070f06c45fffd910d890afba1313a (patch)
tree0d8c8becbd33e0845174e0278a0f9921187e3040 /gi/pygi-info.c
parente7b758badd0ab0b147117859f7871c39fb5399c1 (diff)
downloadpygobject-c86b2fe8d01070f06c45fffd910d890afba1313a.tar.gz
Add GIBaseInfo.equal method
Break PyGIBaseInfo rich compare into two methods: equal and richcompare. Equal is a direct exposure of the GI method and richcompare makes use of this with additional support for Pyton "==" and "!=" operators. https://bugzilla.gnome.org/show_bug.cgi?id=709008
Diffstat (limited to 'gi/pygi-info.c')
-rw-r--r--gi/pygi-info.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index db963a07..30c6a7a3 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -152,25 +152,40 @@ _base_info_repr (PyGIBaseInfo *self)
}
static PyObject *
-_base_info_richcompare (PyGIBaseInfo *self, PyObject *other, int op)
+_wrap_g_base_info_equal (PyGIBaseInfo *self, PyObject *other)
{
- PyObject *res;
GIBaseInfo *other_info;
- if (!PyObject_TypeCheck(other, &PyGIBaseInfo_Type)) {
- Py_INCREF(Py_NotImplemented);
+ if (!PyObject_TypeCheck (other, &PyGIBaseInfo_Type)) {
+ Py_INCREF (Py_NotImplemented);
return Py_NotImplemented;
}
other_info = ((PyGIBaseInfo *)other)->info;
+ if (g_base_info_equal (self->info, other_info)) {
+ Py_RETURN_TRUE;
+ } else {
+ Py_RETURN_FALSE;
+ }
+}
+
+static PyObject *
+_base_info_richcompare (PyGIBaseInfo *self, PyObject *other, int op)
+{
+ PyObject *res;
switch (op) {
case Py_EQ:
- res = g_base_info_equal (self->info, other_info) ? Py_True : Py_False;
- break;
+ return _wrap_g_base_info_equal (self, other);
case Py_NE:
- res = g_base_info_equal (self->info, other_info) ? Py_False : Py_True;
- break;
+ res = _wrap_g_base_info_equal (self, other);
+ if (res == Py_True) {
+ Py_DECREF (res);
+ Py_RETURN_FALSE;
+ } else {
+ Py_DECREF (res);
+ Py_RETURN_TRUE;
+ }
default:
res = Py_NotImplemented;
break;
@@ -270,6 +285,7 @@ static PyMethodDef _PyGIBaseInfo_methods[] = {
{ "get_name_unescaped", (PyCFunction) _wrap_g_base_info_get_name_unescaped, METH_NOARGS },
{ "get_namespace", (PyCFunction) _wrap_g_base_info_get_namespace, METH_NOARGS },
{ "get_container", (PyCFunction) _wrap_g_base_info_get_container, METH_NOARGS },
+ { "equal", (PyCFunction) _wrap_g_base_info_equal, METH_O },
{ NULL, NULL, 0 }
};