mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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.
This commit is contained in:
parent
0504532c39
commit
1616645a00
4 changed files with 27 additions and 1 deletions
|
@ -585,8 +585,25 @@ class IOTest(unittest.TestCase):
|
||||||
self.assertEqual(rawio.read(2), b"")
|
self.assertEqual(rawio.read(2), b"")
|
||||||
|
|
||||||
class CIOTest(IOTest):
|
class CIOTest(IOTest):
|
||||||
|
|
||||||
|
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
|
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):
|
class PyIOTest(IOTest):
|
||||||
test_array_writes = unittest.skip(
|
test_array_writes = unittest.skip(
|
||||||
"len(array.array) returns number of elements rather than bytelength"
|
"len(array.array) returns number of elements rather than bytelength"
|
||||||
|
|
|
@ -686,6 +686,7 @@ Armin Rigo
|
||||||
Nicholas Riley
|
Nicholas Riley
|
||||||
Jean-Claude Rimbault
|
Jean-Claude Rimbault
|
||||||
Juan M. Bello Rivas
|
Juan M. Bello Rivas
|
||||||
|
Davide Rizzo
|
||||||
Anthony Roach
|
Anthony Roach
|
||||||
Mark Roberts
|
Mark Roberts
|
||||||
Jim Robinson
|
Jim Robinson
|
||||||
|
|
|
@ -9,6 +9,12 @@ What's New in Python 2.7.3?
|
||||||
Core and Builtins
|
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
|
- Issue #12501: Adjust callable() warning: callable() is only not supported in
|
||||||
Python 3.1. callable() is again supported in Python 3.2.
|
Python 3.1. callable() is again supported in Python 3.2.
|
||||||
|
|
||||||
|
|
|
@ -1013,6 +1013,8 @@ subtype_dealloc(PyObject *self)
|
||||||
assert(basedealloc);
|
assert(basedealloc);
|
||||||
basedealloc(self);
|
basedealloc(self);
|
||||||
|
|
||||||
|
PyType_Modified(type);
|
||||||
|
|
||||||
/* Can't reference self beyond this point */
|
/* Can't reference self beyond this point */
|
||||||
Py_DECREF(type);
|
Py_DECREF(type);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue