summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-01-23 23:21:22 (GMT)
committerBrett Cannon <bcannon@gmail.com>2007-01-23 23:21:22 (GMT)
commitf5bee30e30687447d9d532dc298ba0793beb4515 (patch)
tree429f3a16538dc9c832f2b04f74f9200f95121b23 /Lib
parent6c5c502b914261ba333e98c4657a8d90cfbbe872 (diff)
downloadcpython-f5bee30e30687447d9d532dc298ba0793beb4515.zip
cpython-f5bee30e30687447d9d532dc298ba0793beb4515.tar.gz
cpython-f5bee30e30687447d9d532dc298ba0793beb4515.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/crashers/weakref_in_del.py3
-rw-r--r--Lib/test/test_weakref.py14
2 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/crashers/weakref_in_del.py b/Lib/test/crashers/weakref_in_del.py
index 3bbcfc3..2e9b186 100644
--- a/Lib/test/crashers/weakref_in_del.py
+++ b/Lib/test/crashers/weakref_in_del.py
@@ -1,11 +1,12 @@
import weakref
# http://python.org/sf/1377858
+# Fixed for new-style classes in 2.5c1.
ref = None
def test_weakref_in_del():
- class Target(object):
+ class Target():
def __del__(self):
global ref
ref = weakref.ref(self)
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index d2e4d34..6ca283c 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):