aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 26e146031..e8c549542 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 cbf48c135..013e36468 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()