[Python-checkins] r71860 - in python/trunk: Lib/test/test_descr.py Misc/NEWS Objects/typeobject.c

benjamin.peterson python-checkins at python.org
Sat Apr 25 02:41:22 CEST 2009


Author: benjamin.peterson
Date: Sat Apr 25 02:41:22 2009
New Revision: 71860
Log:
fix a segfault when setting __class__ in __del__ #5283
Modified:
 python/trunk/Lib/test/test_descr.py
 python/trunk/Misc/NEWS
 python/trunk/Objects/typeobject.c
Modified: python/trunk/Lib/test/test_descr.py
==============================================================================
--- python/trunk/Lib/test/test_descr.py	(original)
+++ python/trunk/Lib/test/test_descr.py	Sat Apr 25 02:41:22 2009
@@ -3003,6 +3003,16 @@
 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
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Apr 25 02:41:22 2009
@@ -12,6 +12,8 @@
 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.
 
Modified: python/trunk/Objects/typeobject.c
==============================================================================
--- python/trunk/Objects/typeobject.c	(original)
+++ python/trunk/Objects/typeobject.c	Sat Apr 25 02:41:22 2009
@@ -928,6 +928,9 @@
 			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 @@
 		}
 	}
 
+	/* 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.
 	 */


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /