aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-02-24 17:52:46 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-02-24 18:19:24 -0300
commitea10af7b04f581034a32bf1f051ad0d024cfcc9c (patch)
tree9370f0b9ac774b4f7e7ee7486f57a8c562ffa3ba /libshiboken
parentdb98871a87cf4c74f4e54b1b7185edf9ad0c0db4 (diff)
Adds a 'new' function to the SbkBaseWrapperType meta type.
When a Python programmer extends a wrapped C++ class the newly created type must inherit its parent class' special information (e.g. multiple inheritance casting). The 'new' function for the wrapper meta type copies the parent information for the extended type. As it is now the meta type new works properly only with a Python class inheriting from a single wrapped C++ type. Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Diffstat (limited to 'libshiboken')
-rw-r--r--libshiboken/basewrapper.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 05276b7fa..6ec023465 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -215,6 +215,26 @@ bool importModule(const char* moduleName, PyTypeObject*** cppApiPtr)
// Wrapper metatype and base type ----------------------------------------------------------
+static PyObject*
+SbkBaseWrapperType_TpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds)
+{
+ // The meta type creates a new type when the Python programmer extends a wrapped C++ class.
+ SbkBaseWrapperType* newType = reinterpret_cast<SbkBaseWrapperType*>(PyType_Type.tp_new(metatype, args, kwds));
+
+ if (!newType)
+ return 0;
+
+ // This expects that Python classes will inherit from only one C++ wrapped class.
+ SbkBaseWrapperType* parentType = reinterpret_cast<SbkBaseWrapperType*>(PyTuple_GET_ITEM(PyTuple_GET_ITEM(args, 1), 0));
+
+ newType->mi_offsets = parentType->mi_offsets;
+ newType->mi_init = parentType->mi_init;
+ newType->mi_specialcast = parentType->mi_specialcast;
+ newType->type_name_func = parentType->type_name_func;
+
+ return reinterpret_cast<PyObject*>(newType);
+}
+
extern "C"
{
@@ -259,7 +279,7 @@ PyTypeObject SbkBaseWrapperType_Type = {
/*tp_dictoffset*/ 0,
/*tp_init*/ 0,
/*tp_alloc*/ 0,
- /*tp_new*/ 0,
+ /*tp_new*/ SbkBaseWrapperType_TpNew,
/*tp_free*/ 0,
/*tp_is_gc*/ 0,
/*tp_bases*/ 0,