diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-15 13:17:36 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-12-15 13:17:36 (GMT) |
commit | d73a9acb633883a713fe63dbe67b36b3bddec902 (patch) | |
tree | 26fedb768d21152bd2a19c72258efe85827702a1 | |
parent | 96ff0840b68a9568d859a7bef2f59e851f811ae3 (diff) | |
parent | 2e872082f620e2fa96fe37dc6a5c3cb5b55bdcbd (diff) | |
download | cpython-d73a9acb633883a713fe63dbe67b36b3bddec902.zip cpython-d73a9acb633883a713fe63dbe67b36b3bddec902.tar.gz cpython-d73a9acb633883a713fe63dbe67b36b3bddec902.tar.bz2 |
Fix the fix for issue #12149: it was incorrect, although it had the side
effect of appearing to resolve the issue. Thanks to Mark Shannon for
noticing.
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Objects/typeobject.c | 18 |
2 files changed, 14 insertions, 8 deletions
@@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Fix the fix for issue #12149: it was incorrect, although it had the side + effect of appearing to resolve the issue. Thanks to Mark Shannon for + noticing. + - Issue #13505: Pickle bytes objects in a way that is compatible with Python 2 when using protocols <= 2. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 5383eee..02999d6 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -999,8 +999,6 @@ subtype_dealloc(PyObject *self) assert(basedealloc); basedealloc(self); - PyType_Modified(type); - /* Can't reference self beyond this point */ Py_DECREF(type); @@ -2776,15 +2774,16 @@ type_clear(PyTypeObject *type) for heaptypes. */ assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); - /* The only field we need to clear is tp_mro, which is part of a - hard cycle (its first element is the class itself) that won't - be broken otherwise (it's a tuple and tuples don't have a + /* We need to invalidate the method cache carefully before clearing + the dict, so that other objects caught in a reference cycle + don't start calling destroyed methods. + + Otherwise, the only field we need to clear is tp_mro, which is + part of a hard cycle (its first element is the class itself) that + won't be broken otherwise (it's a tuple and tuples don't have a tp_clear handler). None of the other fields need to be cleared, and here's why: - tp_dict: - It is a dict, so the collector will call its tp_clear. - tp_cache: Not used; if it were, it would be a dict. @@ -2801,6 +2800,9 @@ type_clear(PyTypeObject *type) A tuple of strings can't be part of a cycle. */ + PyType_Modified(type); + if (type->tp_dict) + PyDict_Clear(type->tp_dict); Py_CLEAR(type->tp_mro); return 0; |