summaryrefslogtreecommitdiff
path: root/Lib/test/test_weakref.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-01-23 22:41:20 +0000
committerBrett Cannon <bcannon@gmail.com>2007-01-23 22:41:20 +0000
commit75ba075110bbb3dcac6e975540bf8eda65774ec1 (patch)
tree012de9cedbf5036184d8bbbea0ec4da61ea1f00f /Lib/test/test_weakref.py
parent601d03a5be6a6952ecb57750f0365d6ef2abd4eb (diff)
downloadcpython-git-75ba075110bbb3dcac6e975540bf8eda65774ec1.tar.gz
If you created a weakref in an object's __del__ method to itself it would
segfault the interpreter during weakref clean up. Now any new weakrefs created after __del__ is run are removed silently. Fixes bug #1377858 and the weakref_in_del crasher for new-style classes. Classic classes are still affected.
Diffstat (limited to 'Lib/test/test_weakref.py')
-rw-r--r--Lib/test/test_weakref.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 18ab4012fb..c669109f08 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -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):