diff options
author | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2007-04-30 17:37:01 +0000 |
---|---|---|
committer | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2007-04-30 17:37:01 +0000 |
commit | a0f7e83fb9a50a43668eb5c622bfa6edb06185f5 (patch) | |
tree | 2ce9b002a31c658994ca26f19e99a285a039f2f2 | |
parent | d96aaf253b925d4e84374f5c7e79398c21eff72f (diff) | |
download | pygobject-a0f7e83fb9a50a43668eb5c622bfa6edb06185f5.tar.gz pygobject-a0f7e83fb9a50a43668eb5c622bfa6edb06185f5.tar.xz pygobject-a0f7e83fb9a50a43668eb5c622bfa6edb06185f5.zip |
fix descriptor / toggle_ref interaction bug
svn path=/trunk/; revision=658
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | gobject/pygobject.c | 7 | ||||
-rw-r--r-- | tests/test_subtype.py | 12 |
3 files changed, 26 insertions, 3 deletions
@@ -1,3 +1,13 @@ +2007-04-30 Gustavo J. A. M. Carneiro <gjc@inescporto.pt> + + * tests/test_subtype.py (TestSubType.testDescriptor): Unit test + for the bug below. + + * gobject/pygobject.c (pygobject_setattro): Account for the case + when attribute setting doesn't actually create an instance + dictionary, in which case pygobject_switch_to_toggle_ref would be + called twice, thereby causing gobject error. + 2007-04-29 James Livingstone <doclivingstone@gmail.com> reviewed by: Johan Dahlin <johan@gnome.org> diff --git a/gobject/pygobject.c b/gobject/pygobject.c index a17762d..27f82f6 100644 --- a/gobject/pygobject.c +++ b/gobject/pygobject.c @@ -2011,12 +2011,13 @@ pygobject_setattro(PyObject *self, PyObject *name, PyObject *value) { int res; PyGObject *gself = (PyGObject *) self; - if (gself->inst_dict == NULL) { + PyObject *inst_dict_before = gself->inst_dict; + /* call parent type's setattro */ + res = PyGObject_Type.tp_base->tp_setattro(self, name, value); + if (inst_dict_before == NULL && gself->inst_dict != NULL) { if (G_LIKELY(gself->obj)) pygobject_switch_to_toggle_ref(gself); } - /* call parent type's setattro */ - res = PyGObject_Type.tp_base->tp_setattro(self, name, value); return res; } diff --git a/tests/test_subtype.py b/tests/test_subtype.py index 244fdc4..2b2c21f 100644 --- a/tests/test_subtype.py +++ b/tests/test_subtype.py @@ -234,3 +234,15 @@ class TestSubType(unittest.TestCase): gobj.set_data('tmp', CallInDel(on_dispose)) del gobj assert len(disposed_calls) == 1 + + def testDescriptor(self): + class GProperty(object): + def __set__(self, instance, value): + pass + + class C(gobject.GObject): + str = GProperty() + + o = C() + o.str = 'str' + o.str = 'str' |