summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-03-23 12:47:33 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-03-23 13:01:04 -0300
commit26c960fc8e893a4edc655d8548a5ec56f7262bc4 (patch)
tree8a8ebe14958eb4b5bbb1992ceeab25bcd37438f5
parenta38c294732542b8d25ca1a34856c2ffa4fa2b1ac (diff)
downloadshiboken-26c960fc8e893a4edc655d8548a5ec56f7262bc4.tar.gz
shiboken-26c960fc8e893a4edc655d8548a5ec56f7262bc4.tar.xz
shiboken-26c960fc8e893a4edc655d8548a5ec56f7262bc4.zip
Fixes Converter<void*>::toPython method.
The void* converter transforms a C++ NULL pointer in a Python None. An unit test for this case was added as well. Reviewed by Anderson Lizardo <anderson.lizardo@openbossa.org> Reviewed by Bruno Ara├║jo <bruno.araujo@openbossa.org>
-rw-r--r--libshiboken/conversions.h2
-rwxr-xr-xtests/samplebinding/voidholder_test.py6
2 files changed, 8 insertions, 0 deletions
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h
index 541e026b..35f22d38 100644
--- a/libshiboken/conversions.h
+++ b/libshiboken/conversions.h
@@ -179,6 +179,8 @@ struct Converter<void*>
static inline bool isConvertible(PyObject* pyobj) { return true; }
static PyObject* toPython(const void* cppobj)
{
+ if (!cppobj)
+ Py_RETURN_NONE;
PyObject* pyobj = BindingManager::instance().retrieveWrapper(cppobj);
if (pyobj)
Py_INCREF(pyobj);
diff --git a/tests/samplebinding/voidholder_test.py b/tests/samplebinding/voidholder_test.py
index 8d08d1fd..a6fce2e0 100755
--- a/tests/samplebinding/voidholder_test.py
+++ b/tests/samplebinding/voidholder_test.py
@@ -45,6 +45,12 @@ class VoidHolderTest(unittest.TestCase):
voidholder = VoidHolder(obj)
self.assertEquals(obj, voidholder.voidPointer())
+ def testGetNoneObjectFromVoidHolder(self):
+ '''A VoidHolder created without parameters returns a NULL pointer
+ that should be converted to a Python None.'''
+ voidholder = VoidHolder()
+ self.assertEquals(voidholder.voidPointer(), None)
+
if __name__ == '__main__':
unittest.main()