[Python-checkins] cpython (2.7): Issue #12149: Update the method cache after a type's dictionnary gets
antoine.pitrou
python-checkins at python.org
Tue Jul 12 22:05:50 CEST 2011
http://hg.python.org/cpython/rev/9618303852da
changeset: 71299:9618303852da
branch: 2.7
parent: 71290:09c9cb6ece33
user: Antoine Pitrou <solipsis at pitrou.net>
date: Tue Jul 12 22:04:20 2011 +0200
summary:
Issue #12149: Update the method cache after a type's dictionnary gets
cleared by the garbage collector. This fixes a segfault when an instance
and its type get caught in a reference cycle, and the instance's
deallocator calls one of the methods on the type (e.g. when subclassing
IOBase).
Diagnosis and patch by Davide Rizzo.
files:
Lib/test/test_io.py | 19 ++++++++++++++++++-
Misc/ACKS | 1 +
Misc/NEWS | 6 ++++++
Objects/typeobject.c | 2 ++
4 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -585,7 +585,24 @@
self.assertEqual(rawio.read(2), b"")
class CIOTest(IOTest):
- pass
+
+ def test_IOBase_finalize(self):
+ # Issue #12149: segmentation fault on _PyIOBase_finalize when both a
+ # class which inherits IOBase and an object of this class are caught
+ # in a reference cycle and close() is already in the method cache.
+ class MyIO(self.IOBase):
+ def close(self):
+ pass
+
+ # create an instance to populate the method cache
+ MyIO()
+ obj = MyIO()
+ obj.obj = obj
+ wr = weakref.ref(obj)
+ del MyIO
+ del obj
+ support.gc_collect()
+ self.assertTrue(wr() is None, wr)
class PyIOTest(IOTest):
test_array_writes = unittest.skip(
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -686,6 +686,7 @@
Nicholas Riley
Jean-Claude Rimbault
Juan M. Bello Rivas
+Davide Rizzo
Anthony Roach
Mark Roberts
Jim Robinson
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,12 @@
Core and Builtins
-----------------
+- Issue #12149: Update the method cache after a type's dictionnary gets
+ cleared by the garbage collector. This fixes a segfault when an instance
+ and its type get caught in a reference cycle, and the instance's
+ deallocator calls one of the methods on the type (e.g. when subclassing
+ IOBase). Diagnosis and patch by Davide Rizzo.
+
- Issue #12501: Adjust callable() warning: callable() is only not supported in
Python 3.1. callable() is again supported in Python 3.2.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1013,6 +1013,8 @@
assert(basedealloc);
basedealloc(self);
+ PyType_Modified(type);
+
/* Can't reference self beyond this point */
Py_DECREF(type);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list