diff options
author | Simon van der Linden <svdlinden@src.gnome.org> | 2009-11-06 19:17:36 +0100 |
---|---|---|
committer | Simon van der Linden <svdlinden@src.gnome.org> | 2009-11-07 16:53:11 +0100 |
commit | 421c03b1c5b69f90c778663df901b45ca3ee8ba5 (patch) | |
tree | e0d70e0b801c89b4c298db1c258a9174034e63c9 /gobject | |
parent | a9c168c58cc6a449b51653417bf3f58bdd41457c (diff) | |
download | pygobject-421c03b1c5b69f90c778663df901b45ca3ee8ba5.tar.gz pygobject-421c03b1c5b69f90c778663df901b45ca3ee8ba5.tar.xz pygobject-421c03b1c5b69f90c778663df901b45ca3ee8ba5.zip |
Make GType.pytype aware of the interface, enum, flags, pointer and boxed wrappers
Diffstat (limited to 'gobject')
-rw-r--r-- | gobject/pygtype.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/gobject/pygtype.c b/gobject/pygtype.c index 601ea83..782e998 100644 --- a/gobject/pygtype.c +++ b/gobject/pygtype.c @@ -70,12 +70,36 @@ pyg_type_wrapper_dealloc(PyGTypeWrapper *self) PyObject_DEL(self); } +static GQuark +_pyg_type_key(GType type) { + GQuark key; + + if (g_type_is_a(type, G_TYPE_INTERFACE)) { + key = pyginterface_type_key; + } else if (g_type_is_a(type, G_TYPE_ENUM)) { + key = pygenum_class_key; + } else if (g_type_is_a(type, G_TYPE_FLAGS)) { + key = pygflags_class_key; + } else if (g_type_is_a(type, G_TYPE_POINTER)) { + key = pygpointer_class_key; + } else if (g_type_is_a(type, G_TYPE_BOXED)) { + key = pygboxed_type_key; + } else { + key = pygobject_class_key; + } + + return key; +} + static PyObject * _wrap_g_type_wrapper__get_pytype(PyGTypeWrapper *self, void *closure) { + GQuark key; PyObject *py_type; - - py_type = g_type_get_qdata(self->type, pygobject_class_key); + + key = _pyg_type_key(self->type); + + py_type = g_type_get_qdata(self->type, key); if (!py_type) py_type = Py_None; @@ -86,15 +110,18 @@ _wrap_g_type_wrapper__get_pytype(PyGTypeWrapper *self, void *closure) static int _wrap_g_type_wrapper__set_pytype(PyGTypeWrapper *self, PyObject* value, void *closure) { + GQuark key; PyObject *py_type; - - py_type = g_type_get_qdata(self->type, pygobject_class_key); + + key = _pyg_type_key(self->type); + + py_type = g_type_get_qdata(self->type, key); Py_CLEAR(py_type); if (value == Py_None) - g_type_set_qdata(self->type, pygobject_class_key, NULL); + g_type_set_qdata(self->type, key, NULL); else if (PyType_Check(value)) { Py_INCREF(value); - g_type_set_qdata(self->type, pygobject_class_key, value); + g_type_set_qdata(self->type, key, value); } else { PyErr_SetString(PyExc_TypeError, "Value must be None or a type object"); return -1; |