summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-07-27 14:24:46 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-07-27 17:23:47 -0300
commit21460348ae4a73877ecbcc610d5ccd66a390d0c1 (patch)
tree30eca97f07cf325d8397958ff760b02244c660d3
parent7bd306347b8d55343e783a340f8bdc723111944f (diff)
downloadshiboken-21460348ae4a73877ecbcc610d5ccd66a390d0c1.tar.gz
shiboken-21460348ae4a73877ecbcc610d5ccd66a390d0c1.tar.xz
shiboken-21460348ae4a73877ecbcc610d5ccd66a390d0c1.zip
BindingManager destructor now asserts if the wrapper map is empty.
The assertion is only used in debug mode. The duck punching test was altered to avoid failing when run with debug. Check the duck punching test file for a better explanation. Also added a debug helper method "showWrapperMap" to the binding manager, it shows the contents of the C pointer to Python wrapper mapping. Reviewed by Luciano Wolf <luciano.wolf@openbossa.org> Reviewed by Renato Ara├║jo <renato.filho@openbossa.org>
-rw-r--r--libshiboken/bindingmanager.cpp11
-rw-r--r--tests/samplebinding/duck_punching_test.py13
2 files changed, 24 insertions, 0 deletions
diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp
index 26e14603..e8c54954 100644
--- a/libshiboken/bindingmanager.cpp
+++ b/libshiboken/bindingmanager.cpp
@@ -43,6 +43,16 @@ namespace Shiboken
typedef google::dense_hash_map<const void*, PyObject*> WrapperMap;
+static void showWrapperMap(const WrapperMap& wrapperMap)
+{
+ printf("-------------------------------\n");
+ printf("WrapperMap: %p (size: %d)\n", &wrapperMap, (int) wrapperMap.size());
+ WrapperMap::const_iterator iter;
+ for (iter = wrapperMap.begin(); iter != wrapperMap.end(); ++iter)
+ printf("key: %p, value: %p (%s)\n", iter->first, iter->second, iter->second->ob_type->tp_name);
+ printf("-------------------------------\n");
+}
+
struct BindingManager::BindingManagerPrivate {
WrapperMap wrapperMapper;
void releaseWrapper(void* cptr);
@@ -75,6 +85,7 @@ BindingManager::BindingManager()
BindingManager::~BindingManager()
{
+ assert(m_d->wrapperMapper.size() == 0);
delete m_d;
}
diff --git a/tests/samplebinding/duck_punching_test.py b/tests/samplebinding/duck_punching_test.py
index cbf48c13..013e3646 100644
--- a/tests/samplebinding/duck_punching_test.py
+++ b/tests/samplebinding/duck_punching_test.py
@@ -68,6 +68,13 @@ class DuckPunchingTest(unittest.TestCase):
self.assertEqual(result1, result2)
self.assertEqual(result1, VirtualMethods.virtualMethod0(vm, pt, val, cpx, b) * self.multiplier)
+ # This is done to decrease the refcount of the vm object
+ # allowing the object wrapper to be deleted before the
+ # BindingManager. This is useful when compiling Shiboken
+ # for debug, since the BindingManager destructor has an
+ # assert that checks if the wrapper mapper is empty.
+ vm.virtualMethod0 = None
+
def testMonkeyPatchOnVirtualMethodWithInheritance(self):
'''Injects new 'virtualMethod0' on an object that inherits from VirtualMethods and makes C++ call it.'''
duck = Duck()
@@ -90,6 +97,8 @@ class DuckPunchingTest(unittest.TestCase):
self.assertEqual(result1, result2)
self.assertEqual(result1, VirtualMethods.virtualMethod0(duck, pt, val, cpx, b) * self.multiplier)
+ duck.virtualMethod0 = None
+
def testMonkeyPatchOnMethodWithStaticAndNonStaticOverloads(self):
'''Injects new 'exists' on a SimpleFile instance and makes C++ call it.'''
simplefile = SimpleFile('foobar')
@@ -112,6 +121,8 @@ class DuckPunchingTest(unittest.TestCase):
simplefile.exists()
self.assert_(self.duck_method_called)
+ simplefile.exists = None
+
def testMonkeyPatchOnMethodWithStaticAndNonStaticOverloadsWithInheritance(self):
'''Injects new 'exists' on an object that inherits from SimpleFile and makes C++ call it.'''
monkey = Monkey('foobar')
@@ -134,6 +145,8 @@ class DuckPunchingTest(unittest.TestCase):
monkey.exists()
self.assert_(self.duck_method_called)
+ monkey.exists = None
+
if __name__ == '__main__':
unittest.main()