From eddccffb2412dd42754cc36244ea6476d742d691 Mon Sep 17 00:00:00 2001 From: Frederic Peters Date: Tue, 29 Apr 2008 12:01:38 +0000 Subject: [project @ fpeters@0d.be-20071005125351-543q5fahhrljdmaj] (work in progress) some infra for python wrapper Original author: Frederic Peters Date: 2007-10-05 14:53:51.026000+02:00 --- bindings/lang_python_wrapper_top.c | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 bindings/lang_python_wrapper_top.c (limited to 'bindings/lang_python_wrapper_top.c') diff --git a/bindings/lang_python_wrapper_top.c b/bindings/lang_python_wrapper_top.c new file mode 100644 index 00000000..6c5f74a2 --- /dev/null +++ b/bindings/lang_python_wrapper_top.c @@ -0,0 +1,66 @@ +#include +#include + +GQuark lasso_wrapper_key; + + +typedef struct { + PyObject_HEAD + GObject *obj; +} PyGObjectPtr; + +static PyTypeObject PyGObjectPtrType; + +static void +PyGObjectPtr_dealloc(PyGObjectPtr *self) +{ + g_object_unref(self->obj); + self->ob_type->tp_free((PyObject*)self); +} + +static PyObject* +PyGObjectPtr_New(GObject *obj) +{ + PyGObjectPtr *self; + + if (obj == NULL) { + Py_INCREF(Py_None); + return Py_None; + } + + self = (PyGObjectPtr*)g_object_get_qdata(obj, lasso_wrapper_key) + if (self != NULL) { + Py_INCREF(self); + } else { + self = (PyGObjectPtr*)PyObject_NEW(PyGObjectPtr, &PyGObjectPtrType); + g_object_set_qdata_full(obj, lasso_wrapper_key, self, NULL); + self->obj = obj; + } + return (PyObject*)self; +} + +static PyTypeObject PyGObjectPtrType = { + PyObject_HEAD_INIT(NULL), + 0, /* ob_size */ + "_lasso.PyGObjectPtr", /* tp_name */ + sizeof(PyGObjectPtr), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PyGObjectPtr_dealloc, /* tp_dealloc */ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "PyGObjectPtr objects", /* tp_doc */ +}; + -- cgit