[pygobject] Make GType.pytype aware of the interface, enum, flags, pointer and boxed wrappers
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject] Make GType.pytype aware of the interface, enum, flags, pointer and boxed wrappers
- Date: Mon, 9 Nov 2009 21:38:32 +0000 (UTC)
commit 421c03b1c5b69f90c778663df901b45ca3ee8ba5
Author: Simon van der Linden <svdlinden src gnome org>
Date: Fri Nov 6 19:17:36 2009 +0100
Make GType.pytype aware of the interface, enum, flags, pointer and boxed wrappers
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]