diff options
author | John Ehresman <jpe@wingware.com> | 2013-05-28 10:13:37 -0400 |
---|---|---|
committer | John Cummings <jcummings2@users.sf.net> | 2013-06-24 20:19:03 +0200 |
commit | 42f40dc10b715cd91d8d020a4708154a5d7f6a6d (patch) | |
tree | f1d3cb4d61468cf79760a3e9a16afb26bc4428ae /tests/samplebinding | |
parent | 79e32dd6c67cfbd0d0e2b163e6d1959ea5161465 (diff) |
Decref reference to type object
A decref is needed if the type is not subclassed when an instance
is deallocated
Change-Id: I2c64d7cb5b726c5bf108c1cbc5283cf315a5f8e9
Reviewed-by: John Cummings <jcummings2@users.sf.net>
Diffstat (limited to 'tests/samplebinding')
-rw-r--r-- | tests/samplebinding/objecttype_test.py | 12 | ||||
-rw-r--r-- | tests/samplebinding/privatedtor_test.py | 15 |
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/samplebinding/objecttype_test.py b/tests/samplebinding/objecttype_test.py index 57947e839..814e25839 100644 --- a/tests/samplebinding/objecttype_test.py +++ b/tests/samplebinding/objecttype_test.py @@ -101,5 +101,17 @@ class ObjectTypeTest(unittest.TestCase): shiboken.invalidate(parents) + def testClassDecref(self): + # Bug was that class PyTypeObject wasn't decrefed when instance died + before = sys.getrefcount(ObjectType) + + for i in range(1000): + obj = ObjectType() + shiboken.delete(obj) + + after = sys.getrefcount(ObjectType) + + self.assertLess(abs(before - after), 5) + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/privatedtor_test.py b/tests/samplebinding/privatedtor_test.py index 3101ebf17..795e526c3 100644 --- a/tests/samplebinding/privatedtor_test.py +++ b/tests/samplebinding/privatedtor_test.py @@ -30,6 +30,7 @@ import gc import sys import unittest +import shiboken from sample import PrivateDtor @@ -74,6 +75,20 @@ class PrivateDtorTest(unittest.TestCase): self.assertEqual(pd3.instanceCalls(), calls + 2) self.assertEqual(sys.getrefcount(pd3), refcnt) + def testClassDecref(self): + # Bug was that class PyTypeObject wasn't decrefed when instance + # was invalidated + + before = sys.getrefcount(PrivateDtor) + + for i in range(1000): + obj = PrivateDtor.instance() + shiboken.invalidate(obj) + + after = sys.getrefcount(PrivateDtor) + + self.assertLess(abs(before - after), 5) + if __name__ == '__main__': unittest.main() |