[Python-checkins] python/dist/src/Lib/test test_descr.py,1.137,1.138

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 04 Jun 2002 12:52:55 -0700


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

Modified Files:
	test_descr.py 
Log Message:
Address SF bug 519621: slots weren't traversed by GC.

While I was at it, I added a tp_clear handler and changed the
tp_dealloc handler to use the clear_slots helper for the tp_clear
handler.

Also tightened the rules for slot names: they must now be proper
identifiers (ignoring the dirty little fact that <ctype.h> is locale
sensitive).

Also set mp->flags = READONLY for the __weakref__ pseudo-slot.

Most of this is a 2.2 bugfix candidate; I'll apply it there myself.



Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.137
retrieving revision 1.138
diff -C2 -d -r1.137 -r1.138
*** test_descr.py	4 Jun 2002 06:10:37 -0000	1.137
--- test_descr.py	4 Jun 2002 19:52:53 -0000	1.138
***************
*** 1061,1064 ****
--- 1061,1103 ----
      vereq(x.c, 3)
  
+     # Make sure slot names are proper identifiers
+     try:
+         class C(object):
+             __slots__ = [None]
+     except TypeError:
+         pass
+     else:
+         raise TestFailed, "[None] slots not caught"
+     try:
+         class C(object):
+             __slots__ = ["foo bar"]
+     except TypeError:
+         pass
+     else:
+         raise TestFailed, "['foo bar'] slots not caught"
+     try:
+         class C(object):
+             __slots__ = ["foo\0bar"]
+     except TypeError:
+         pass
+     else:
+         raise TestFailed, "['foo\\0bar'] slots not caught"
+     try:
+         class C(object):
+             __slots__ = ["1"]
+     except TypeError:
+         pass
+     else:
+         raise TestFailed, "['1'] slots not caught"
+     try:
+         class C(object):
+             __slots__ = [""]
+     except TypeError:
+         pass
+     else:
+         raise TestFailed, "[''] slots not caught"
+     class C(object):
+         __slots__ = ["a", "a_b", "_a", "A0123456789Z"]
+ 
      # Test leaks
      class Counted(object):
***************
*** 1093,1096 ****
--- 1132,1147 ----
      vereq(Counted.counter, 3)
      del x
+     vereq(Counted.counter, 0)
+ 
+     # Test cyclical leaks [SF bug 519621]
+     class F(object):
+         __slots__ = ['a', 'b']
+     log = []
+     s = F()
+     s.a = [Counted(), s]
+     vereq(Counted.counter, 1)
+     s = None
+     import gc
+     gc.collect()
      vereq(Counted.counter, 0)