diff options
author | Guido van Rossum <guido@python.org> | 2001-12-05 22:45:48 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-12-05 22:45:48 (GMT) |
commit | 33bab01da6e2634231bdaa4f03405f4e5a043d59 (patch) | |
tree | 9408a488d290e80d96d55746bf441b3d007fff95 /Lib/test | |
parent | 9145be431023f74bd9532590e271395c1381aaf1 (diff) | |
download | cpython-33bab01da6e2634231bdaa4f03405f4e5a043d59.zip cpython-33bab01da6e2634231bdaa4f03405f4e5a043d59.tar.gz cpython-33bab01da6e2634231bdaa4f03405f4e5a043d59.tar.bz2 |
Fix SF bug #489581: __slots__ leak.
It was easier than I thought, assuming that no other things contribute
to the instance size besides slots -- a pretty good bet. With a test
suite, no less!
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_descr.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index b73025b..481ca0f 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -1000,6 +1000,40 @@ def slots(): vereq(x.b, 2) vereq(x.c, 3) + # Test leaks + class Counted(object): + counter = 0 # counts the number of instances alive + def __init__(self): + Counted.counter += 1 + def __del__(self): + Counted.counter -= 1 + class C(object): + __slots__ = ['a', 'b', 'c'] + x = C() + x.a = Counted() + x.b = Counted() + x.c = Counted() + vereq(Counted.counter, 3) + del x + vereq(Counted.counter, 0) + class D(C): + pass + x = D() + x.a = Counted() + x.z = Counted() + vereq(Counted.counter, 2) + del x + vereq(Counted.counter, 0) + class E(D): + __slots__ = ['e'] + x = E() + x.a = Counted() + x.z = Counted() + x.e = Counted() + vereq(Counted.counter, 3) + del x + vereq(Counted.counter, 0) + def dynamics(): if verbose: print "Testing class attribute propagation..." class D(object): |