diff options
| author | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:01:38 +0000 |
|---|---|---|
| committer | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:01:38 +0000 |
| commit | eddccffb2412dd42754cc36244ea6476d742d691 (patch) | |
| tree | 27010e79efbe401e39c7c17682dedf3e56d1a2d1 /bindings/lang_python_wrapper_top.c | |
| parent | 02644ef15b19f60e69d33d4e28bbfdfb77fb16d1 (diff) | |
| download | lasso-eddccffb2412dd42754cc36244ea6476d742d691.tar.gz lasso-eddccffb2412dd42754cc36244ea6476d742d691.tar.xz lasso-eddccffb2412dd42754cc36244ea6476d742d691.zip | |
[project @ fpeters@0d.be-20071005125351-543q5fahhrljdmaj]
(work in progress) some infra for python wrapper
Original author: Frederic Peters <fpeters@0d.be>
Date: 2007-10-05 14:53:51.026000+02:00
Diffstat (limited to 'bindings/lang_python_wrapper_top.c')
| -rw-r--r-- | bindings/lang_python_wrapper_top.c | 66 |
1 files changed, 66 insertions, 0 deletions
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 <Python.h> +#include <lasso/lasso.h> + +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 */ +}; + |
