diff options
author | Guido van Rossum <guido@python.org> | 2002-06-04 19:52:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-06-04 19:52:53 (GMT) |
commit | 9923ffe2c0f96b1b79f2f5ae39b64b55e038c566 (patch) | |
tree | 7449f4009ac1d95cac9185ebad1d2d622546c708 /Lib | |
parent | e22bc1e84135765456dee6337e6e6f61245aa694 (diff) | |
download | cpython-9923ffe2c0f96b1b79f2f5ae39b64b55e038c566.zip cpython-9923ffe2c0f96b1b79f2f5ae39b64b55e038c566.tar.gz cpython-9923ffe2c0f96b1b79f2f5ae39b64b55e038c566.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_descr.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 61a52f8..aa71a2f 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1060,6 +1060,45 @@ def slots(): vereq(x.b, 2) 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): counter = 0 # counts the number of instances alive @@ -1094,6 +1133,18 @@ def slots(): 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) + def dynamics(): if verbose: print "Testing class attribute propagation..." class D(object): |