mirror of
https://github.com/python/cpython.git
synced 2025-07-30 06:34:15 +00:00
Fix crasher for when an object's __del__ creates a new weakref to itself.
Patch only fixes new-style classes; classic classes still buggy. Closes bug #1377858. Already backported.
This commit is contained in:
parent
6c5c502b91
commit
f5bee30e30
5 changed files with 34 additions and 1 deletions
|
@ -6,6 +6,8 @@ import weakref
|
|||
|
||||
from test import test_support
|
||||
|
||||
# Used in ReferencesTestCase.test_ref_created_during_del() .
|
||||
ref_from_del = None
|
||||
|
||||
class C:
|
||||
def method(self):
|
||||
|
@ -630,6 +632,18 @@ class ReferencesTestCase(TestBase):
|
|||
finally:
|
||||
gc.set_threshold(*thresholds)
|
||||
|
||||
def test_ref_created_during_del(self):
|
||||
# Bug #1377858
|
||||
# A weakref created in an object's __del__() would crash the
|
||||
# interpreter when the weakref was cleaned up since it would refer to
|
||||
# non-existent memory. This test should not segfault the interpreter.
|
||||
class Target(object):
|
||||
def __del__(self):
|
||||
global ref_from_del
|
||||
ref_from_del = weakref.ref(self)
|
||||
|
||||
w = Target()
|
||||
|
||||
|
||||
class SubclassableWeakrefTestCase(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue