diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-06-09 15:09:16 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-06-09 15:09:18 +0200 |
commit | 98fe750774ac252fe35c42b752e68108b594e43f (patch) | |
tree | 849e9ad1f5e558d610a6d42711eb9f6b49e35e02 /sources/shiboken2 | |
parent | 2635541daec35024390dc973ff16e7603c94ce39 (diff) | |
parent | 6d8dee0c92dc914a501e2e0fe3a5e044f5d6d872 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.9
Change-Id: I73f39966a2af7aa935e1890e29c9b71573aae97c
Diffstat (limited to 'sources/shiboken2')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 11 | ||||
-rw-r--r-- | sources/shiboken2/generator/shiboken2/headergenerator.cpp | 39 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/autodecref.h | 11 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/basewrapper.cpp | 8 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/conversions.h | 2 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/helper.cpp | 2 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/sbkconverter.cpp | 2 | ||||
-rw-r--r-- | sources/shiboken2/libshiboken/shibokenbuffer.cpp | 2 |
8 files changed, 50 insertions, 27 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 6aa2c83df..91ed7eec5 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -265,17 +265,6 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h")); s << endl << "// main header" << endl << "#include \"" << headerfile << '"' << endl; - // PYSIDE-500: Use also includes for inherited wrapper classes, because - // without the protected hack, we sometimes need to cast inherited wrappers. - s << endl << "// inherited wrapper classes" << endl; - AbstractMetaClass *basis = metaClass->baseClass(); - for (; basis; basis = basis->baseClass()) { - GeneratorContext basisContext(basis); - QString headerfile = fileNameForContext(basisContext); - headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h")); - s << "#include \"" << headerfile << '"' << endl; - } - s << endl << "// inner classes" << endl; const AbstractMetaClassList &innerClasses = metaClass->innerClasses(); for (AbstractMetaClass *innerClass : innerClasses) { diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index 6b8185dc9..9fde98d91 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -106,11 +106,12 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte } else { wrapperName = HeaderGenerator::wrapperName(classContext.preciseType()); } - QString headerGuard = getFilteredCppSignatureString(wrapperName).toUpper(); + QString outerHeaderGuard = getFilteredCppSignatureString(wrapperName).toUpper(); + QString innerHeaderGuard; // Header - s << "#ifndef SBK_" << headerGuard << "_H" << endl; - s << "#define SBK_" << headerGuard << "_H" << endl<< endl; + s << "#ifndef SBK_" << outerHeaderGuard << "_H" << endl; + s << "#define SBK_" << outerHeaderGuard << "_H" << endl << endl; if (!avoidProtectedHack()) s << "#define protected public" << endl << endl; @@ -120,10 +121,16 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte //Includes s << metaClass->typeEntry()->include() << endl; - if (shouldGenerateCppWrapper(metaClass)) { + if (shouldGenerateCppWrapper(metaClass) && + usePySideExtensions() && metaClass->isQObject()) + s << "namespace PySide { class DynamicQMetaObject; }\n\n"; - if (usePySideExtensions() && metaClass->isQObject()) - s << "namespace PySide { class DynamicQMetaObject; }\n\n"; + while (shouldGenerateCppWrapper(metaClass)) { + if (!innerHeaderGuard.isEmpty()) { + s << "# ifndef SBK_" << innerHeaderGuard << "_H" << endl; + s << "# define SBK_" << innerHeaderGuard << "_H" << endl << endl; + s << "// Inherited base class:" << endl; + } // Class s << "class " << wrapperName; @@ -173,15 +180,33 @@ void HeaderGenerator::generateClass(QTextStream &s, GeneratorContext &classConte if (m_inheritedOverloads.size()) { s << INDENT << "// Inherited overloads, because the using keyword sux" << endl; writeInheritedOverloads(s); + m_inheritedOverloads.clear(); } if (usePySideExtensions()) s << INDENT << "static void pysideInitQtMetaTypes();" << endl; s << "};" << endl << endl; + if (!innerHeaderGuard.isEmpty()) + s << "# endif // SBK_" << innerHeaderGuard << "_H" << endl << endl; + + // PYSIDE-500: Use also includes for inherited wrapper classes, because + // without the protected hack, we sometimes need to cast inherited wrappers. + // But we don't use multiple include files. Instead, they are inserted as recursive + // headers. This keeps the file structure as simple as before the enhanced inheritance. + metaClass = metaClass->baseClass(); + if (!metaClass || !avoidProtectedHack()) + break; + classContext = GeneratorContext(metaClass); + if (!classContext.forSmartPointer()) { + wrapperName = HeaderGenerator::wrapperName(metaClass); + } else { + wrapperName = HeaderGenerator::wrapperName(classContext.preciseType()); + } + innerHeaderGuard = getFilteredCppSignatureString(wrapperName).toUpper(); } - s << "#endif // SBK_" << headerGuard << "_H" << endl << endl; + s << "#endif // SBK_" << outerHeaderGuard << "_H" << endl << endl; } void HeaderGenerator::writeFunction(QTextStream& s, const AbstractMetaFunction* func) diff --git a/sources/shiboken2/libshiboken/autodecref.h b/sources/shiboken2/libshiboken/autodecref.h index 1fefcc259..a82bbb35c 100644 --- a/sources/shiboken2/libshiboken/autodecref.h +++ b/sources/shiboken2/libshiboken/autodecref.h @@ -43,6 +43,11 @@ #include "sbkpython.h" #include "basewrapper.h" +#ifdef _MSC_VER +__pragma(warning(push)) +__pragma(warning(disable:4522)) // warning: C4522: 'Shiboken::AutoDecRef': multiple assignment operators specified +#endif + struct SbkObject; namespace Shiboken { @@ -75,7 +80,7 @@ public: inline PyObject* object() { return m_pyObj; } inline operator PyObject*() { return m_pyObj; } inline operator PyTupleObject*() { return reinterpret_cast<PyTupleObject*>(m_pyObj); } - inline operator bool() const { return m_pyObj; } + inline operator bool() const { return m_pyObj != 0; } inline PyObject* operator->() { return m_pyObj; } template<typename T> @@ -111,5 +116,9 @@ private: } // namespace Shiboken +#ifdef _MSC_VER +__pragma(warning(pop)) +#endif + #endif // AUTODECREF_H diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index 5ecda1eaf..83e88c331 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -622,7 +622,7 @@ namespace ObjectType bool checkType(PyTypeObject* type) { - return PyType_IsSubtype(type, reinterpret_cast<PyTypeObject*>(&SbkObject_Type)); + return PyType_IsSubtype(type, reinterpret_cast<PyTypeObject*>(&SbkObject_Type)) != 0; } bool isUserType(PyTypeObject* type) @@ -651,7 +651,7 @@ void* callExternalCppConversion(SbkObjectType*, PyObject*) { return 0; } bool hasCast(SbkObjectType* type) { - return type->d->mi_specialcast; + return type->d->mi_specialcast != 0; } void* cast(SbkObjectType* sourceType, SbkObject* obj, PyTypeObject* targetType) @@ -1011,7 +1011,7 @@ void makeValid(SbkObject* self) bool hasParentInfo(SbkObject* pyObj) { - return pyObj->d->parentInfo; + return pyObj->d->parentInfo != 0; } void* cppPointer(SbkObject* pyObj, PyTypeObject* desiredType) @@ -1041,7 +1041,7 @@ bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr) if (reinterpret_cast<SbkObjectType*>(Py_TYPE(sbkObj))->d->is_multicpp) idx = getTypeIndexOnHierarchy(Py_TYPE(sbkObj), desiredType); - bool alreadyInitialized = sbkObj->d->cptr[idx]; + const bool alreadyInitialized = sbkObj->d->cptr[idx] != 0; if (alreadyInitialized) PyErr_SetString(PyExc_RuntimeError, "You can't initialize an object twice!"); else diff --git a/sources/shiboken2/libshiboken/conversions.h b/sources/shiboken2/libshiboken/conversions.h index f0af2be8e..a21fa0c2b 100644 --- a/sources/shiboken2/libshiboken/conversions.h +++ b/sources/shiboken2/libshiboken/conversions.h @@ -279,7 +279,7 @@ struct Converter<bool> static inline bool isConvertible(PyObject* pyobj) { return PyInt_Check(pyobj); } static inline PyObject* toPython(void* cppobj) { return toPython(*reinterpret_cast<bool*>(cppobj)); } static inline PyObject* toPython(bool cppobj) { return PyBool_FromLong(cppobj); } - static inline bool toCpp(PyObject* pyobj) { return PyInt_AS_LONG(pyobj); } + static inline bool toCpp(PyObject* pyobj) { return PyInt_AS_LONG(pyobj) != 0; } }; /** diff --git a/sources/shiboken2/libshiboken/helper.cpp b/sources/shiboken2/libshiboken/helper.cpp index 9709d0776..2249bf458 100644 --- a/sources/shiboken2/libshiboken/helper.cpp +++ b/sources/shiboken2/libshiboken/helper.cpp @@ -53,7 +53,7 @@ bool sequenceToArgcArgv(PyObject* argList, int* argc, char*** argv, const char* // Check all items Shiboken::AutoDecRef args(PySequence_Fast(argList, 0)); - int numArgs = PySequence_Fast_GET_SIZE(argList); + int numArgs = int(PySequence_Fast_GET_SIZE(argList)); for (int i = 0; i < numArgs; ++i) { PyObject* item = PySequence_Fast_GET_ITEM(args.object(), i); if (!PyBytes_Check(item) && !PyUnicode_Check(item)) diff --git a/sources/shiboken2/libshiboken/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp index b22b33705..2a51edd76 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkconverter.cpp @@ -516,7 +516,7 @@ bool pythonTypeIsObjectType(const SbkConverter *converter) bool pythonTypeIsWrapperType(const SbkConverter *converter) { - return converter->pointerToPython; + return converter->pointerToPython != 0; } SpecificConverter::SpecificConverter(const char* typeName) diff --git a/sources/shiboken2/libshiboken/shibokenbuffer.cpp b/sources/shiboken2/libshiboken/shibokenbuffer.cpp index 6cc617668..222deb3fa 100644 --- a/sources/shiboken2/libshiboken/shibokenbuffer.cpp +++ b/sources/shiboken2/libshiboken/shibokenbuffer.cpp @@ -43,7 +43,7 @@ bool Shiboken::Buffer::checkType(PyObject* pyObj) { - return PyObject_CheckReadBuffer(pyObj); + return PyObject_CheckReadBuffer(pyObj) != 0; } void* Shiboken::Buffer::getPointer(PyObject* pyObj, Py_ssize_t* size) |