[Python-checkins]
python/dist/src/Lib/test test_weakref.py, 1.28.6.4, 1.28.6.5
fdrake at users.sourceforge.net
fdrake at users.sourceforge.net
Wed Feb 4 18:13:46 EST 2004
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21840/Lib/test
Modified Files:
Tag: release23-maint
test_weakref.py
Log Message:
Allocating a new weakref object can cause existing weakref objects for
the same object to be collected by the cyclic GC support if they are
only referenced by a cycle. If the weakref being collected was one of
the weakrefs without callbacks, some local variables for the
constructor became invalid and have to be re-computed.
The test caused a segfault under a debug build without the fix applied.
Index: test_weakref.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_weakref.py,v
retrieving revision 1.28.6.4
retrieving revision 1.28.6.5
diff -C2 -d -r1.28.6.4 -r1.28.6.5
*** test_weakref.py 3 Feb 2004 20:18:20 -0000 1.28.6.4
--- test_weakref.py 4 Feb 2004 23:13:43 -0000 1.28.6.5
***************
*** 1,2 ****
--- 1,3 ----
+ import gc
import sys
import unittest
***************
*** 593,596 ****
--- 594,628 ----
self.assertEqual(alist, [])
+ def test_gc_during_ref_creation(self):
+ self.check_gc_during_creation(weakref.ref)
+
+ def test_gc_during_proxy_creation(self):
+ self.check_gc_during_creation(weakref.proxy)
+
+ def check_gc_during_creation(self, makeref):
+ thresholds = gc.get_threshold()
+ gc.set_threshold(1, 1, 1)
+ gc.collect()
+ class A:
+ pass
+
+ def callback(*args):
+ pass
+
+ referenced = A()
+
+ a = A()
+ a.a = a
+ a.wr = makeref(referenced)
+
+ try:
+ # now make sure the object and the ref get labeled as
+ # cyclic trash:
+ a = A()
+ a.wrc = weakref.ref(referenced, callback)
+
+ finally:
+ gc.set_threshold(*thresholds)
+
class Object:
def __init__(self, arg):
More information about the Python-checkins
mailing list