summaryrefslogtreecommitdiffstats
path: root/gobject/pygenum.c
diff options
context:
space:
mode:
authorManish Singh <yosh@gimp.org>2005-11-03 19:15:23 +0000
committerJohan Dahlin <johan@src.gnome.org>2005-11-03 19:15:23 +0000
commit55d03f1c08d4f7624732fab642b4c25a0e76e9d3 (patch)
tree2a1828f654b93eba33dbbc8bfc22367ff7294340 /gobject/pygenum.c
parentd0449bfb71c391fd5b4ac9bc7d344639eda80332 (diff)
downloadpygobject-55d03f1c08d4f7624732fab642b4c25a0e76e9d3.tar.gz
pygobject-55d03f1c08d4f7624732fab642b4c25a0e76e9d3.tar.xz
pygobject-55d03f1c08d4f7624732fab642b4c25a0e76e9d3.zip
reviewed by: Johan Dahlin <jdahlin@async.com.br>
2005-11-03 Manish Singh <yosh@gimp.org> reviewed by: Johan Dahlin <jdahlin@async.com.br> * gobject/gobjectmodule.c: (pyg_integer_richcompare): * gobject/pygenum.c: (pyg_enum_richcompare): * gobject/pygflags.c: (pyg_flags_richcompare): * gobject/pygobject-private.h: Prepare for Python 2.5 richcompare changes, fixes #320455.
Diffstat (limited to 'gobject/pygenum.c')
-rw-r--r--gobject/pygenum.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index aceba9d..aa8907e 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -27,25 +27,22 @@
#include "pygobject-private.h"
-
-#define GET_INT(x) (((PyIntObject*)x)->ob_ival)
-static int
-pyg_enum_compare(PyGEnum *self, PyObject *other)
+static PyObject *
+pyg_enum_richcompare(PyGEnum *self, PyObject *other, int op)
{
- if (!PyInt_CheckExact(other) && ((PyGEnum*)other)->gtype != self->gtype) {
+ if (!PyInt_Check(other)) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+
+ if (PyObject_TypeCheck(other, &PyGEnum_Type) && ((PyGEnum*)other)->gtype != self->gtype) {
PyErr_Warn(PyExc_Warning, "comparing different enum types");
- return -1;
+ return NULL;
}
-
- if (GET_INT(self) == GET_INT(other))
- return 0;
- else if (GET_INT(self) < GET_INT(other))
- return -1;
- else
- return 1;
+
+ return pyg_integer_richcompare((PyObject *)self, other, op);
}
-#undef GET_INT
-
+
static PyObject *
pyg_enum_repr(PyGEnum *self)
{
@@ -293,7 +290,7 @@ PyTypeObject PyGEnum_Type = {
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- (cmpfunc)pyg_enum_compare, /* tp_compare */
+ 0, /* tp_compare */
(reprfunc)pyg_enum_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -308,7 +305,7 @@ PyTypeObject PyGEnum_Type = {
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
- 0, /* tp_richcompare */
+ (richcmpfunc)pyg_enum_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */