Commit 193152c1 authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 71860 via svnmerge from

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
........
parent 24fb1d0a
...@@ -2747,6 +2747,16 @@ order (MRO) for bases """ ...@@ -2747,6 +2747,16 @@ order (MRO) for bases """
continue continue
cant(cls(), cls2) 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): def test_set_dict(self):
# Testing __dict__ assignment... # Testing __dict__ assignment...
class C(object): pass class C(object): pass
......
...@@ -12,6 +12,8 @@ What's New in Python 3.1 beta 1? ...@@ -12,6 +12,8 @@ What's New in Python 3.1 beta 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #5283: Setting __class__ in __del__ caused a segfault.
- Issue #5816: complex(repr(z)) now recovers z exactly, even when - Issue #5816: complex(repr(z)) now recovers z exactly, even when
z involves nans, infs or negative zeros. z involves nans, infs or negative zeros.
......
...@@ -877,6 +877,9 @@ subtype_dealloc(PyObject *self) ...@@ -877,6 +877,9 @@ subtype_dealloc(PyObject *self)
assert(base); assert(base);
} }
/* Extract the type again; tp_del may have changed it */
type = Py_TYPE(self);
/* Call the base tp_dealloc() */ /* Call the base tp_dealloc() */
assert(basedealloc); assert(basedealloc);
basedealloc(self); basedealloc(self);
...@@ -958,6 +961,9 @@ subtype_dealloc(PyObject *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 /* Call the base tp_dealloc(); first retrack self if
* basedealloc knows about gc. * basedealloc knows about gc.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment