diff options
author | James Henstridge <jamesh@src.gnome.org> | 2001-07-08 15:03:14 +0000 |
---|---|---|
committer | James Henstridge <jamesh@src.gnome.org> | 2001-07-08 15:03:14 +0000 |
commit | 1bb54702e7cf0b8dff5874f80d91e0bd96cfb172 (patch) | |
tree | 294d605551bd6bd86a8f962c7892366eaf9ffa6e | |
parent | 25421c59c3ff79fe77b8c13f35f474cdce1b2687 (diff) | |
download | pygobject-1bb54702e7cf0b8dff5874f80d91e0bd96cfb172.tar.gz pygobject-1bb54702e7cf0b8dff5874f80d91e0bd96cfb172.tar.xz pygobject-1bb54702e7cf0b8dff5874f80d91e0bd96cfb172.zip |
register a "PyObject" boxed type with glib.. (pyg_value_from_pyobject): if
* gobjectmodule.c:
(initgobject): register a "PyObject" boxed type with glib..
(pyg_value_from_pyobject): if the value holds a PY_TYPE_OBJECT,
set the value directly.
(pyg_value_as_pyobject): special case the PY_TYPE_OBJECT case
again.
-rw-r--r-- | gobject/gobjectmodule.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index edb0cd0..65a7f0a 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -170,7 +170,7 @@ pyg_type_thingee_new(GType (* get_type)(void)) /* -------------- class <-> wrapper manipulation --------------- */ -void +static void pygobject_destroy_notify(gpointer user_data) { PyObject *obj = (PyObject *)user_data; @@ -274,6 +274,25 @@ pygobject_new(GObject *obj) /* ---------------- GBoxed functions -------------------- */ +static GType PY_TYPE_OBJECT = 0; + +static gpointer +pyobject_copy(gpointer boxed) +{ + PyObject *object = boxed; + + Py_INCREF(object); + return object; +} + +static void +pyobject_free(gpointer boxed) +{ + PyObject *object = boxed; + + Py_DECREF(object); +} + static void pyg_boxed_dealloc(PyGBoxed *self) { @@ -711,7 +730,9 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj) } else if (G_VALUE_HOLDS_BOXED(value)) { PyGBoxedMarshal *bm; - if (ExtensionClassSubclassInstance_Check(obj, &PyGBoxed_Type) && + if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT)) { + g_value_set_boxed(value, obj); + } else if (ExtensionClassSubclassInstance_Check(obj, &PyGBoxed_Type) && G_VALUE_HOLDS(value, ((PyGBoxed *)obj)->gtype)) { g_value_set_boxed(value, pyg_boxed_get(obj, gpointer)); } else if ((bm = pyg_boxed_lookup(G_VALUE_TYPE(value))) != NULL) { @@ -761,8 +782,12 @@ pyg_value_as_pyobject(const GValue *value) } else if (G_VALUE_HOLDS_FLAGS(value)) { return PyInt_FromLong(g_value_get_flags(value)); } else if (G_VALUE_HOLDS_BOXED(value)) { - PyGBoxedMarshal *bm = pyg_boxed_lookup(G_VALUE_TYPE(value)); + PyGBoxedMarshal *bm; + + if (G_VALUE_HOLDS(value, PY_TYPE_OBJECT)) + return (PyObject *)g_value_dup_boxed(value); + bm = pyg_boxed_lookup(G_VALUE_TYPE(value)); if (bm) return bm->fromvalue(value); else @@ -2081,6 +2106,13 @@ initgobject(void) d = PyModule_GetDict(m); g_type_init(); + + PY_TYPE_OBJECT = g_boxed_type_register_static("PyObject", + NULL, + pyobject_copy, + pyobject_free, + TRUE); + pygobject_register_class(d, "GObject", 0, &PyGObject_Type, NULL); PyDict_SetItemString(PyGObject_Type.class_dictionary, "__gtype__", o=PyInt_FromLong(G_TYPE_OBJECT)); |