]> granicus.if.org Git - python/commitdiff
Merged revisions 71860 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 25 Apr 2009 01:08:45 +0000 (01:08 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 25 Apr 2009 01:08:45 +0000 (01:08 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r71860 | benjamin.peterson | 2009-04-24 19:41:22 -0500 (Fri, 24 Apr 2009) | 1 line

  fix a segfault when setting __class__ in __del__ #5283
........

Lib/test/test_descr.py
Misc/NEWS
Objects/typeobject.c

index 407959d75ba65ab49761c3f93093f9a0de1fd66b..4558b9835fe7fd5a2e23f50f504bf88bece0dcd3 100644 (file)
@@ -2747,6 +2747,16 @@ order (MRO) for bases """
                     continue
                 cant(cls(), cls2)
 
+        # Issue5283: when __class__ changes in __del__, the wrong
+        # type gets DECREF'd.
+        class O(object):
+            pass
+        class A(object):
+            def __del__(self):
+                self.__class__ = O
+        l = [A() for x in range(100)]
+        del l
+
     def test_set_dict(self):
         # Testing __dict__ assignment...
         class C(object): pass
index 20bbe630fc6db454cf0f87fdb9faefaa79a50326..c3a965af702f443b3cb86b6e80c567da253f045d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.1 beta 1?
 Core and Builtins
 -----------------
 
+- Issue #5283: Setting __class__ in __del__ caused a segfault.
+
 - Issue #5816: complex(repr(z)) now recovers z exactly, even when
   z involves nans, infs or negative zeros.
 
index 47bc0bb9b7cad54fc2ae98c3171b1c98c25022e6..06d600ead9a4e0e58a1ce41a46bae6d6c665463e 100644 (file)
@@ -877,6 +877,9 @@ subtype_dealloc(PyObject *self)
                        assert(base);
                }
 
+               /* Extract the type again; tp_del may have changed it */
+               type = Py_TYPE(self);
+
                /* Call the base tp_dealloc() */
                assert(basedealloc);
                basedealloc(self);
@@ -958,6 +961,9 @@ subtype_dealloc(PyObject *self)
                }
        }
 
+       /* Extract the type again; tp_del may have changed it */
+       type = Py_TYPE(self);
+
        /* Call the base tp_dealloc(); first retrack self if
         * basedealloc knows about gc.
         */