aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-12-14 10:24:41 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-12-14 14:14:29 -0300
commitcdcb5567c77b3f703541839101cad564605b7f61 (patch)
treeea3ad5751a0ab5f3a3b14bc6b85da82c019463d5
parent0f31a28bcb0d802f461fd2012dd2a239decb81b0 (diff)
All wrapped classes now inherit from the SbkBaseWrapper of the metatype SbkBaseWrapperType.
The wrapped classes are described with a SbkBaseWrapperType structure which extends the PyTypeObject with information about multiple inheritance and parenting ownership. This works well for the classes produced by the generator but inheriting classes written in Python continues using the PyTypeObject to describe themselves. To fix this the SbkBaseWrapperType is now a metatype for all the wrapped classes and anyone inheriting from them. In addition all the wrapped classes now inherit from SbkBaseWrapper, since Python's PyType_Ready method need that multiple inheriting classes have a common base class with the same size of the classes involved in the multiple inheritance, which disqualifies Python's base "object" class. The metatype and the base wrapper type are initialized by calling the new Shiboken::init_shiboken() function. This is done by all the imported binding modules, but it is really run only in the first call. Another noteworthy change is the replacement of PyTypeObject as a basis for SbkBaseWrapperType by the PyHeapTypeObject, since the latter is the proper choice for types created on the heap, e.g. user defined classes extending the generated wrapper classes. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
-rw-r--r--cppgenerator.cpp61
-rw-r--r--headergenerator.cpp4
-rw-r--r--libshiboken/basewrapper.cpp163
-rw-r--r--libshiboken/basewrapper.h13
-rw-r--r--libshiboken/conversions.h2
-rw-r--r--shibokengenerator.cpp4
6 files changed, 193 insertions, 54 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 1999ed236..2b5c3c3e8 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -436,7 +436,7 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun
QString className = cpythonTypeName(metaClass);
s << "PyObject*" << endl;
- s << cpythonFunctionName(rfunc) << "(PyTypeObject* type, PyObject* args, PyObject* kwds)" << endl;
+ s << cpythonFunctionName(rfunc) << "(Shiboken::SbkBaseWrapperType* type, PyObject* args, PyObject* kwds)" << endl;
s << '{' << endl;
s << INDENT << "PyObject* self;" << endl;
@@ -446,7 +446,7 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun
s << "* cptr;" << endl << endl;
if (metaClass->isAbstract()) {
- s << INDENT << "if (type == (PyTypeObject*)&" << className << ") {" << endl;
+ s << INDENT << "if (type == &" << className << ") {" << endl;
{
Indentation indent(INDENT);
s << INDENT << "PyErr_SetString(PyExc_NotImplementedError," << endl;
@@ -460,7 +460,7 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun
s << INDENT << '}' << endl << endl;
}
- s << INDENT << "if (!PyType_IsSubtype(type, (PyTypeObject*)&" << className << "))" << endl;
+ s << INDENT << "if (!PyType_IsSubtype((PyTypeObject*)type, (PyTypeObject*)&" << className << "))" << endl;
{
Indentation indentation(INDENT);
s << INDENT << "return 0;" << endl << endl;
@@ -468,13 +468,12 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun
if (metaClass->baseClassNames().size() > 1) {
if (!metaClass->isAbstract())
- s << INDENT << "if (type != (PyTypeObject*)&" << className << ") {" << endl;
+ s << INDENT << "if (type != &" << className << ") {" << endl;
{
Indentation indentation(INDENT);
- s << INDENT << "SbkBaseWrapperType* shibotype = reinterpret_cast<SbkBaseWrapperType*>(type);" << endl;
- s << INDENT << "shibotype->mi_init = " << className << ".mi_init;" << endl;
- s << INDENT << "shibotype->mi_offsets = " << className << ".mi_offsets;" << endl;
- s << INDENT << "shibotype->mi_specialcast = " << className << ".mi_specialcast;" << endl;
+ s << INDENT << "type->mi_init = " << className << ".mi_init;" << endl;
+ s << INDENT << "type->mi_offsets = " << className << ".mi_offsets;" << endl;
+ s << INDENT << "type->mi_specialcast = " << className << ".mi_specialcast;" << endl;
}
if (!metaClass->isAbstract())
s << INDENT << '}' << endl << endl;
@@ -1327,10 +1326,10 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass*
QString tp_as_number('0');
QString tp_as_sequence('0');
QString mi_init('0');
- QString mi_specialCast('0');
+ QString mi_specialcast('0');
QString cppClassName = metaClass->qualifiedCppName();
QString className = cpythonTypeName(metaClass).replace(QRegExp("_Type$"), "");
- QString baseClassName;
+ QString baseClassName("(PyTypeObject*)&");
if (metaClass->hasArithmeticOperatorOverload()
|| metaClass->hasLogicalOperatorOverload()
@@ -1343,9 +1342,9 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass*
tp_as_sequence = QString("&Py%1_as_sequence").arg(cppClassName);
if (metaClass->baseClass())
- baseClassName = QString("(PyTypeObject*)&%1").arg(cpythonTypeName(metaClass->baseClass()->typeEntry()));
+ baseClassName.append(cpythonTypeName(metaClass->baseClass()->typeEntry()));
else
- baseClassName = QString("0");
+ baseClassName.append("Shiboken::SbkBaseWrapper_Type");
if (metaClass->isNamespace() || metaClass->hasPrivateDestructor()) {
tp_flags = "Py_TPFLAGS_HAVE_CLASS";
@@ -1353,7 +1352,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass*
"(destructor)Shiboken::SbkBaseWrapper_Dealloc_PrivateDtor" : "0";
tp_new = "0";
} else {
- tp_flags = "Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES";
+ tp_flags = "Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES";//|Py_TPFLAGS_HAVE_GC";
QString deallocClassName;
if (shouldGenerateCppWrapper(metaClass))
@@ -1363,7 +1362,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass*
tp_dealloc = QString("(destructor)&(Shiboken::SbkBaseWrapper_Dealloc< %1 >)").arg(deallocClassName);
AbstractMetaFunctionList ctors = metaClass->queryFunctions(AbstractMetaClass::Constructors);
- tp_new = ctors.isEmpty() ? "0" : className + "_New";
+ tp_new = ctors.isEmpty() ? "0" : QString("(newfunc)%1_New").arg(className);
}
QString tp_richcompare = QString('0');
@@ -1388,15 +1387,15 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass*
s << "extern int* " << multipleInheritanceInitializerFunctionName(miClass);
s << "(const void* cptr);" << endl;
}
- mi_specialCast = '&'+cpythonSpecialCastFunctionName(metaClass);
+ mi_specialcast = '&'+cpythonSpecialCastFunctionName(metaClass);
writeSpecialCastFunction(s, metaClass);
s << endl;
}
s << "// Class Definition -----------------------------------------------" << endl;
- s << "Shiboken::SbkBaseWrapperType " << className + "_Type" << " = { {" << endl;
- s << INDENT << "PyObject_HEAD_INIT(&PyType_Type)" << endl;
+ s << "Shiboken::SbkBaseWrapperType " << className + "_Type" << " = { { {" << endl;
+ s << INDENT << "PyObject_HEAD_INIT(&Shiboken::SbkBaseWrapperType_Type)" << endl;
s << INDENT << "/*ob_size*/ 0," << endl;
s << INDENT << "/*tp_name*/ \"" << cppClassName << "\"," << endl;
s << INDENT << "/*tp_basicsize*/ sizeof(Shiboken::SbkBaseWrapper)," << endl;
@@ -1433,19 +1432,19 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass*
s << INDENT << "/*tp_descr_set*/ 0," << endl;
s << INDENT << "/*tp_dictoffset*/ 0," << endl;
s << INDENT << "/*tp_init*/ 0," << endl;
- s << INDENT << "/*tp_alloc*/ PyType_GenericAlloc," << endl;
+ s << INDENT << "/*tp_alloc*/ 0," << endl;
s << INDENT << "/*tp_new*/ " << tp_new << ',' << endl;
- s << INDENT << "/*tp_free*/ PyObject_Del," << endl;
+ s << INDENT << "/*tp_free*/ 0," << endl;
s << INDENT << "/*tp_is_gc*/ 0," << endl;
s << INDENT << "/*tp_bases*/ 0," << endl;
s << INDENT << "/*tp_mro*/ 0," << endl;
s << INDENT << "/*tp_cache*/ 0," << endl;
s << INDENT << "/*tp_subclasses*/ 0," << endl;
s << INDENT << "/*tp_weaklist*/ 0" << endl;
- s << "}," << endl;
+ s << "}, }," << endl;
s << INDENT << "/*mi_offsets*/ 0," << endl;
s << INDENT << "/*mi_init*/ " << mi_init << ',' << endl;
- s << INDENT << "/*mi_specialCast*/ " << mi_specialCast << endl;
+ s << INDENT << "/*mi_specialcast*/ " << mi_specialcast << endl;
s << "};" << endl;
}
@@ -1747,7 +1746,7 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu
if (cppEnum->enclosingClass()) {
addFunction = QString("PyDict_SetItemString(Sbk")
+ cppEnum->enclosingClass()->name()
- + "_Type.pytype.tp_dict,";
+ + "_Type.super.ht_type.tp_dict,";
} else {
addFunction = "PyModule_AddObject(module,";
}
@@ -1806,7 +1805,7 @@ void CppGenerator::writeFlagsNewMethod(QTextStream& s, const FlagsTypeEntry* cpp
{
QString cpythonName = cpythonFlagsName(cppFlags);
s << "static PyObject*" << endl;
- s << cpythonName << "_New(PyTypeObject *type, PyObject *args, PyObject *kwds)" << endl;
+ s << cpythonName << "_New(PyTypeObject* type, PyObject* args, PyObject* kwds)" << endl;
s << '{' << endl;
s << INDENT << "if (!PyType_IsSubtype(type, &" << cpythonName << "_Type))" << endl;
s << INDENT << INDENT << "return 0;" << endl << endl;
@@ -2073,7 +2072,7 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m
{
QString pyTypeName = cpythonTypeName(metaClass);
s << "PyAPI_FUNC(void)" << endl;
- s << "init_" << metaClass->name().toLower() << "(PyObject *module)" << endl;
+ s << "init_" << metaClass->name().toLower() << "(PyObject* module)" << endl;
s << '{' << endl;
// class inject-code target/beginning
@@ -2084,7 +2083,7 @@ void CppGenerator::writeClassRegister(QTextStream& s, const AbstractMetaClass* m
// Multiple inheritance
if (metaClass->baseClassNames().size() > 1) {
- s << INDENT << pyTypeName << ".pytype.tp_bases = PyTuple_Pack(";
+ s << INDENT << pyTypeName << ".super.ht_type.tp_bases = PyTuple_Pack(";
s << metaClass->baseClassNames().size();
s << ',' << endl;
QStringList bases;
@@ -2340,6 +2339,7 @@ void CppGenerator::finishGeneration()
s << INDENT << "}" << endl << endl;
}
+ s << INDENT << "Shiboken::init_shiboken();" << endl;
s << INDENT << "PyObject* module = Py_InitModule(\"" << moduleName() << "\", ";
s << moduleName() << "_methods);" << endl << endl;
@@ -2363,9 +2363,14 @@ void CppGenerator::finishGeneration()
s << endl;
}
- s << INDENT << "if (PyErr_Occurred())" << endl;
- s << INDENT << INDENT << "Py_FatalError(\"can't initialize module ";
- s << moduleName() << "\");" << endl << '}' << endl << endl;
+ s << INDENT << "if (PyErr_Occurred()) {" << endl;
+ {
+ Indentation indentation(INDENT);
+ s << INDENT << "PyErr_Print();" << endl;
+ s << INDENT << "Py_FatalError(\"can't initialize module " << moduleName() << "\");" << endl;
+ }
+ s << INDENT << '}' << endl;
+ s << '}' << endl << endl;
s << "} // extern \"C\"" << endl << endl;
// module inject-code native/end
diff --git a/headergenerator.cpp b/headergenerator.cpp
index b13fb2bf1..e19bbc277 100644
--- a/headergenerator.cpp
+++ b/headergenerator.cpp
@@ -227,14 +227,14 @@ void HeaderGenerator::finishGeneration()
if (shouldGenerate(innerClass)) {
s_cin << innerClass->typeEntry()->include().toString() << endl;
s_pts << getApiExportMacro() << " PyAPI_FUNC(PyObject*) " << cpythonBaseName(innerClass->typeEntry());
- s_pts << "_New(PyTypeObject* type, PyObject* args, PyObject* kwds);" << endl;
+ s_pts << "_New(Shiboken::SbkBaseWrapperType* type, PyObject* args, PyObject* kwds);" << endl;
writeTypeCheckMacro(s_pts, innerClass->typeEntry());
writeTypeConverterDecl(convDecl, innerClass->typeEntry());
convDecl << endl;
}
}
s_pts << getApiExportMacro() << " PyAPI_FUNC(PyObject*) " << cpythonBaseName(metaClass->typeEntry());
- s_pts << "_New(PyTypeObject* type, PyObject* args, PyObject* kwds);" << endl;
+ s_pts << "_New(Shiboken::SbkBaseWrapperType* type, PyObject* args, PyObject* kwds);" << endl;
writeTypeCheckMacro(s_pts, classType);
s_pts << "#define Sbk" << metaClass->name() << "_cptr(pyobj) ((";
s_pts << metaClass->name() << "*)SbkBaseWrapper_cptr(pyobj))" << endl << endl;
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 397db1dff..eb7ee2b5d 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -41,12 +41,13 @@ namespace Shiboken
void removeParent(SbkBaseWrapper* child)
{
- if (child->parentInfo->parent) {
- ShiboChildrenList& oldBrothers = child->parentInfo->parent->parentInfo->children;
- oldBrothers.remove(child);
- child->parentInfo->parent = 0;
- Py_DECREF(child);
- }
+ if (!child->parentInfo->parent)
+ return;
+
+ ShiboChildrenList& oldBrothers = child->parentInfo->parent->parentInfo->children;
+ oldBrothers.remove(child);
+ child->parentInfo->parent = 0;
+ Py_DECREF(child);
}
void setParent(PyObject* parent, PyObject* child)
@@ -104,16 +105,18 @@ void destroyParentInfo(SbkBaseWrapper* obj, bool removeFromParent)
_destroyParentInfo(obj, removeFromParent);
}
-PyObject* SbkBaseWrapper_New(PyTypeObject* instanceType,
- const void* cptr,
- unsigned int hasOwnership,
- unsigned int containsCppWrapper)
+PyObject* SbkBaseWrapper_New(SbkBaseWrapperType* instanceType,
+ const void* cptr,
+ unsigned int hasOwnership,
+ unsigned int containsCppWrapper)
{
+ static PyObject* zeroargs = 0;
if (!cptr)
return 0;
+ else if (!zeroargs)
+ zeroargs = PyTuple_New(0);
- SbkBaseWrapperType* const& instanceType_ = reinterpret_cast<SbkBaseWrapperType*>(instanceType);
- SbkBaseWrapper* self = (SbkBaseWrapper*)instanceType_->pytype.tp_alloc((PyTypeObject*) instanceType, 0);
+ SbkBaseWrapper* self = reinterpret_cast<SbkBaseWrapper*>(PyBaseObject_Type.tp_new(reinterpret_cast<PyTypeObject*>(instanceType), zeroargs, 0));
self->cptr = const_cast<void*>(cptr);
self->hasOwnership = hasOwnership;
@@ -121,11 +124,11 @@ PyObject* SbkBaseWrapper_New(PyTypeObject* instanceType,
self->validCppObject = 1;
self->parentInfo = 0;
- if (instanceType_->mi_init && !instanceType_->mi_offsets)
- instanceType_->mi_offsets = instanceType_->mi_init(cptr);
+ if (instanceType->mi_init && !instanceType->mi_offsets)
+ instanceType->mi_offsets = instanceType->mi_init(cptr);
BindingManager::instance().assignWrapper(reinterpret_cast<PyObject*>(self), cptr);
- if (instanceType_->mi_offsets) {
- int* offset = instanceType_->mi_offsets;
+ if (instanceType->mi_offsets) {
+ int* offset = instanceType->mi_offsets;
while (*offset != -1) {
if (*offset > 0) {
BindingManager::instance().assignWrapper(reinterpret_cast<PyObject*>(self),
@@ -148,8 +151,134 @@ bool cppObjectIsInvalid(PyObject* wrapper)
void SbkBaseWrapper_Dealloc_PrivateDtor(PyObject* self)
{
BindingManager::instance().releaseWrapper(self);
- Py_TYPE(((SbkBaseWrapper*)self))->tp_free((PyObject*)self);
+ Py_TYPE(reinterpret_cast<SbkBaseWrapper*>(self))->tp_free(self);
}
+// Wrapper metatype and base type ----------------------------------------------------------
+
+extern "C"
+{
+
+struct SbkBaseWrapperType_Type;
+
+PyTypeObject SbkBaseWrapperType_Type = {
+ PyObject_HEAD_INIT(0)
+ /*ob_size*/ 0,
+ /*tp_name*/ "Shiboken.BaseWrapperType",
+ /*tp_basicsize*/ sizeof(SbkBaseWrapperType),
+ /*tp_itemsize*/ 0,
+ /*tp_dealloc*/ 0,
+ /*tp_print*/ 0,
+ /*tp_getattr*/ 0,
+ /*tp_setattr*/ 0,
+ /*tp_compare*/ 0,
+ /*tp_repr*/ 0,
+ /*tp_as_number*/ 0,
+ /*tp_as_sequence*/ 0,
+ /*tp_as_mapping*/ 0,
+ /*tp_hash*/ 0,
+ /*tp_call*/ 0,
+ /*tp_str*/ 0,
+ /*tp_getattro*/ 0,
+ /*tp_setattro*/ 0,
+ /*tp_as_buffer*/ 0,
+ /*tp_flags*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+ /*tp_doc*/ 0,
+ /*tp_traverse*/ 0,
+ /*tp_clear*/ 0,
+ /*tp_richcompare*/ 0,
+ /*tp_weaklistoffset*/ 0,
+ /*tp_iter*/ 0,
+ /*tp_iternext*/ 0,
+ /*tp_methods*/ 0,
+ /*tp_members*/ 0,
+ /*tp_getset*/ 0,
+ /*tp_base*/ 0,
+ /*tp_dict*/ 0,
+ /*tp_descr_get*/ 0,
+ /*tp_descr_set*/ 0,
+ /*tp_dictoffset*/ 0,
+ /*tp_init*/ 0,
+ /*tp_alloc*/ 0,
+ /*tp_new*/ 0,
+ /*tp_free*/ 0,
+ /*tp_is_gc*/ 0,
+ /*tp_bases*/ 0,
+ /*tp_mro*/ 0,
+ /*tp_cache*/ 0,
+ /*tp_subclasses*/ 0,
+ /*tp_weaklist*/ 0
+};
+
+SbkBaseWrapperType SbkBaseWrapper_Type = {
+ PyObject_HEAD_INIT(&SbkBaseWrapperType_Type)
+ /*ob_size*/ 0,
+ /*tp_name*/ "Shiboken.BaseWrapper",
+ /*tp_basicsize*/ sizeof(SbkBaseWrapper),
+ /*tp_itemsize*/ 0,
+ /*tp_dealloc*/ 0,
+ /*tp_print*/ 0,
+ /*tp_getattr*/ 0,
+ /*tp_setattr*/ 0,
+ /*tp_compare*/ 0,
+ /*tp_repr*/ 0,
+ /*tp_as_number*/ 0,
+ /*tp_as_sequence*/ 0,
+ /*tp_as_mapping*/ 0,
+ /*tp_hash*/ 0,
+ /*tp_call*/ 0,
+ /*tp_str*/ 0,
+ /*tp_getattro*/ 0,
+ /*tp_setattro*/ 0,
+ /*tp_as_buffer*/ 0,
+ /*tp_flags*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+ /*tp_doc*/ 0,
+ /*tp_traverse*/ 0,
+ /*tp_clear*/ 0,
+ /*tp_richcompare*/ 0,
+ /*tp_weaklistoffset*/ 0,
+ /*tp_iter*/ 0,
+ /*tp_iternext*/ 0,
+ /*tp_methods*/ 0,
+ /*tp_members*/ 0,
+ /*tp_getset*/ 0,
+ /*tp_base*/ 0,
+ /*tp_dict*/ 0,
+ /*tp_descr_get*/ 0,
+ /*tp_descr_set*/ 0,
+ /*tp_dictoffset*/ 0,
+ /*tp_init*/ 0,
+ /*tp_alloc*/ 0,
+ /*tp_new*/ 0,
+ /*tp_free*/ 0,
+ /*tp_is_gc*/ 0,
+ /*tp_bases*/ 0,
+ /*tp_mro*/ 0,
+ /*tp_cache*/ 0,
+ /*tp_subclasses*/ 0,
+ /*tp_weaklist*/ 0
+};
+
+PyAPI_FUNC(void) init_shiboken()
+{
+ static bool shibokenAlreadInitialised = false;
+ if (shibokenAlreadInitialised)
+ return;
+
+ SbkBaseWrapperType_Type.tp_base = &PyType_Type;
+
+ if (PyType_Ready(&SbkBaseWrapperType_Type) < 0)
+ Py_FatalError("[libshiboken] Failed to initialise Shiboken.BaseWrapperType metatype.");
+
+ if (PyType_Ready((PyTypeObject *)&SbkBaseWrapper_Type) < 0)
+ Py_FatalError("[libshiboken] Failed to initialise Shiboken.BaseWrapper type.");
+
+ shibokenAlreadInitialised = true;
+}
+
+} // extern "C"
+
} // namespace Shiboken
+
+
diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h
index 46471e5ed..5f781d547 100644
--- a/libshiboken/basewrapper.h
+++ b/libshiboken/basewrapper.h
@@ -70,10 +70,13 @@ struct SbkBaseWrapperType;
*/
typedef void* (*SpecialCastFunction)(PyObject*, SbkBaseWrapperType*);
+LIBSHIBOKEN_API PyAPI_DATA(PyTypeObject) SbkBaseWrapperType_Type;
+LIBSHIBOKEN_API PyAPI_DATA(SbkBaseWrapperType) SbkBaseWrapper_Type;
+
/// PyTypeObject extended with C++ multiple inheritance information.
struct LIBSHIBOKEN_API SbkBaseWrapperType
{
- PyTypeObject pytype;
+ PyHeapTypeObject super;
int* mi_offsets;
MultipleInheritanceInitFunction mi_init;
/// Special cast function, null if this class doesn't have multiple inheritance.
@@ -96,6 +99,8 @@ struct LIBSHIBOKEN_API SbkBaseWrapper
ShiboParentInfo* parentInfo;
};
+LIBSHIBOKEN_API PyAPI_FUNC(void) init_shiboken();
+
} // extern "C"
/**
@@ -186,7 +191,7 @@ typedef struct {
#endif
LIBSHIBOKEN_API PyAPI_FUNC(PyObject*)
-SbkBaseWrapper_New(PyTypeObject* instanceType,
+SbkBaseWrapper_New(SbkBaseWrapperType* instanceType,
const void *cptr,
unsigned int hasOwnership = 1,
unsigned int containsCppWrapper = 0);
@@ -199,10 +204,10 @@ void SbkBaseWrapper_Dealloc(PyObject* self)
{
BindingManager::instance().releaseWrapper(self);
if (SbkBaseWrapper_hasOwnership(self))
- delete ((T*)SbkBaseWrapper_cptr(self));
+ delete (reinterpret_cast<T*>(SbkBaseWrapper_cptr(self)));
if (SbkBaseWrapper_hasParentInfo(self))
destroyParentInfo(reinterpret_cast<SbkBaseWrapper*>(self));
- Py_TYPE(((SbkBaseWrapper*)self))->tp_free((PyObject*)self);
+ Py_TYPE(reinterpret_cast<SbkBaseWrapper*>(self))->tp_free(self);
}
LIBSHIBOKEN_API PyAPI_FUNC(void) SbkBaseWrapper_Dealloc_PrivateDtor(PyObject* self);
diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h
index 7b911b3ea..301a27212 100644
--- a/libshiboken/conversions.h
+++ b/libshiboken/conversions.h
@@ -79,7 +79,7 @@ struct ConverterBase
{
static PyObject* createWrapper(const T* cppobj)
{
- return Shiboken::SbkBaseWrapper_New(SbkType<T>(), cppobj);
+ return Shiboken::SbkBaseWrapper_New(reinterpret_cast<SbkBaseWrapperType*>(SbkType<T>()), cppobj);
}
static bool isConvertible(PyObject* pyobj) { return pyobj == Py_None; }
diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp
index ba3d03e35..b7644593d 100644
--- a/shibokengenerator.cpp
+++ b/shibokengenerator.cpp
@@ -879,7 +879,7 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s,
if (context) {
// replace template variable for the Python Type object for the
// class context in which the variable is used
- code.replace("%PYTHONTYPEOBJECT", cpythonTypeName(context) + ".pytype");
+ code.replace("%PYTHONTYPEOBJECT", cpythonTypeName(context) + ".super.ht_type");
}
// replace "toPython "converters
@@ -956,7 +956,7 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s,
// replace template variable for the Python Type object for the
// class implementing the method in which the code snip is written
if (func->isStatic()) {
- code.replace("%PYTHONTYPEOBJECT", cpythonTypeName(func->implementingClass()) + ".pytype");
+ code.replace("%PYTHONTYPEOBJECT", cpythonTypeName(func->implementingClass()) + ".super.ht_type");
} else {
code.replace("%PYTHONTYPEOBJECT.", QString("%1->ob_type->").arg(pySelf));
code.replace("%PYTHONTYPEOBJECT", QString("%1->ob_type").arg(pySelf));