[Python-checkins] CVS: python/dist/src/Lib/test test_gc.py,1.12,1.12.10.1

Tim Peters tim_one@users.sourceforge.net
Thu, 28 Mar 2002 15:18:12 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv30082/221/Lib/test

Modified Files:
      Tag: release22-maint
	test_gc.py 
Log Message:
Backport of a new test to check the interaction between cyclic GC
and the trashcan mechanism.


Index: test_gc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_gc.py,v
retrieving revision 1.12
retrieving revision 1.12.10.1
diff -C2 -d -r1.12 -r1.12.10.1
*** test_gc.py	15 Oct 2001 22:49:27 -0000	1.12
--- test_gc.py	28 Mar 2002 23:18:08 -0000	1.12.10.1
***************
*** 172,175 ****
--- 172,203 ----
      apply(gc.set_threshold, thresholds)
  
+ class Ouch:
+     n = 0
+     def __del__(self):
+         Ouch.n = Ouch.n + 1
+         if Ouch.n % 7 == 0:
+             gc.collect()
+ 
+ def test_trashcan():
+     # "trashcan" is a hack to prevent stack overflow when deallocating
+     # very deeply nested tuples etc.  It works in part by abusing the
+     # type pointer and refcount fields, and that can yield horrible
+     # problems when gc tries to traverse the structures.
+     # If this test fails (as it does in 2.0, 2.1 and 2.2), it will
+     # most likely die via segfault.
+ 
+     gc.enable()
+     N = 200
+     for count in range(3):
+         t = []
+         for i in range(N):
+             t = [t, Ouch()]
+         u = []
+         for i in range(N):
+             u = [u, Ouch()]
+         v = {}
+         for i in range(N):
+             v = {1: v, 2: Ouch()}
+     gc.disable()
  
  def test_all():
***************
*** 188,191 ****
--- 216,220 ----
      run_test("__del__", test_del)
      run_test("saveall", test_saveall)
+     run_test("trashcan", test_trashcan)
  
  def test():