]> granicus.if.org Git - python/commitdiff
Merged revisions 71860 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 25 Apr 2009 00:44:44 +0000 (00:44 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 25 Apr 2009 00:44:44 +0000 (00:44 +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 554e1c8a65a95e29b194fdabf901723b634ca0a6..cef7d476e13aeea9c8a0d27e4428471c6f7c418f 100644 (file)
@@ -2959,6 +2959,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 546c7c1e1383114dec01a3677b3f925e6c81abf3..5c074e13caea37cf3640218b038525f93df2d8ed 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@ Core and Builtins
 - Issue #5787: object.__getattribute__(some_type, "__bases__") segfaulted on
   some builtin types.
 
+- Issue #5283: Setting __class__ in __del__ caused a segfault.
+
 - Issue #5759: float() didn't call __float__ on str subclasses.
 
 Library
index ddfc73056582f7449dd864b0f2142ec2caf54c50..7e48172fecf50f023a58377baceea5465481d9e2 100644 (file)
@@ -928,6 +928,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);
@@ -1009,6 +1012,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.
         */