summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-04-25 01:08:45 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-04-25 01:08:45 (GMT)
commit193152c17479732f2fd9bd5d14ae4db119727bec (patch)
tree2166ce7a5f084ee4e95b88f7563f7e9cba3be49a
parent24fb1d0a7b6306f8c5e4f8591eff8c4fe21388d8 (diff)
downloadcpython-193152c17479732f2fd9bd5d14ae4db119727bec.zip
cpython-193152c17479732f2fd9bd5d14ae4db119727bec.tar.gz
cpython-193152c17479732f2fd9bd5d14ae4db119727bec.tar.bz2
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 ........
-rw-r--r--Lib/test/test_descr.py10
-rw-r--r--Misc/NEWS2
-rw-r--r--Objects/typeobject.c6
3 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 407959d..4558b98 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -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
diff --git a/Misc/NEWS b/Misc/NEWS
index 20bbe63..c3a965a 100644
--- 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.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 47bc0bb..06d600e 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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.
*/