diff options
-rw-r--r-- | cppgenerator.cpp | 40 | ||||
-rw-r--r-- | headergenerator.cpp | 10 | ||||
-rw-r--r-- | libshiboken/basewrapper.cpp | 22 | ||||
-rw-r--r-- | libshiboken/basewrapper.h | 65 | ||||
-rw-r--r-- | libshiboken/bindingmanager.cpp | 18 | ||||
-rw-r--r-- | libshiboken/bindingmanager.h | 15 | ||||
-rw-r--r-- | libshiboken/conversions.h | 14 | ||||
-rw-r--r-- | libshiboken/pyenum.cpp | 22 | ||||
-rw-r--r-- | libshiboken/pyenum.h | 12 | ||||
-rw-r--r-- | shibokengenerator.cpp | 8 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 6 |
11 files changed, 117 insertions, 115 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index c24dccfc9..f7fea0c10 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -1163,7 +1163,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f if (func->isConstructor()) { QString className = cpythonTypeName(func->ownerClass()); - s << INDENT << "self = Shiboken::PyBaseWrapper_New(type, cptr"; + s << INDENT << "self = Shiboken::SbkBaseWrapper_New(type, cptr"; // If the created C++ object has a C++ wrapper the ownership is assigned to Python // (first "1") and the flag indicating that the Python wrapper holds an C++ wrapper // is marked as true (the second "1"). Otherwise the default values apply: @@ -1212,7 +1212,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f s << INDENT; if (arg_mod.ownerships[TypeSystem::TargetLangCode] == TypeSystem::TargetLangOwnership) - s << "PyBaseWrapper_setOwnership(" << pyArgName << ", true"; + s << "SbkBaseWrapper_setOwnership(" << pyArgName << ", true"; else if (wrappedClass->hasVirtualDestructor()) s << "BindingManager::instance().transferOwnershipToCpp(" << pyArgName; else @@ -1342,7 +1342,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* if (metaClass->isNamespace() || metaClass->hasPrivateDestructor()) { tp_flags = "Py_TPFLAGS_HAVE_CLASS"; tp_dealloc = metaClass->hasPrivateDestructor() ? - "(destructor)Shiboken::PyBaseWrapper_Dealloc_PrivateDtor" : "0"; + "(destructor)Shiboken::SbkBaseWrapper_Dealloc_PrivateDtor" : "0"; tp_new = "0"; } else { tp_flags = "Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES"; @@ -1352,7 +1352,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* deallocClassName = wrapperName(metaClass); else deallocClassName = cppClassName; - tp_dealloc = QString("(destructor)&(Shiboken::PyBaseWrapper_Dealloc< %1 >)").arg(deallocClassName); + tp_dealloc = QString("(destructor)&(Shiboken::SbkBaseWrapper_Dealloc< %1 >)").arg(deallocClassName); AbstractMetaFunctionList ctors = metaClass->queryFunctions(AbstractMetaClass::Constructors); tp_new = ctors.isEmpty() ? "0" : className + "_New"; @@ -1391,7 +1391,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* s << INDENT << "PyObject_HEAD_INIT(&PyType_Type)" << endl; s << INDENT << "/*ob_size*/ 0," << endl; s << INDENT << "/*tp_name*/ \"" << cppClassName << "\"," << endl; - s << INDENT << "/*tp_basicsize*/ sizeof(Shiboken::PyBaseWrapper)," << endl; + s << INDENT << "/*tp_basicsize*/ sizeof(Shiboken::SbkBaseWrapper)," << endl; s << INDENT << "/*tp_itemsize*/ 0," << endl; s << INDENT << "/*tp_dealloc*/ " << tp_dealloc << ',' << endl; s << INDENT << "/*tp_print*/ 0," << endl; @@ -1676,7 +1676,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl s << INDENT << '}'; } - s << " else goto Py" << metaClass->name() << "_RichComparison_TypeError;" << endl; + s << " else goto Sbk" << metaClass->name() << "_RichComparison_TypeError;" << endl; s << endl; s << INDENT << "break;" << endl; @@ -1696,7 +1696,7 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl s << INDENT << "Py_RETURN_TRUE;" << endl; } s << INDENT << "Py_RETURN_FALSE;" << endl << endl; - s << INDENT << "Py" << metaClass->name() << "_RichComparison_TypeError:" << endl; + s << INDENT << "Sbk" << metaClass->name() << "_RichComparison_TypeError:" << endl; { Indentation indent(INDENT); s << INDENT << "PyErr_SetString(PyExc_TypeError, \"operator called with wrong parameters.\");" << endl; @@ -1736,7 +1736,7 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu QString cpythonName = cpythonEnumName(cppEnum); QString addFunction; if (cppEnum->enclosingClass()) { - addFunction = QString("PyDict_SetItemString(Py") + addFunction = QString("PyDict_SetItemString(Sbk") + cppEnum->enclosingClass()->name() + "_Type.pytype.tp_dict,"; } else { @@ -1774,7 +1774,7 @@ void CppGenerator::writeEnumInitialization(QTextStream& s, const AbstractMetaEnu if (cppEnum->typeEntry()->isEnumValueRejected(enumValue->name())) continue; - s << INDENT << "enum_item = Shiboken::PyEnumObject_New(&"; + s << INDENT << "enum_item = Shiboken::SbkEnumObject_New(&"; s << cpythonName << "_Type," << endl; { Indentation indent(INDENT); @@ -1807,7 +1807,7 @@ void CppGenerator::writeFlagsNewMethod(QTextStream& s, const FlagsTypeEntry* cpp Indentation indent(INDENT); s << INDENT << "return 0;" << endl; } - s << INDENT << "PyObject* self = Shiboken::PyEnumObject_New(type, item_value);" << endl << endl; + s << INDENT << "PyObject* self = Shiboken::SbkEnumObject_New(type, item_value);" << endl << endl; s << INDENT << "if (!self)" << endl; { Indentation indent(INDENT); @@ -1824,7 +1824,7 @@ void CppGenerator::writeEnumDefinition(QTextStream& s, const AbstractMetaEnum* c tp_as_number = QString("&%1_as_number").arg(cpythonName); s << "static PyGetSetDef " << cpythonName << "_getsetlist[] = {" << endl; - s << INDENT << "{const_cast<char*>(\"name\"), (getter)Shiboken::PyEnumObject_name}," << endl; + s << INDENT << "{const_cast<char*>(\"name\"), (getter)Shiboken::SbkEnumObject_name}," << endl; s << INDENT << "{0} // Sentinel" << endl; s << "};" << endl << endl; @@ -1832,20 +1832,20 @@ void CppGenerator::writeEnumDefinition(QTextStream& s, const AbstractMetaEnum* c s << INDENT << "PyObject_HEAD_INIT(&PyType_Type)" << endl; s << INDENT << "/*ob_size*/ 0," << endl; s << INDENT << "/*tp_name*/ \"" << cppEnum->name() << "\"," << endl; - s << INDENT << "/*tp_basicsize*/ sizeof(Shiboken::PyEnumObject)," << endl; + s << INDENT << "/*tp_basicsize*/ sizeof(Shiboken::SbkEnumObject)," << endl; s << INDENT << "/*tp_itemsize*/ 0," << endl; s << INDENT << "/*tp_dealloc*/ 0," << endl; s << INDENT << "/*tp_print*/ 0," << endl; s << INDENT << "/*tp_getattr*/ 0," << endl; s << INDENT << "/*tp_setattr*/ 0," << endl; s << INDENT << "/*tp_compare*/ 0," << endl; - s << INDENT << "/*tp_repr*/ Shiboken::PyEnumObject_repr," << endl; + s << INDENT << "/*tp_repr*/ Shiboken::SbkEnumObject_repr," << endl; s << INDENT << "/*tp_as_number*/ " << tp_as_number << ',' << endl; s << INDENT << "/*tp_as_sequence*/ 0," << endl; s << INDENT << "/*tp_as_mapping*/ 0," << endl; s << INDENT << "/*tp_hash*/ 0," << endl; s << INDENT << "/*tp_call*/ 0," << endl; - s << INDENT << "/*tp_str*/ Shiboken::PyEnumObject_repr," << endl; + s << INDENT << "/*tp_str*/ Shiboken::SbkEnumObject_repr," << endl; s << INDENT << "/*tp_getattro*/ 0," << endl; s << INDENT << "/*tp_setattro*/ 0," << endl; s << INDENT << "/*tp_as_buffer*/ 0," << endl; @@ -1867,7 +1867,7 @@ void CppGenerator::writeEnumDefinition(QTextStream& s, const AbstractMetaEnum* c s << INDENT << "/*tp_dictoffset*/ 0," << endl; s << INDENT << "/*tp_init*/ 0," << endl; s << INDENT << "/*tp_alloc*/ 0," << endl; - s << INDENT << "/*tp_new*/ Shiboken::PyEnumObject_NonExtensibleNew," << endl; + s << INDENT << "/*tp_new*/ Shiboken::SbkEnumObject_NonExtensibleNew," << endl; s << INDENT << "/*tp_free*/ 0," << endl; s << INDENT << "/*tp_is_gc*/ 0," << endl; s << INDENT << "/*tp_bases*/ 0," << endl; @@ -1956,20 +1956,20 @@ void CppGenerator::writeFlagsDefinition(QTextStream& s, const AbstractMetaEnum* s << INDENT << "PyObject_HEAD_INIT(&PyType_Type)" << endl; s << INDENT << "/*ob_size*/ 0," << endl; s << INDENT << "/*tp_name*/ \"" << flagsEntry->flagsName() << "\"," << endl; - s << INDENT << "/*tp_basicsize*/ sizeof(Shiboken::PyEnumObject)," << endl; + s << INDENT << "/*tp_basicsize*/ sizeof(Shiboken::SbkEnumObject)," << endl; s << INDENT << "/*tp_itemsize*/ 0," << endl; s << INDENT << "/*tp_dealloc*/ 0," << endl; s << INDENT << "/*tp_print*/ 0," << endl; s << INDENT << "/*tp_getattr*/ 0," << endl; s << INDENT << "/*tp_setattr*/ 0," << endl; s << INDENT << "/*tp_compare*/ 0," << endl; - s << INDENT << "/*tp_repr*/ Shiboken::PyEnumObject_repr," << endl; + s << INDENT << "/*tp_repr*/ Shiboken::SbkEnumObject_repr," << endl; s << INDENT << "/*tp_as_number*/ 0," << endl; s << INDENT << "/*tp_as_sequence*/ 0," << endl; s << INDENT << "/*tp_as_mapping*/ 0," << endl; s << INDENT << "/*tp_hash*/ 0," << endl; s << INDENT << "/*tp_call*/ 0," << endl; - s << INDENT << "/*tp_str*/ Shiboken::PyEnumObject_repr," << endl; + s << INDENT << "/*tp_str*/ Shiboken::SbkEnumObject_repr," << endl; s << INDENT << "/*tp_getattro*/ 0," << endl; s << INDENT << "/*tp_setattro*/ 0," << endl; s << INDENT << "/*tp_as_buffer*/ 0," << endl; @@ -2014,7 +2014,7 @@ void CppGenerator::writeFlagsBinaryOperator(QTextStream& s, const AbstractMetaEn s << INDENT << "return Shiboken::Converter< " << flagsEntry->originalName() << " >::toPython(" << endl; { Indentation indent(INDENT); - s << INDENT << "((" << flagsEntry->originalName() << ") ((PyEnumObject*)self)->ob_ival)" << endl; + s << INDENT << "((" << flagsEntry->originalName() << ") ((SbkEnumObject*)self)->ob_ival)" << endl; s << INDENT << cppOpName << " Shiboken::Converter< "; s << flagsEntry->originalName() << " >::toCpp(arg)" << endl; } @@ -2032,7 +2032,7 @@ void CppGenerator::writeFlagsInplaceOperator(QTextStream& s, const AbstractMetaE s << cpythonEnumName(cppEnum) << "___" << pyOpName << "__(PyObject* self, PyObject* arg)" << endl; s << '{' << endl; - s << INDENT << "((" << flagsEntry->originalName() << ") ((PyEnumObject*)self)->ob_ival) " << cppOpName << endl; + s << INDENT << "((" << flagsEntry->originalName() << ") ((SbkEnumObject*)self)->ob_ival) " << cppOpName << endl; s << INDENT << "Shiboken::Converter< " << flagsEntry->originalName() << " >::toCpp(arg);" << endl; s << INDENT << "Py_INCREF(self);" << endl; diff --git a/headergenerator.cpp b/headergenerator.cpp index 69681c45e..fe35eb445 100644 --- a/headergenerator.cpp +++ b/headergenerator.cpp @@ -246,8 +246,8 @@ void HeaderGenerator::finishGeneration() s_pts << "PyAPI_FUNC(PyObject*) " << cpythonBaseName(metaClass->typeEntry()); s_pts << "_New(PyTypeObject* type, PyObject* args, PyObject* kwds);" << endl; writeTypeCheckMacro(s_pts, classType); - s_pts << "#define Py" << metaClass->name() << "_cptr(pyobj) (("; - s_pts << metaClass->name() << "*)PyBaseWrapper_cptr(pyobj))" << endl << endl; + s_pts << "#define Sbk" << metaClass->name() << "_cptr(pyobj) (("; + s_pts << metaClass->name() << "*)SbkBaseWrapper_cptr(pyobj))" << endl << endl; writeTypeConverterDecl(convDecl, classType); convDecl << endl; } @@ -353,18 +353,18 @@ void HeaderGenerator::writePyTypeFunction(QTextStream& s, const AbstractMetaEnum QString enumPrefix; if (cppEnum->enclosingClass()) enumPrefix = cppEnum->enclosingClass()->qualifiedCppName() + "::"; - s << "template<>\ninline PyTypeObject* PyType<" << enumPrefix << cppEnum->name() << " >() " + s << "template<>\ninline PyTypeObject* SbkType<" << enumPrefix << cppEnum->name() << " >() " << "{ return &" << cpythonTypeName(cppEnum->typeEntry()) << "; }\n"; FlagsTypeEntry* flag = cppEnum->typeEntry()->flags(); if (flag) { - s << "template<>\ninline PyTypeObject* PyType<" << flag->name() << " >() " + s << "template<>\ninline PyTypeObject* SbkType<" << flag->name() << " >() " << "{ return &" << cpythonTypeName(flag) << "; }\n"; } } void HeaderGenerator::writePyTypeFunction(QTextStream& s, const AbstractMetaClass* cppClass) { - s << "template<>\ninline PyTypeObject* PyType<" << cppClass->qualifiedCppName() << " >() " + s << "template<>\ninline PyTypeObject* SbkType<" << cppClass->qualifiedCppName() << " >() " << "{ return reinterpret_cast<PyTypeObject*>(&" << cpythonTypeName(cppClass) << "); }\n"; } diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp index 3a2bc9964..6653c8ab5 100644 --- a/libshiboken/basewrapper.cpp +++ b/libshiboken/basewrapper.cpp @@ -39,7 +39,7 @@ namespace Shiboken { -void removeParent(PyBaseWrapper* child) +void removeParent(SbkBaseWrapper* child) { if (child->parentInfo->parent) { ShiboChildrenList& oldBrothers = child->parentInfo->parent->parentInfo->children; @@ -56,8 +56,8 @@ void setParent(PyObject* parent, PyObject* child) bool parentIsNull = !parent || parent == Py_None; - PyBaseWrapper* parent_ = reinterpret_cast<PyBaseWrapper*>(parent); - PyBaseWrapper* child_ = reinterpret_cast<PyBaseWrapper*>(child); + SbkBaseWrapper* parent_ = reinterpret_cast<SbkBaseWrapper*>(parent); + SbkBaseWrapper* child_ = reinterpret_cast<SbkBaseWrapper*>(child); if (!child_->parentInfo) child_->parentInfo = new ShiboParentInfo; @@ -84,13 +84,13 @@ void setParent(PyObject* parent, PyObject* child) } } -static void _destroyParentInfo(PyBaseWrapper* obj, bool removeFromParent) +static void _destroyParentInfo(SbkBaseWrapper* obj, bool removeFromParent) { if (removeFromParent && obj->parentInfo->parent) removeParent(obj); ShiboChildrenList::iterator it = obj->parentInfo->children.begin(); for (; it != obj->parentInfo->children.end(); ++it) { - PyBaseWrapper*& child = *it; + SbkBaseWrapper*& child = *it; _destroyParentInfo(child, false); Py_DECREF(child); } @@ -98,13 +98,13 @@ static void _destroyParentInfo(PyBaseWrapper* obj, bool removeFromParent) obj->parentInfo = 0; } -void destroyParentInfo(PyBaseWrapper* obj, bool removeFromParent) +void destroyParentInfo(SbkBaseWrapper* obj, bool removeFromParent) { BindingManager::instance().invalidateWrapper(obj); _destroyParentInfo(obj, removeFromParent); } -PyObject* PyBaseWrapper_New(PyTypeObject* instanceType, +PyObject* SbkBaseWrapper_New(PyTypeObject* instanceType, const void* cptr, unsigned int hasOwnership, unsigned int containsCppWrapper) @@ -113,7 +113,7 @@ PyObject* PyBaseWrapper_New(PyTypeObject* instanceType, return 0; ShiboTypeObject* const& instanceType_ = reinterpret_cast<ShiboTypeObject*>(instanceType); - PyBaseWrapper* self = (PyBaseWrapper*)instanceType_->pytype.tp_alloc((PyTypeObject*) instanceType, 0); + SbkBaseWrapper* self = (SbkBaseWrapper*)instanceType_->pytype.tp_alloc((PyTypeObject*) instanceType, 0); self->cptr = const_cast<void*>(cptr); self->hasOwnership = hasOwnership; @@ -139,16 +139,16 @@ PyObject* PyBaseWrapper_New(PyTypeObject* instanceType, bool cppObjectIsInvalid(PyObject* wrapper) { - if (wrapper == Py_None || ((Shiboken::PyBaseWrapper*)wrapper)->validCppObject) + if (wrapper == Py_None || ((Shiboken::SbkBaseWrapper*)wrapper)->validCppObject) return false; PyErr_SetString(PyExc_RuntimeError, "internal C++ object already deleted."); return true; } -void PyBaseWrapper_Dealloc_PrivateDtor(PyObject* self) +void SbkBaseWrapper_Dealloc_PrivateDtor(PyObject* self) { BindingManager::instance().releaseWrapper(self); - Py_TYPE(((PyBaseWrapper*)self))->tp_free((PyObject*)self); + Py_TYPE(((SbkBaseWrapper*)self))->tp_free((PyObject*)self); } } // namespace Shiboken diff --git a/libshiboken/basewrapper.h b/libshiboken/basewrapper.h index a9279ef6c..9187a775b 100644 --- a/libshiboken/basewrapper.h +++ b/libshiboken/basewrapper.h @@ -42,10 +42,10 @@ namespace Shiboken { -struct PyBaseWrapper; +struct SbkBaseWrapper; -/// Linked list of PyBaseWrapper pointers -typedef std::list<PyBaseWrapper*> ShiboChildrenList; +/// Linked list of SbkBaseWrapper pointers +typedef std::list<SbkBaseWrapper*> ShiboChildrenList; /// Struct used to store information about object parent and children. struct LIBSHIBOKEN_API ShiboParentInfo @@ -53,7 +53,7 @@ struct LIBSHIBOKEN_API ShiboParentInfo /// Default ctor. ShiboParentInfo() : parent(0) {} /// Pointer to parent object. - PyBaseWrapper* parent; + SbkBaseWrapper* parent; /// List of object children. ShiboChildrenList children; }; @@ -81,7 +81,7 @@ struct LIBSHIBOKEN_API ShiboTypeObject }; /// Base Python object for all the wrapped C++ classes. -struct LIBSHIBOKEN_API PyBaseWrapper +struct LIBSHIBOKEN_API SbkBaseWrapper { PyObject_HEAD /// Pointer to the C++ class. @@ -110,32 +110,32 @@ LIBSHIBOKEN_API void setParent(PyObject* parent, PyObject* child); * Remove this child from their parent, if any. * \param child the child. */ -LIBSHIBOKEN_API void removeParent(PyBaseWrapper* child); +LIBSHIBOKEN_API void removeParent(SbkBaseWrapper* child); /** -* \internal This is an internal function called by PyBaseWrapper_Dealloc, it's exported just for techinical reasons. +* \internal This is an internal function called by SbkBaseWrapper_Dealloc, it's exported just for techinical reasons. * \note Do not call this function inside your bindings. */ -LIBSHIBOKEN_API void destroyParentInfo(PyBaseWrapper* obj, bool removeFromParent = true); +LIBSHIBOKEN_API void destroyParentInfo(SbkBaseWrapper* obj, bool removeFromParent = true); /** - * Shiboken_TypeCheck macro performs a type check using the values registered with PyType<>() template. + * Shiboken_TypeCheck macro performs a type check using the values registered with SbkType<>() template. */ -#define Shiboken_TypeCheck(pyobj, type) (PyObject_TypeCheck(pyobj, PyType<type>())) +#define Shiboken_TypeCheck(pyobj, type) (PyObject_TypeCheck(pyobj, SbkType<type>())) -#define PyBaseWrapper_Check(op) PyObject_TypeCheck(op, &Shiboken::PyBaseWrapper_Type) -#define PyBaseWrapper_CheckExact(op) ((op)->ob_type == &Shiboken::PyBaseWrapper_Type) +#define SbkBaseWrapper_Check(op) PyObject_TypeCheck(op, &Shiboken::SbkBaseWrapper_Type) +#define SbkBaseWrapper_CheckExact(op) ((op)->ob_type == &Shiboken::SbkBaseWrapper_Type) -#define PyBaseWrapper_cptr(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->cptr) -#define PyBaseWrapper_setCptr(pyobj,c) (((Shiboken::PyBaseWrapper*)pyobj)->cptr = c) -#define PyBaseWrapper_hasOwnership(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->hasOwnership) -#define PyBaseWrapper_setOwnership(pyobj,o) (((Shiboken::PyBaseWrapper*)pyobj)->hasOwnership = o) -#define PyBaseWrapper_hasParentInfo(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->parentInfo) -#define PyBaseWrapper_containsCppWrapper(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->containsCppWrapper) -#define PyBaseWrapper_setContainsCppWrapper(pyobj,o)(((Shiboken::PyBaseWrapper*)pyobj)->containsCppWrapper= o) -#define PyBaseWrapper_validCppObject(pyobj) (((Shiboken::PyBaseWrapper*)pyobj)->validCppObject) -#define PyBaseWrapper_setValidCppObject(pyobj,v) (((Shiboken::PyBaseWrapper*)pyobj)->validCppObject = v) +#define SbkBaseWrapper_cptr(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->cptr) +#define SbkBaseWrapper_setCptr(pyobj,c) (((Shiboken::SbkBaseWrapper*)pyobj)->cptr = c) +#define SbkBaseWrapper_hasOwnership(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->hasOwnership) +#define SbkBaseWrapper_setOwnership(pyobj,o) (((Shiboken::SbkBaseWrapper*)pyobj)->hasOwnership = o) +#define SbkBaseWrapper_hasParentInfo(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->parentInfo) +#define SbkBaseWrapper_containsCppWrapper(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->containsCppWrapper) +#define SbkBaseWrapper_setContainsCppWrapper(pyobj,o)(((Shiboken::SbkBaseWrapper*)pyobj)->containsCppWrapper= o) +#define SbkBaseWrapper_validCppObject(pyobj) (((Shiboken::SbkBaseWrapper*)pyobj)->validCppObject) +#define SbkBaseWrapper_setValidCppObject(pyobj,v) (((Shiboken::SbkBaseWrapper*)pyobj)->validCppObject = v) /* The #defines below were taken from Cython-generated code to allow shiboken to be used with python2.5. * Maybe not all of these defines are useful to us, time will tell which ones are really needed or not. @@ -186,27 +186,28 @@ typedef struct { #endif LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) -PyBaseWrapper_New(PyTypeObject* instanceType, - const void *cptr, - unsigned int hasOwnership = 1, - unsigned int containsCppWrapper = 0); +SbkBaseWrapper_New(PyTypeObject* instanceType, + const void *cptr, + unsigned int hasOwnership = 1, + unsigned int containsCppWrapper = 0); /// Returns true and sets a Python RuntimeError if the Python wrapper is not marked as valid. LIBSHIBOKEN_API bool cppObjectIsInvalid(PyObject* wrapper); template <typename T> -void PyBaseWrapper_Dealloc(PyObject* self) +void SbkBaseWrapper_Dealloc(PyObject* self) { BindingManager::instance().releaseWrapper(self); - if (PyBaseWrapper_hasOwnership(self)) - delete ((T*)PyBaseWrapper_cptr(self)); - if (PyBaseWrapper_hasParentInfo(self)) - destroyParentInfo(reinterpret_cast<PyBaseWrapper*>(self)); - Py_TYPE(((PyBaseWrapper*)self))->tp_free((PyObject*)self); + if (SbkBaseWrapper_hasOwnership(self)) + delete ((T*)SbkBaseWrapper_cptr(self)); + if (SbkBaseWrapper_hasParentInfo(self)) + destroyParentInfo(reinterpret_cast<SbkBaseWrapper*>(self)); + Py_TYPE(((SbkBaseWrapper*)self))->tp_free((PyObject*)self); } -LIBSHIBOKEN_API PyAPI_FUNC(void) PyBaseWrapper_Dealloc_PrivateDtor(PyObject* self); +LIBSHIBOKEN_API PyAPI_FUNC(void) SbkBaseWrapper_Dealloc_PrivateDtor(PyObject* self); } // namespace Shiboken #endif // BASEWRAPPER_H + diff --git a/libshiboken/bindingmanager.cpp b/libshiboken/bindingmanager.cpp index 5788b1108..6b08829e7 100644 --- a/libshiboken/bindingmanager.cpp +++ b/libshiboken/bindingmanager.cpp @@ -86,7 +86,7 @@ void BindingManager::assignWrapper(PyObject* wrapper, const void* cptr) void BindingManager::releaseWrapper(PyObject* wrapper) { - void* cptr = PyBaseWrapper_cptr(wrapper); + void* cptr = SbkBaseWrapper_cptr(wrapper); m_d->releaseWrapper(cptr); if (((ShiboTypeObject*) wrapper->ob_type)->mi_offsets) { int* offset = ((ShiboTypeObject*) wrapper->ob_type)->mi_offsets; @@ -138,14 +138,14 @@ PyObject* BindingManager::getOverride(const void* cptr, const char* methodName) return 0; } -void BindingManager::invalidateWrapper(PyBaseWrapper* wrapper) +void BindingManager::invalidateWrapper(SbkBaseWrapper* wrapper) { - if (!PyBaseWrapper_validCppObject(wrapper)) + if (!SbkBaseWrapper_validCppObject(wrapper)) return; - PyBaseWrapper_setValidCppObject(wrapper, false); - PyBaseWrapper_setOwnership(wrapper, false); + SbkBaseWrapper_setValidCppObject(wrapper, false); + SbkBaseWrapper_setOwnership(wrapper, false); // If it is a parent invalidate all children. - if (PyBaseWrapper_hasParentInfo(wrapper)) { + if (SbkBaseWrapper_hasParentInfo(wrapper)) { ShiboChildrenList::iterator it = wrapper->parentInfo->children.begin(); for (; it != wrapper->parentInfo->children.end(); ++it) invalidateWrapper(*it); @@ -160,13 +160,13 @@ void BindingManager::invalidateWrapper(const void* cptr) invalidateWrapper(iter->second); } -void BindingManager::transferOwnershipToCpp(PyBaseWrapper* wrapper) +void BindingManager::transferOwnershipToCpp(SbkBaseWrapper* wrapper) { if (wrapper->parentInfo) Shiboken::removeParent(wrapper); - if (PyBaseWrapper_containsCppWrapper(wrapper)) - PyBaseWrapper_setOwnership(wrapper, false); + if (SbkBaseWrapper_containsCppWrapper(wrapper)) + SbkBaseWrapper_setOwnership(wrapper, false); else invalidateWrapper(wrapper); } diff --git a/libshiboken/bindingmanager.h b/libshiboken/bindingmanager.h index 602066f91..05e115412 100644 --- a/libshiboken/bindingmanager.h +++ b/libshiboken/bindingmanager.h @@ -41,7 +41,7 @@ namespace Shiboken { -struct PyBaseWrapper; +struct SbkBaseWrapper; class LIBSHIBOKEN_API BindingManager { @@ -55,21 +55,21 @@ public: PyObject* getOverride(const void* cptr, const char* methodName); /// Invalidate the Python wrapper and removes the relations from C++ pointers to the Python wrapper. - void invalidateWrapper(PyBaseWrapper* wrapper); - /// Convenience method to call invalidateWrapper with a properly cast PyBaseWrapper. + void invalidateWrapper(SbkBaseWrapper* wrapper); + /// Convenience method to call invalidateWrapper with a properly cast SbkBaseWrapper. inline void invalidateWrapper(PyObject* wrapper) { - invalidateWrapper(reinterpret_cast<PyBaseWrapper*>(wrapper)); + invalidateWrapper(reinterpret_cast<SbkBaseWrapper*>(wrapper)); } /// Convenience method to invalidate the Python wrapper for a C++ wrapped object. Do nothing if C++ pointer has no Python wrapper. void invalidateWrapper(const void* cptr); /// Transfers the ownership of a Python wrapper to C++. - void transferOwnershipToCpp(PyBaseWrapper* wrapper); - /// Convenience method to call transferOwnershipToCpp with a properly cast PyBaseWrapper. + void transferOwnershipToCpp(SbkBaseWrapper* wrapper); + /// Convenience method to call transferOwnershipToCpp with a properly cast SbkBaseWrapper. inline void transferOwnershipToCpp(PyObject* wrapper) { - transferOwnershipToCpp(reinterpret_cast<PyBaseWrapper*>(wrapper)); + transferOwnershipToCpp(reinterpret_cast<SbkBaseWrapper*>(wrapper)); } private: @@ -86,3 +86,4 @@ private: } // namespace Shiboken #endif // BINDINGMANAGER_H + diff --git a/libshiboken/conversions.h b/libshiboken/conversions.h index ce32eff5d..b33d4e748 100644 --- a/libshiboken/conversions.h +++ b/libshiboken/conversions.h @@ -54,7 +54,7 @@ namespace Shiboken * \see SpecialCastFunction */ template<typename T> -inline PyTypeObject* PyType() +inline PyTypeObject* SbkType() { assert(false); // This *SHOULD* never be called. return 0; @@ -68,7 +68,7 @@ struct ConverterBase { static PyObject* createWrapper(const T* cppobj) { - return Shiboken::PyBaseWrapper_New(PyType<T>(), cppobj);; + return Shiboken::SbkBaseWrapper_New(SbkType<T>(), cppobj);; } static T* copyCppObject(const T& cppobj) { return 0; } static bool isConvertible(PyObject* pyobj) { return pyobj == Py_None; } @@ -104,8 +104,8 @@ struct ConverterBase<T*> : ConverterBase<T> return 0; ShiboTypeObject* shiboType = reinterpret_cast<ShiboTypeObject*>(pyobj->ob_type); if (shiboType->mi_specialcast) - return (T*) shiboType->mi_specialcast(pyobj, reinterpret_cast<ShiboTypeObject*>(PyType<T>())); - return (T*) ((Shiboken::PyBaseWrapper*) pyobj)->cptr; + return (T*) shiboType->mi_specialcast(pyobj, reinterpret_cast<ShiboTypeObject*>(SbkType<T>())); + return (T*) ((Shiboken::SbkBaseWrapper*) pyobj)->cptr; } }; @@ -128,7 +128,7 @@ struct Converter<T*> : Converter<T> static T* toCpp(PyObject* pyobj) { if (Shiboken_TypeCheck(pyobj, T)) - return (T*) ((Shiboken::PyBaseWrapper*) pyobj)->cptr; + return (T*) ((Shiboken::SbkBaseWrapper*) pyobj)->cptr; else if (Converter<T>::isConvertible(pyobj)) return Converter<T>::copyCppObject(Converter<T>::toCpp(pyobj)); return 0; @@ -269,11 +269,11 @@ struct Converter_CppEnum { static PyObject* createWrapper(CppEnum cppobj) { - return PyEnumObject_New(PyType<CppEnum>(), (long)cppobj); + return SbkEnumObject_New(SbkType<CppEnum>(), (long)cppobj); } static CppEnum toCpp(PyObject* pyobj) { - return (CppEnum) ((Shiboken::PyEnumObject*)pyobj)->ob_ival; + return (CppEnum) ((Shiboken::SbkEnumObject*)pyobj)->ob_ival; } static PyObject* toPython(CppEnum cppenum) { diff --git a/libshiboken/pyenum.cpp b/libshiboken/pyenum.cpp index be15496a5..3a223ef08 100644 --- a/libshiboken/pyenum.cpp +++ b/libshiboken/pyenum.cpp @@ -38,24 +38,24 @@ namespace Shiboken { PyObject* -PyEnumObject_New(PyTypeObject *type, long item_value, PyObject* item_name) +SbkEnumObject_New(PyTypeObject *type, long item_value, PyObject* item_name) { if (!item_name) item_name = PyString_FromString(""); - PyEnumObject* enum_obj = (PyEnumObject*) type->tp_alloc(type, 0); + SbkEnumObject* enum_obj = (SbkEnumObject*) type->tp_alloc(type, 0); enum_obj->ob_name = item_name; enum_obj->ob_ival = item_value; return (PyObject*) enum_obj; } PyObject* -PyEnumObject_New(PyTypeObject *type, long item_value, const char* item_name) +SbkEnumObject_New(PyTypeObject *type, long item_value, const char* item_name) { PyObject* py_item_name = 0; if (item_name) py_item_name = PyString_FromString(item_name); - PyObject* enum_obj = PyEnumObject_New(type, item_value, py_item_name); + PyObject* enum_obj = SbkEnumObject_New(type, item_value, py_item_name); if (!enum_obj) { Py_XDECREF(py_item_name); return 0; @@ -77,7 +77,7 @@ extern "C" { PyObject* -PyEnumObject_NonExtensibleNew(PyTypeObject *type, PyObject *args, PyObject *kwds) +SbkEnumObject_NonExtensibleNew(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyErr_SetString(PyExc_TypeError, "enum is not extensible"); return 0; @@ -85,19 +85,19 @@ PyEnumObject_NonExtensibleNew(PyTypeObject *type, PyObject *args, PyObject *kwds PyObject* -PyEnumObject_repr(PyObject* self) +SbkEnumObject_repr(PyObject* self) { return PyString_FromFormat("<enum-item %s.%s (%ld)>", self->ob_type->tp_name, - PyString_AS_STRING(((PyEnumObject*)self)->ob_name), - ((PyEnumObject*)self)->ob_ival); + PyString_AS_STRING(((SbkEnumObject*)self)->ob_name), + ((SbkEnumObject*)self)->ob_ival); } PyObject* -PyEnumObject_name(PyObject* self) +SbkEnumObject_name(PyObject* self) { - Py_INCREF(((PyEnumObject*)self)->ob_name); - return ((PyEnumObject*)self)->ob_name; + Py_INCREF(((SbkEnumObject*)self)->ob_name); + return ((SbkEnumObject*)self)->ob_name; } } // extern "C" diff --git a/libshiboken/pyenum.h b/libshiboken/pyenum.h index 18dc6730c..4e7d6bf20 100644 --- a/libshiboken/pyenum.h +++ b/libshiboken/pyenum.h @@ -48,18 +48,18 @@ typedef struct { PyObject_HEAD long ob_ival; PyObject* ob_name; -} PyEnumObject; +} SbkEnumObject; -LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) PyEnumObject_repr(PyObject* self); -LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) PyEnumObject_name(PyObject* self); -LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) PyEnumObject_NonExtensibleNew(PyTypeObject* type, PyObject* args, PyObject* kwds); +LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) SbkEnumObject_repr(PyObject* self); +LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) SbkEnumObject_name(PyObject* self); +LIBSHIBOKEN_API PyAPI_FUNC(PyObject*) SbkEnumObject_NonExtensibleNew(PyTypeObject* type, PyObject* args, PyObject* kwds); } // extern "C" -LIBSHIBOKEN_API PyObject* PyEnumObject_New(PyTypeObject *instanceType, +LIBSHIBOKEN_API PyObject* SbkEnumObject_New(PyTypeObject *instanceType, long item_value, const char* item_name); -LIBSHIBOKEN_API PyObject* PyEnumObject_New(PyTypeObject *instanceType, +LIBSHIBOKEN_API PyObject* SbkEnumObject_New(PyTypeObject *instanceType, long item_value, PyObject* item_name = 0); diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index 314909d08..feb14b968 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -217,7 +217,7 @@ QString ShibokenGenerator::cpythonFunctionName(const AbstractMetaFunction* func) else result += func->name(); } else { - result = "Py" + moduleName() + "Module_" + func->name(); + result = "Sbk" + moduleName() + "Module_" + func->name(); } return result; @@ -225,7 +225,7 @@ QString ShibokenGenerator::cpythonFunctionName(const AbstractMetaFunction* func) static QString cpythonEnumFlagsName(QString moduleName, QString qualifiedCppName) { - QString result = QString("Py%1_%2").arg(moduleName).arg(qualifiedCppName); + QString result = QString("Sbk%1_%2").arg(moduleName).arg(qualifiedCppName); result.replace("::", "_"); return result; } @@ -376,7 +376,7 @@ QString ShibokenGenerator::cpythonBaseName(const TypeEntry* type) { QString baseName; if ((type->isObject() || type->isValue() || type->isNamespace())) { // && !type->isReference()) { - baseName = QString("Py") + type->name(); + baseName = QString("Sbk") + type->name(); } else if (type->isPrimitive()) { const PrimitiveTypeEntry* ptype = (const PrimitiveTypeEntry*) type; if (ptype->basicAliasedTypeEntry()) @@ -436,7 +436,7 @@ QString ShibokenGenerator::cpythonOperatorFunctionName(const AbstractMetaFunctio { if (!func->isOperatorOverload()) return QString(); - return QString("Py") + func->ownerClass()->name() + return QString("Sbk") + func->ownerClass()->name() + '_' + pythonOperatorFunctionName(func->originalName()); } diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index d27647de4..c3c5786ba 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -82,7 +82,7 @@ <inject-code class="native" position="beginning"> static void reparent_layout_items(PyObject* parent, PyObject* layout) { - const ObjectTypeList& objChildren = PyObjectTypeLayout_cptr(layout)->objects(); + const ObjectTypeList& objChildren = SbkObjectTypeLayout_cptr(layout)->objects(); ObjectTypeList::const_iterator it = objChildren.begin(); for (; it != objChildren.end(); ++it) { if ((*it)->isLayoutType()) { @@ -544,7 +544,7 @@ </modify-function> <modify-function signature="name()"> <inject-code class="native" position="end"> - PyStr_cptr(%0)->prepend(Str("Pimped")); + SbkStr_cptr(%0)->prepend(Str("Pimped")); </inject-code> </modify-function> <modify-function signature="callMe()"> @@ -755,7 +755,7 @@ <add-function signature="__setitem__" > <inject-code class="target" position="beginning"> PyObject* args = Py_BuildValue("(iO)", _i, _value); - PyObject* result = PyStr_set_char(self, args); + PyObject* result = SbkStr_set_char(self, args); Py_DECREF(args); int ok = result == Py_True; if (result) { |