diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | glib/glibmodule.c | 2 | ||||
-rw-r--r-- | glib/pyglib-python-compat.h | 6 | ||||
-rw-r--r-- | gobject/gobjectmodule.c | 16 | ||||
-rw-r--r-- | gobject/pygenum.c | 16 | ||||
-rw-r--r-- | gobject/pygflags.c | 28 |
6 files changed, 56 insertions, 28 deletions
@@ -1,5 +1,21 @@ 2008-07-27 Johan Dahlin <johan@gnome.org> + * glib/pyglib-python-compat.h: + Add a Py_TYPE macro for accessing ob_type. + * glib/glibmodule.c (pyglib_register_constants): + * gobject/gobjectmodule.c (pygobject__g_instance_init), + (pyg_integer_richcompare): + * gobject/pygenum.c (pyg_enum_repr), (pyg_enum_from_gtype), + (pyg_enum_add), (pyg_enum_get_value_name), + (pyg_enum_get_value_nick): + * gobject/pygflags.c (pyg_flags_repr), (pyg_flags_from_gtype), + (pyg_flags_add), (pyg_flags_and), (pyg_flags_or), (pyg_flags_xor), + (pyg_flags_get_first_value_name), (pyg_flags_get_first_value_nick), + (pyg_flags_get_value_names), (pyg_flags_get_value_nicks): + Use Py_TYPE and PyLong macros to access struct fields + +2008-07-27 Johan Dahlin <johan@gnome.org> + * gobject/gobjectmodule.c (pyg_param_spec_from_object), (add_properties), (pyg_signal_new), (pyg_signal_list_ids), (pyg_signal_lookup), (pyg_signal_query): diff --git a/glib/glibmodule.c b/glib/glibmodule.c index 9228057..1f3194c 100644 --- a/glib/glibmodule.c +++ b/glib/glibmodule.c @@ -519,7 +519,6 @@ pyglib_set_prgname(PyObject *self, PyObject *args) return Py_None; } - static PyMethodDef _glib_functions[] = { { "spawn_async", (PyCFunction)pyglib_spawn_async, METH_VARARGS|METH_KEYWORDS }, @@ -623,7 +622,6 @@ pyglib_register_version_tuples(PyObject *d) static void pyglib_register_constants(PyObject *m) { - PyModule_AddIntConstant(m, "SPAWN_LEAVE_DESCRIPTORS_OPEN", G_SPAWN_LEAVE_DESCRIPTORS_OPEN); PyModule_AddIntConstant(m, "SPAWN_DO_NOT_REAP_CHILD", diff --git a/glib/pyglib-python-compat.h b/glib/pyglib-python-compat.h index c36f7e4..0fb4601 100644 --- a/glib/pyglib-python-compat.h +++ b/glib/pyglib-python-compat.h @@ -28,7 +28,7 @@ typedef int Py_ssize_t; /* Compilation on Python 2.x */ #if PY_VERSION_HEX < 0x03000000 - +#define RO READONLY #define _PyUnicode_Check PyString_Check #define _PyUnicode_AsString PyString_AsString #define _PyUnicode_AsStringAndSize PyString_AsStringAndSize @@ -42,9 +42,10 @@ typedef int Py_ssize_t; #define _PyLong_Check PyInt_Check #define _PyLong_FromLong PyInt_FromLong #define _PyLong_AsLong PyInt_AsLong -#define RO READONLY #define _PyLongObject PyIntObject #define _PyLong_Type PyInt_Type +#define _PyLong_AS_LONG PyInt_AS_LONG +#define Py_TYPE(ob) (ob->ob_type) #else #undef PYGLIB_MODULE_START #undef PYGLIB_MODULE_END @@ -96,6 +97,7 @@ PyTypeObject symbol = { \ #define _PyLong_Check PyLong_Check #define _PyLong_FromLong PyLong_FromLong #define _PyLong_AsLong PyLong_AsLong +#define _PyLong_AS_LONG PyLong_AS_LONG #define _PyLongObject PyLongObject #define _PyLong_Type PyLong_Type #endif diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 0ec1382..7fb9154 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -1045,7 +1045,7 @@ pygobject__g_instance_init(GTypeInstance *instance, wrapper = pygobject_new_full(object, FALSE, g_class); args = PyTuple_New(0); kwargs = PyDict_New(); - if (wrapper->ob_type->tp_init(wrapper, args, kwargs)) + if (Py_TYPE(wrapper)->tp_init(wrapper, args, kwargs)) PyErr_Print(); Py_DECREF(args); Py_DECREF(kwargs); @@ -2306,7 +2306,6 @@ pyg_set_object_has_new_constructor(GType type) g_type_set_qdata(type, pygobject_has_updated_constructor_key, GINT_TO_POINTER(1)); } -#define GET_INT(x) (((_PyLongObject*)x)->ob_ival) PyObject * pyg_integer_richcompare(PyObject *v, PyObject *w, int op) { @@ -2314,12 +2313,12 @@ pyg_integer_richcompare(PyObject *v, PyObject *w, int op) gboolean t; switch (op) { - case Py_EQ: t = GET_INT(v) == GET_INT(w); break; - case Py_NE: t = GET_INT(v) != GET_INT(w); break; - case Py_LE: t = GET_INT(v) <= GET_INT(w); break; - case Py_GE: t = GET_INT(v) >= GET_INT(w); break; - case Py_LT: t = GET_INT(v) < GET_INT(w); break; - case Py_GT: t = GET_INT(v) > GET_INT(w); break; + case Py_EQ: t = _PyLong_AS_LONG(v) == _PyLong_AS_LONG(w); break; + case Py_NE: t = _PyLong_AS_LONG(v) != _PyLong_AS_LONG(w); break; + case Py_LE: t = _PyLong_AS_LONG(v) <= _PyLong_AS_LONG(w); break; + case Py_GE: t = _PyLong_AS_LONG(v) >= _PyLong_AS_LONG(w); break; + case Py_LT: t = _PyLong_AS_LONG(v) < _PyLong_AS_LONG(w); break; + case Py_GT: t = _PyLong_AS_LONG(v) > _PyLong_AS_LONG(w); break; default: g_assert_not_reached(); } @@ -2327,7 +2326,6 @@ pyg_integer_richcompare(PyObject *v, PyObject *w, int op) Py_INCREF(result); return result; } -#undef GET_INT static void _log_func(const gchar *log_domain, diff --git a/gobject/pygenum.c b/gobject/pygenum.c index bf40cc1..e35f738 100644 --- a/gobject/pygenum.c +++ b/gobject/pygenum.c @@ -64,13 +64,13 @@ pyg_enum_repr(PyGEnum *self) g_assert(G_IS_ENUM_CLASS(enum_class)); for (index = 0; index < enum_class->n_values; index++) - if (self->parent.ob_ival == enum_class->values[index].value) + if (_PyLong_AS_LONG(self) == enum_class->values[index].value) break; value = enum_class->values[index].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)); + sprintf(tmp, "<enum %ld of type %s>", _PyLong_AS_LONG(self), g_type_name(self->gtype)); g_type_class_unref(enum_class); @@ -168,7 +168,11 @@ pyg_enum_from_gtype (GType gtype, int value) retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0); g_assert(retval != NULL); +#if PY_VERSION_HEX >= 0x03000000 +# warning "FIXME: figure out how to subclass long" +#else ((_PyLongObject*)retval)->ob_ival = value; +#endif ((PyGFlags*)retval)->gtype = gtype; //return _PyLong_FromLong(value); } @@ -236,7 +240,11 @@ pyg_enum_add (PyObject * module, PyObject *item, *intval; item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0); +#if PY_VERSION_HEX >= 0x03000000 +# warning "FIXME: figure out how to subclass long" +#else ((_PyLongObject*)item)->ob_ival = eclass->values[i].value; +#endif ((PyGEnum*)item)->gtype = gtype; intval = _PyLong_FromLong(eclass->values[i].value); @@ -284,7 +292,7 @@ pyg_enum_get_value_name(PyGEnum *self, void *closure) 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); + enum_value = g_enum_get_value(enum_class, _PyLong_AS_LONG(self)); retval = _PyUnicode_FromString(enum_value->value_name); g_type_class_unref(enum_class); @@ -302,7 +310,7 @@ pyg_enum_get_value_nick(PyGEnum *self, void *closure) 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); + enum_value = g_enum_get_value(enum_class, _PyLong_AS_LONG(self)); retval = _PyUnicode_FromString(enum_value->value_nick); g_type_class_unref(enum_class); diff --git a/gobject/pygflags.c b/gobject/pygflags.c index f419161..34b328f 100644 --- a/gobject/pygflags.c +++ b/gobject/pygflags.c @@ -33,8 +33,6 @@ GQuark pygflags_class_key; PYGLIB_DEFINE_TYPE("gobject.GFlags", PyGFlags_Type, PyGFlags); -#define GET_INT_VALUE(x) (((_PyLongObject*)x)->ob_ival) - static PyObject * pyg_flags_richcompare(PyGFlags *self, PyObject *other, int op) { @@ -94,13 +92,13 @@ pyg_flags_repr(PyGFlags *self) char *tmp, *retval; PyObject *pyretval; - tmp = generate_repr(self->gtype, self->parent.ob_ival); + tmp = generate_repr(self->gtype, _PyLong_AS_LONG(self)); if (tmp) retval = g_strdup_printf("<flags %s of type %s>", tmp, g_type_name(self->gtype)); else - retval = g_strdup_printf("<flags %ld of type %s>", self->parent.ob_ival, + retval = g_strdup_printf("<flags %ld of type %s>", _PyLong_AS_LONG(self), g_type_name(self->gtype)); g_free(tmp); @@ -192,7 +190,11 @@ pyg_flags_from_gtype (GType gtype, int value) retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0); g_assert(retval != NULL); +#if PY_VERSION_HEX >= 0x03000000 +# warning "FIXME: figure out how to subclass long" +#else ((_PyLongObject*)retval)->ob_ival = value; +#endif ((PyGFlags*)retval)->gtype = gtype; } else { Py_INCREF(retval); @@ -257,7 +259,11 @@ pyg_flags_add (PyObject * module, PyObject *item, *intval; item = ((PyTypeObject *)stub)->tp_alloc((PyTypeObject *)stub, 0); +#if PY_VERSION_HEX >= 0x03000000 +# warning "FIXME: figure out how to subclass long" +#else ((_PyLongObject*)item)->ob_ival = eclass->values[i].value; +#endif ((PyGFlags*)item)->gtype = gtype; intval = _PyLong_FromLong(eclass->values[i].value); @@ -294,7 +300,7 @@ pyg_flags_and(PyGFlags *a, PyGFlags *b) (PyObject*)b); return pyg_flags_from_gtype(a->gtype, - GET_INT_VALUE(a) & GET_INT_VALUE(b)); + _PyLong_AS_LONG(a) & _PyLong_AS_LONG(b)); } static PyObject * @@ -304,7 +310,7 @@ pyg_flags_or(PyGFlags *a, PyGFlags *b) return _PyLong_Type.tp_as_number->nb_or((PyObject*)a, (PyObject*)b); - return pyg_flags_from_gtype(a->gtype, GET_INT_VALUE(a) | GET_INT_VALUE(b)); + return pyg_flags_from_gtype(a->gtype, _PyLong_AS_LONG(a) | _PyLong_AS_LONG(b)); } static PyObject * @@ -315,7 +321,7 @@ pyg_flags_xor(PyGFlags *a, PyGFlags *b) (PyObject*)b); return pyg_flags_from_gtype(a->gtype, - GET_INT_VALUE(a) ^ GET_INT_VALUE(b)); + _PyLong_AS_LONG(a) ^ _PyLong_AS_LONG(b)); } @@ -338,7 +344,7 @@ pyg_flags_get_first_value_name(PyGFlags *self, void *closure) flags_class = g_type_class_ref(self->gtype); g_assert(G_IS_FLAGS_CLASS(flags_class)); - flags_value = g_flags_get_first_value(flags_class, self->parent.ob_ival); + flags_value = g_flags_get_first_value(flags_class, _PyLong_AS_LONG(self)); if (flags_value) retval = _PyUnicode_FromString(flags_value->value_name); else { @@ -360,7 +366,7 @@ pyg_flags_get_first_value_nick(PyGFlags *self, void *closure) flags_class = g_type_class_ref(self->gtype); g_assert(G_IS_FLAGS_CLASS(flags_class)); - flags_value = g_flags_get_first_value(flags_class, self->parent.ob_ival); + flags_value = g_flags_get_first_value(flags_class, _PyLong_AS_LONG(self)); if (flags_value) retval = _PyUnicode_FromString(flags_value->value_nick); else { @@ -384,7 +390,7 @@ pyg_flags_get_value_names(PyGFlags *self, void *closure) retval = PyList_New(0); for (i = 0; i < flags_class->n_values; i++) - if ((self->parent.ob_ival & flags_class->values[i].value) == flags_class->values[i].value) + if ((_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value) PyList_Append(retval, _PyUnicode_FromString(flags_class->values[i].value_name)); g_type_class_unref(flags_class); @@ -404,7 +410,7 @@ pyg_flags_get_value_nicks(PyGFlags *self, void *closure) retval = PyList_New(0); for (i = 0; i < flags_class->n_values; i++) - if ((self->parent.ob_ival & flags_class->values[i].value) == flags_class->values[i].value) + if ((_PyLong_AS_LONG(self) & flags_class->values[i].value) == flags_class->values[i].value) PyList_Append(retval, _PyUnicode_FromString(flags_class->values[i].value_nick)); g_type_class_unref(flags_class); |