[pygobject] fix up testshelper module so it compiles in python 3.x
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] fix up testshelper module so it compiles in python 3.x
- Date: Wed, 25 Aug 2010 09:28:57 +0000 (UTC)
commit 1dee5dcd2b1747b4a4af438c0443d7930e4802db
Author: John (J5) Palmieri <johnp redhat com>
Date: Tue Aug 17 02:14:14 2010 -0400
fix up testshelper module so it compiles in python 3.x
* include the compat header
* fix up PyInts to be PYGLIB_Long
* Use PYGLIB_DEFINE_TYPE macros to define module objects
* Use PYGLIB_MODULE_START/END to define modules
https://bugzilla.gnome.org/show_bug.cgi?id=615872
tests/Makefile.am | 2 +-
tests/testhelpermodule.c | 221 ++++++----------------------------------------
2 files changed, 28 insertions(+), 195 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b811c93..3325f5f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,7 +1,7 @@
noinst_LTLIBRARIES = testhelper.la
-testhelper_la_CFLAGS = -I$(top_srcdir)/gobject $(PYTHON_INCLUDES) $(GLIB_CFLAGS)
+testhelper_la_CFLAGS = -I$(top_srcdir)/gobject -I$(top_srcdir)/glib $(PYTHON_INCLUDES) $(GLIB_CFLAGS)
testhelper_la_LDFLAGS = -module -avoid-version
testhelper_la_LIBADD = $(GLIB_LIBS)
testhelper_la_SOURCES = \
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index 5585c96..5610a5d 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -5,6 +5,8 @@
#include "test-unknown.h"
#include "test-floating.h"
+#include <pyglib-python-compat.h>
+
static PyTypeObject *_PyGObject_Type;
#define PyGObject_Type (*_PyGObject_Type)
@@ -83,7 +85,7 @@ _wrap_test_g_object_new (PyObject * self)
PyObject *rv;
obj = g_object_new(g_type_from_name("PyGObject"), NULL);
- rv = PyInt_FromLong(obj->ref_count); /* should be == 2 at this point */
+ rv = PYGLIB_PyLong_FromLong(obj->ref_count); /* should be == 2 at this point */
g_object_unref(obj);
return rv;
}
@@ -112,53 +114,7 @@ static const PyMethodDef _PyTestInterface_methods[] = {
};
/* TestInterface */
-PyTypeObject PyTestInterface_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "test.Interface", /* tp_name */
- sizeof(PyObject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)0, /* tp_dealloc */
- (printfunc)0, /* tp_print */
- (getattrfunc)0, /* tp_getattr */
- (setattrfunc)0, /* tp_setattr */
- (cmpfunc)0, /* tp_compare */
- (reprfunc)0, /* tp_repr */
- (PyNumberMethods*)0, /* tp_as_number */
- (PySequenceMethods*)0, /* tp_as_sequence */
- (PyMappingMethods*)0, /* tp_as_mapping */
- (hashfunc)0, /* tp_hash */
- (ternaryfunc)0, /* tp_call */
- (reprfunc)0, /* tp_str */
- (getattrofunc)0, /* tp_getattro */
- (setattrofunc)0, /* tp_setattro */
- (PyBufferProcs*)0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- NULL, /* Documentation string */
- (traverseproc)0, /* tp_traverse */
- (inquiry)0, /* tp_clear */
- (richcmpfunc)0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- (getiterfunc)0, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
- (struct PyMethodDef*)_PyTestInterface_methods, /* tp_methods */
- (struct PyMemberDef*)0, /* tp_members */
- (struct PyGetSetDef*)0, /* tp_getset */
- NULL, /* tp_base */
- NULL, /* tp_dict */
- (descrgetfunc)0, /* tp_descr_get */
- (descrsetfunc)0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)0, /* tp_init */
- (allocfunc)0, /* tp_alloc */
- (newfunc)0, /* tp_new */
- (freefunc)0, /* tp_free */
- (inquiry)0 /* tp_is_gc */
-
-
-
-};
+PYGLIB_DEFINE_TYPE("test.Interface", PyTestInterface_Type, PyObject);
static PyObject *
_wrap_TestInterface__do_iface_method(PyObject *cls, PyObject *args, PyObject *kwargs)
@@ -183,51 +139,7 @@ _wrap_TestInterface__do_iface_method(PyObject *cls, PyObject *args, PyObject *kw
return Py_None;
}
-PyTypeObject PyTestUnknown_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "testhelper.Unknown", /* tp_name */
- sizeof(PyGObject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)0, /* tp_dealloc */
- (printfunc)0, /* tp_print */
- (getattrfunc)0, /* tp_getattr */
- (setattrfunc)0, /* tp_setattr */
- (cmpfunc)0, /* tp_compare */
- (reprfunc)0, /* tp_repr */
- (PyNumberMethods*)0, /* tp_as_number */
- (PySequenceMethods*)0, /* tp_as_sequence */
- (PyMappingMethods*)0, /* tp_as_mapping */
- (hashfunc)0, /* tp_hash */
- (ternaryfunc)0, /* tp_call */
- (reprfunc)0, /* tp_str */
- (getattrofunc)0, /* tp_getattro */
- (setattrofunc)0, /* tp_setattro */
- (PyBufferProcs*)0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- NULL, /* Documentation string */
- (traverseproc)0, /* tp_traverse */
- (inquiry)0, /* tp_clear */
- (richcmpfunc)0, /* tp_richcompare */
- offsetof(PyGObject, weakreflist), /* tp_weaklistoffset */
- (getiterfunc)0, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
- (struct PyMethodDef*)0, /* tp_methods */
- (struct PyMemberDef*)0, /* tp_members */
- (struct PyGetSetDef*)0, /* tp_getset */
- NULL, /* tp_base */
- NULL, /* tp_dict */
- (descrgetfunc)0, /* tp_descr_get */
- (descrsetfunc)0, /* tp_descr_set */
- offsetof(PyGObject, inst_dict), /* tp_dictoffset */
- (initproc)0, /* tp_init */
- (allocfunc)0, /* tp_alloc */
- (newfunc)0, /* tp_new */
- (freefunc)0, /* tp_free */
- (inquiry)0 /* tp_is_gc */
-};
-
+PYGLIB_DEFINE_TYPE("testhelper.Unknown", PyTestUnknown_Type, PyGObject);
static void
_wrap_TestInterface__proxy_do_iface_method(TestInterface *self)
@@ -313,98 +225,10 @@ static const GInterfaceInfo __TestInterface__iinfo = {
};
/* TestFloatingWithSinkFunc */
-
-PyTypeObject PyTestFloatingWithSinkFunc_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "testhelper.FloatingWithSinkFunc", /* tp_name */
- sizeof(PyGObject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)0, /* tp_dealloc */
- (printfunc)0, /* tp_print */
- (getattrfunc)0, /* tp_getattr */
- (setattrfunc)0, /* tp_setattr */
- (cmpfunc)0, /* tp_compare */
- (reprfunc)0, /* tp_repr */
- (PyNumberMethods*)0, /* tp_as_number */
- (PySequenceMethods*)0, /* tp_as_sequence */
- (PyMappingMethods*)0, /* tp_as_mapping */
- (hashfunc)0, /* tp_hash */
- (ternaryfunc)0, /* tp_call */
- (reprfunc)0, /* tp_str */
- (getattrofunc)0, /* tp_getattro */
- (setattrofunc)0, /* tp_setattro */
- (PyBufferProcs*)0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- NULL, /* Documentation string */
- (traverseproc)0, /* tp_traverse */
- (inquiry)0, /* tp_clear */
- (richcmpfunc)0, /* tp_richcompare */
- offsetof(PyGObject, weakreflist), /* tp_weaklistoffset */
- (getiterfunc)0, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
- (struct PyMethodDef*)0, /* tp_methods */
- (struct PyMemberDef*)0, /* tp_members */
- (struct PyGetSetDef*)0, /* tp_getset */
- NULL, /* tp_base */
- NULL, /* tp_dict */
- (descrgetfunc)0, /* tp_descr_get */
- (descrsetfunc)0, /* tp_descr_set */
- offsetof(PyGObject, inst_dict), /* tp_dictoffset */
- (initproc)0, /* tp_init */
- (allocfunc)0, /* tp_alloc */
- (newfunc)0, /* tp_new */
- (freefunc)0, /* tp_free */
- (inquiry)0 /* tp_is_gc */
-};
+PYGLIB_DEFINE_TYPE("testhelper.FloatingWithSinkFunc", PyTestFloatingWithSinkFunc_Type, PyGObject);
/* TestFloatingWithoutSinkFunc */
-
-PyTypeObject PyTestFloatingWithoutSinkFunc_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "testhelper.FloatingWithoutSinkFunc", /* tp_name */
- sizeof(PyGObject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)0, /* tp_dealloc */
- (printfunc)0, /* tp_print */
- (getattrfunc)0, /* tp_getattr */
- (setattrfunc)0, /* tp_setattr */
- (cmpfunc)0, /* tp_compare */
- (reprfunc)0, /* tp_repr */
- (PyNumberMethods*)0, /* tp_as_number */
- (PySequenceMethods*)0, /* tp_as_sequence */
- (PyMappingMethods*)0, /* tp_as_mapping */
- (hashfunc)0, /* tp_hash */
- (ternaryfunc)0, /* tp_call */
- (reprfunc)0, /* tp_str */
- (getattrofunc)0, /* tp_getattro */
- (setattrofunc)0, /* tp_setattro */
- (PyBufferProcs*)0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- NULL, /* Documentation string */
- (traverseproc)0, /* tp_traverse */
- (inquiry)0, /* tp_clear */
- (richcmpfunc)0, /* tp_richcompare */
- offsetof(PyGObject, weakreflist), /* tp_weaklistoffset */
- (getiterfunc)0, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
- (struct PyMethodDef*)0, /* tp_methods */
- (struct PyMemberDef*)0, /* tp_members */
- (struct PyGetSetDef*)0, /* tp_getset */
- NULL, /* tp_base */
- NULL, /* tp_dict */
- (descrgetfunc)0, /* tp_descr_get */
- (descrsetfunc)0, /* tp_descr_set */
- offsetof(PyGObject, inst_dict), /* tp_dictoffset */
- (initproc)0, /* tp_init */
- (allocfunc)0, /* tp_alloc */
- (newfunc)0, /* tp_new */
- (freefunc)0, /* tp_free */
- (inquiry)0 /* tp_is_gc */
-};
+PYGLIB_DEFINE_TYPE("testhelper.FloatingWithoutSinkFunc", PyTestFloatingWithoutSinkFunc_Type, PyGObject);
#include <string.h>
#include <glib-object.h>
@@ -619,20 +443,17 @@ static PyMethodDef testhelper_functions[] = {
{ NULL, NULL }
};
-void
-inittesthelper ()
+PYGLIB_MODULE_START(testhelper, "testhelper")
{
PyObject *m, *d;
- PyObject *module;
g_thread_init(NULL);
init_pygobject();
- m = Py_InitModule ("testhelper", testhelper_functions);
- d = PyModule_GetDict(m);
+ d = PyModule_GetDict(module);
- if ((module = PyImport_ImportModule("gobject")) != NULL) {
- PyObject *moddict = PyModule_GetDict(module);
+ if ((m = PyImport_ImportModule("gobject")) != NULL) {
+ PyObject *moddict = PyModule_GetDict(m);
_PyGObject_Type = (PyTypeObject *)PyDict_GetItemString(moddict, "GObject");
if (_PyGObject_Type == NULL) {
@@ -647,33 +468,45 @@ inittesthelper ()
}
/* TestInterface */
+ PyTestInterface_Type.tp_methods = (struct PyMethodDef*)_PyTestInterface_methods;
+ PyTestInterface_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
pyg_register_interface(d, "Interface", TEST_TYPE_INTERFACE,
&PyTestInterface_Type);
pyg_register_interface_info(TEST_TYPE_INTERFACE, &__TestInterface__iinfo);
/* TestUnknown */
+ PyTestUnknown_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
+ PyTestUnknown_Type.tp_weaklistoffset = offsetof(PyGObject, weakreflist);
+ PyTestUnknown_Type.tp_dictoffset = offsetof(PyGObject, inst_dict);
pygobject_register_class(d, "Unknown", TEST_TYPE_UNKNOWN,
&PyTestUnknown_Type,
Py_BuildValue("(O)",
- &PyGObject_Type,
- &PyTestInterface_Type));
+ &PyGObject_Type,
+ &PyTestInterface_Type));
pyg_set_object_has_new_constructor(TEST_TYPE_UNKNOWN);
//pyg_register_class_init(TEST_TYPE_UNKNOWN, __GtkUIManager_class_init);
/* TestFloatingWithSinkFunc */
+ PyTestFloatingWithSinkFunc_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
+ PyTestFloatingWithSinkFunc_Type.tp_weaklistoffset = offsetof(PyGObject, weakreflist);
+ PyTestFloatingWithSinkFunc_Type.tp_dictoffset = offsetof(PyGObject, inst_dict);
pygobject_register_class(d, "FloatingWithSinkFunc", TEST_TYPE_FLOATING_WITH_SINK_FUNC,
&PyTestFloatingWithSinkFunc_Type,
Py_BuildValue("(O)",
- &PyGObject_Type));
+ &PyGObject_Type));
pyg_set_object_has_new_constructor(TEST_TYPE_FLOATING_WITH_SINK_FUNC);
pygobject_register_sinkfunc(TEST_TYPE_FLOATING_WITH_SINK_FUNC, sink_test_floating_with_sink_func);
/* TestFloatingWithoutSinkFunc */
+ PyTestFloatingWithoutSinkFunc_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
+ PyTestFloatingWithoutSinkFunc_Type.tp_weaklistoffset = offsetof(PyGObject, weakreflist);
+ PyTestFloatingWithoutSinkFunc_Type.tp_dictoffset = offsetof(PyGObject, inst_dict);
pygobject_register_class(d, "FloatingWithoutSinkFunc", TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC,
&PyTestFloatingWithoutSinkFunc_Type,
Py_BuildValue("(O)",
- &PyGObject_Type));
+ &PyGObject_Type));
pyg_set_object_has_new_constructor(TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC);
}
+PYGLIB_MODULE_END
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]