diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-03-23 12:47:33 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-03-23 13:01:04 -0300 |
commit | 26c960fc8e893a4edc655d8548a5ec56f7262bc4 (patch) | |
tree | 8a8ebe14958eb4b5bbb1992ceeab25bcd37438f5 | |
parent | a38c294732542b8d25ca1a34856c2ffa4fa2b1ac (diff) |
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.h | 2 | ||||
-rwxr-xr-x | tests/samplebinding/voidholder_test.py | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h index 541e026b3..35f22d38f 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 8d08d1fdf..a6fce2e00 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() |