diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-15 01:20:07 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-18 09:22:50 -0300 |
commit | 1081714f5275261420a74ac333a117fd2bbca0c4 (patch) | |
tree | 6c0b17ba834516b10d0fe713ba9b80682ee4ee0d /cppgenerator.h | |
parent | 80282277d0845a65739c33675aa9a91b10faa4b1 (diff) |
Shiboken retrieves a Python wrapper object from its corresponding
C++ object using the memory address of the former to retrieve the
latter. When multiple inheritance is involved, a C++ object passed
to C++ could be caught back downcasted to one of its parents with
a different memory address, following the memory layout for
multiple inheritance used by the compiler. This poses a problem
to keep the Python identity of a C++ object.
The solution was to extend the traditional PyTypeObject with a
number array with all the possible displacements to be added to
an object pointer to produce the memory addresses for the valid
pointers that could appear from all the possible type casts
involving the object parents. All the possible pointers are
registered (and unregistered) by the binding wrapper manager.
To store the multiple inheritance information the ShiboTypeObject
structure was created, expanding the original PyTypeObject with
two fields:
mi_offsets
an integer array containing the possible displacements from the
object base pointer. The array has the value -1 at its end.
mi_init
the function that will initialize the mi_offsets array it is
called at the first instaciation of a multiple inheriting object.
Diffstat (limited to 'cppgenerator.h')
-rw-r--r-- | cppgenerator.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/cppgenerator.h b/cppgenerator.h index a90e3da22..87df8e4a1 100644 --- a/cppgenerator.h +++ b/cppgenerator.h @@ -110,6 +110,17 @@ private: void writeFlagsUnaryOperator(QTextStream& s, const AbstractMetaEnum* cppEnum, QString pyOpName, QString cppOpName, bool boolResult = false); + /// Writes the function that registers the multiple inheritance information for the classes that need it. + void writeMultipleInheritanceInitializerFunction(QTextStream& s, const AbstractMetaClass* metaClass); + + /** + * Returns the multiple inheritance initializer function for the given class. + * \param metaClass the class for whom the function name must be generated. + * \return name of the multiple inheritance information initializer function or + * an empty string if there is no multiple inheritance in its ancestry. + */ + QString multipleInheritanceInitializerFunctionName(const AbstractMetaClass* metaClass); + /// Returns true if the given class supports the python sequence protocol bool supportsSequenceProtocol(const AbstractMetaClass* metaClass); // Maps special function names to function parameters and return types |