From e6ef557a9ba22f8b8afb0e772c206589dbbb0b9a Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sun, 28 May 2006 13:50:05 +0000 Subject: gobject.new fix for 'subsubtype' case --- ChangeLog | 14 ++++++++++++++ gobject/gobjectmodule.c | 6 +++--- gobject/pygobject-private.h | 2 +- gobject/pygobject.c | 14 ++++++++++---- tests/test_subtype.py | 5 +++-- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index af1cde3..d560b75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2006-05-28 Gustavo J. A. M. Carneiro + + * tests/test_subtype.py: Uncomment Johan's "subsubtype" test case. + + * gobject/gobjectmodule.c (pygobject__g_instance_init): Pass the + g_class to pygobject_new_full, because during the instance init + function instances are temporarily assigned the parent's GType. + + * gobject/pygobject-private.h, + * gobject/pygobject.c (pygobject_new_full): Make + pygobject_new_full accept an optional g_class parameter; If + present, the GType is extracted from the class instead of from the + instance. + 2006-05-20 Yevgen Muntyan reviewed by: Gustavo Carneiro diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 914a644..cd0532e 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -1184,7 +1184,7 @@ pygobject__g_instance_init(GTypeInstance *instance, * now */ PyGILState_STATE state; state = pyg_gil_state_ensure(); - wrapper = pygobject_new_full(object, FALSE); + wrapper = pygobject_new_full(object, FALSE, g_class); args = PyTuple_New(0); kwargs = PyDict_New(); if (wrapper->ob_type->tp_init(wrapper, args, kwargs)) @@ -1751,7 +1751,7 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs) obj = g_object_newv(type, n_params, params); if (!obj) PyErr_SetString (PyExc_RuntimeError, "could not create object"); - + cleanup: for (i = 0; i < n_params; i++) { g_free((gchar *) params[i].name); @@ -1761,7 +1761,7 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs) g_type_class_unref(class); if (obj) { - self = (PyGObject *) pygobject_new_full((GObject *)obj, FALSE); + self = (PyGObject *) pygobject_new_full((GObject *)obj, FALSE, NULL); g_object_unref(obj); pygobject_sink(obj); } else diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h index 20ed244..eb4074d 100644 --- a/gobject/pygobject-private.h +++ b/gobject/pygobject-private.h @@ -117,7 +117,7 @@ void pygobject_register_class (PyObject *dict, PyObject *bases); void pygobject_register_wrapper (PyObject *self); PyObject * pygobject_new (GObject *obj); -PyObject * pygobject_new_full (GObject *obj, gboolean sink); +PyObject * pygobject_new_full (GObject *obj, gboolean sink, gpointer g_class); void pygobject_sink (GObject *obj); PyTypeObject *pygobject_lookup_class (GType gtype); void pygobject_watch_closure (PyObject *self, GClosure *closure); diff --git a/gobject/pygobject.c b/gobject/pygobject.c index f6307ac..1451148 100644 --- a/gobject/pygobject.c +++ b/gobject/pygobject.c @@ -739,9 +739,10 @@ pygobject_lookup_class(GType gtype) } /** - * pygobject_new: + * pygobject_new_full: * @obj: a GObject instance. * @sink: whether to sink any floating reference found on the GObject. + * @g_class: the GObjectClass * * This function gets a reference to a wrapper for the given GObject * instance. If a wrapper has already been created, a new reference @@ -751,7 +752,7 @@ pygobject_lookup_class(GType gtype) * Returns: a reference to the wrapper for the GObject. */ PyObject * -pygobject_new_full(GObject *obj, gboolean sink) +pygobject_new_full(GObject *obj, gboolean sink, gpointer g_class) { PyGObject *self; @@ -766,7 +767,11 @@ pygobject_new_full(GObject *obj, gboolean sink) Py_INCREF(self); } else { /* create wrapper */ - PyTypeObject *tp = pygobject_lookup_class(G_OBJECT_TYPE(obj)); + PyTypeObject *tp; + if (g_class) + tp = pygobject_lookup_class(G_OBJECT_CLASS_TYPE(g_class)); + else + tp = pygobject_lookup_class(G_OBJECT_TYPE(obj)); /* need to bump type refcount if created with pygobject_new_with_interfaces(). fixes bug #141042 */ if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE) @@ -792,10 +797,11 @@ pygobject_new_full(GObject *obj, gboolean sink) return (PyObject *)self; } + PyObject * pygobject_new(GObject *obj) { - return pygobject_new_full(obj, TRUE); + return pygobject_new_full(obj, TRUE, NULL); } static void diff --git a/tests/test_subtype.py b/tests/test_subtype.py index 5815923..8aad307 100644 --- a/tests/test_subtype.py +++ b/tests/test_subtype.py @@ -47,5 +47,6 @@ class TestSubType(unittest.TestCase): self.assertEqual(obj.__gtype__.name, 'Object2') obj = gobject.new(Object2) - #self.failUnless(isinstance(obj, Object2)) - #self.assertEqual(obj.__gtype__.name, 'Object2') + self.failUnless(isinstance(obj, Object2)) + self.assertEqual(obj.__gtype__.name, 'Object2') + -- cgit