diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-05 02:44:57 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-05 02:45:35 -0300 |
commit | 5b051968b2c73939bbca2e92296b6f546d911446 (patch) | |
tree | 99b1b98ad4282249975789ea0154d2f987d89ea8 /cppgenerator.cpp | |
parent | 7da644719810ab43d304101f21e0e514109ab86b (diff) |
Constructor initializes multiple inheritance information for Python derived classes.
The Python wrapper constructor for classes that have multiple inheritance
now copies the needed information (mi_offsets, mi_init and mi_specialcast)
from the nearest wrapped class parent in the inheritance hierarchy.
Diffstat (limited to 'cppgenerator.cpp')
-rw-r--r-- | cppgenerator.cpp | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index a4adea6ee..baf62d8d4 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -424,24 +424,28 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun { OverloadData overloadData(overloads, this); const AbstractMetaFunction* rfunc = overloadData.referenceFunction(); - QString className = cpythonTypeName(rfunc->ownerClass()); + const AbstractMetaClass* metaClass = rfunc->ownerClass(); + QString className = cpythonTypeName(metaClass); s << "PyObject*" << endl; - s << cpythonFunctionName(rfunc) << "(PyTypeObject *type, PyObject *args, PyObject *kwds)" << endl; + s << cpythonFunctionName(rfunc) << "(PyTypeObject* type, PyObject* args, PyObject* kwds)" << endl; s << '{' << endl; s << INDENT << "PyObject* self;" << endl; s << INDENT; - bool hasCppWrapper = shouldGenerateCppWrapper(rfunc->ownerClass()); - s << (hasCppWrapper ? wrapperName(rfunc->ownerClass()) : rfunc->ownerClass()->qualifiedCppName()); + bool hasCppWrapper = shouldGenerateCppWrapper(metaClass); + s << (hasCppWrapper ? wrapperName(metaClass) : metaClass->qualifiedCppName()); s << "* cptr;" << endl << endl; - if (rfunc->ownerClass()->isAbstract()) { + if (metaClass->isAbstract()) { s << INDENT << "if (type == (PyTypeObject*)&" << className << ") {" << endl; { Indentation indent(INDENT); s << INDENT << "PyErr_SetString(PyExc_NotImplementedError," << endl; - s << INDENT << INDENT << "\"'" << rfunc->ownerClass()->qualifiedCppName(); + { + Indentation indentation(INDENT); + s << INDENT << "\"'" << metaClass->qualifiedCppName(); + } s << "' represents a C++ abstract class and cannot be instanciated\");" << endl; s << INDENT << "return 0;" << endl; } @@ -449,7 +453,24 @@ void CppGenerator::writeConstructorWrapper(QTextStream& s, const AbstractMetaFun } s << INDENT << "if (!PyType_IsSubtype(type, (PyTypeObject*)&" << className << "))" << endl; - s << INDENT << INDENT << "return 0;" << endl << endl; + { + Indentation indentation(INDENT); + s << INDENT << "return 0;" << endl << endl; + } + + if (metaClass->baseClassNames().size() > 1) { + if (!metaClass->isAbstract()) + s << INDENT << "if (type != (PyTypeObject*)&" << className << ") {" << endl; + { + Indentation indentation(INDENT); + s << INDENT << "ShiboTypeObject* shibotype = reinterpret_cast<ShiboTypeObject*>(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; + } + if (!metaClass->isAbstract()) + s << INDENT << '}' << endl << endl; + } if (overloadData.maxArgs() > 0) { s << endl << INDENT << "int numArgs = "; |