mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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!
This commit is contained in:
parent
9145be4310
commit
33bab01da6
3 changed files with 59 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue