]> granicus.if.org Git - python/commitdiff
Trivial little change: when setting a member to an object, hold the
authorGuido van Rossum <guido@python.org>
Wed, 20 May 1998 22:25:32 +0000 (22:25 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 20 May 1998 22:25:32 +0000 (22:25 +0000)
old value in a temporary and XDECREF it only after then new value has
been set.  This prevents the (unlikely) case where the destructor of
the member uses the containing object -- it would find it in an
undefined state.

Python/structmember.c

index 02464c611f0a2c0cc848e7c25d542682baecaccb..ba0772008ab37e97c09a487ee7ab09078d236686 100644 (file)
@@ -167,6 +167,7 @@ PyMember_Set(addr, mlist, name, v)
        PyObject *v;
 {
        struct memberlist *l;
+       PyObject *oldv;
        
        for (l = mlist; l->name != NULL; l++) {
                if (strcmp(l->name, name) == 0) {
@@ -253,9 +254,10 @@ PyMember_Set(addr, mlist, name, v)
                                }
                                break;
                        case T_OBJECT:
-                               Py_XDECREF(*(PyObject **)addr);
                                Py_XINCREF(v);
+                               oldv = *(PyObject **)addr;
                                *(PyObject **)addr = v;
+                               Py_XDECREF(oldv);
                                break;
                        case T_CHAR:
                                if (PyString_Check(v) &&