diff options
Diffstat (limited to 'gobject')
| -rw-r--r-- | gobject/pygenum.c | 20 | ||||
| -rw-r--r-- | gobject/pygflags.c | 7 |
2 files changed, 14 insertions, 13 deletions
diff --git a/gobject/pygenum.c b/gobject/pygenum.c index 80d241a..17888c8 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -52,16 +52,17 @@ static PyObject * pyg_enum_repr(PyGEnum *self) { GEnumClass *enum_class; - GEnumValue *enum_value; + char *value; static char tmp[256]; enum_class = g_type_class_ref(self->gtype); g_assert(G_IS_ENUM_CLASS(enum_class)); - - enum_value = g_enum_get_value(enum_class, self->parent.ob_ival); - g_assert(enum_value != 0); - - sprintf(tmp, "<enum %s of type %s>", enum_value->value_name, g_type_name(self->gtype)); + + value = enum_class->values[self->parent.ob_ival].value_name; + if (value) + sprintf(tmp, "<enum %s of type %s>", value, g_type_name(self->gtype)); + else + sprintf(tmp, "<enum %ld of type %s>", self->parent.ob_ival, g_type_name(self->gtype)); g_type_class_unref(enum_class); @@ -142,7 +143,12 @@ pyg_enum_from_gtype (GType gtype, int value) retval = PyDict_GetItem(values, PyInt_FromLong(value)); if (!retval) { PyErr_Clear(); - return PyInt_FromLong(value); + retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0); + g_assert(retval != NULL); + + ((PyIntObject*)retval)->ob_ival = value; + ((PyGFlags*)retval)->gtype = gtype; + //return PyInt_FromLong(value); } Py_INCREF(retval); diff --git a/gobject/pygflags.c b/gobject/pygflags.c index 526368a..98e3a9e 100644 --- a/gobject/pygflags.c +++ b/gobject/pygflags.c @@ -80,8 +80,7 @@ pyg_flags_repr(PyGFlags *self) char *tmp, *retval; PyObject *pyretval; - tmp = generate_repr(self->gtype, - self->parent.ob_ival); + tmp = generate_repr(self->gtype, self->parent.ob_ival); retval = g_strdup_printf("<flags %s of type %s>", tmp, g_type_name(self->gtype)); @@ -169,15 +168,11 @@ pyg_flags_from_gtype (GType gtype, int value) if (!retval) { PyErr_Clear(); - return PyInt_FromLong(value); -#if 0 - /* This breaks repr */ retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0); g_assert(retval != NULL); ((PyIntObject*)retval)->ob_ival = value; ((PyGFlags*)retval)->gtype = gtype; -#endif } Py_INCREF(retval); |
