From e25ed8d09b67a0b67dee4239513c00a6b7e701a4 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 9 Jun 2017 10:06:35 +0200 Subject: libshiboken: Fix/Silence some MSVC warnings autodecref.h(110): warning C4522: 'Shiboken::AutoDecRef': multiple assignment operators specified autodecref.h(78): warning C4800: 'PyObject *const ': forcing value to bool 'true' or 'false' (performance warning) conversions.h(282): warning C4800: 'long': forcing value to bool 'true' or 'false' (performance warning) basewrapper.cpp(625): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning) basewrapper.cpp(654): warning C4800: 'SpecialCastFunction': forcing value to bool 'true' or 'false' (performance warning) basewrapper.cpp(1014): warning C4800: 'Shiboken::ParentInfo *': forcing value to bool 'true' or 'false' (performance warning) basewrapper.cpp(1044): warning C4800: 'void *': forcing value to bool 'true' or 'false' (performance warning) helper.cpp(56): warning C4244: 'initializing': conversion from 'Py_ssize_t' to 'int', possible loss of data shibokenbuffer.cpp(46): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning) Change-Id: If1517fde8e7670f258a56f6d845a66ebb3d82141 Reviewed-by: Christian Tismer --- sources/shiboken2/libshiboken/autodecref.h | 11 ++++++++++- sources/shiboken2/libshiboken/basewrapper.cpp | 8 ++++---- sources/shiboken2/libshiboken/conversions.h | 2 +- sources/shiboken2/libshiboken/helper.cpp | 2 +- sources/shiboken2/libshiboken/sbkconverter.cpp | 2 +- sources/shiboken2/libshiboken/shibokenbuffer.cpp | 2 +- 6 files changed, 18 insertions(+), 9 deletions(-) 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(m_pyObj); } - inline operator bool() const { return m_pyObj; } + inline operator bool() const { return m_pyObj != 0; } inline PyObject* operator->() { return m_pyObj; } template @@ -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 b3f99a8a5..b319fea7e 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -624,7 +624,7 @@ namespace ObjectType bool checkType(PyTypeObject* type) { - return PyType_IsSubtype(type, reinterpret_cast(&SbkObject_Type)); + return PyType_IsSubtype(type, reinterpret_cast(&SbkObject_Type)) != 0; } bool isUserType(PyTypeObject* type) @@ -653,7 +653,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) @@ -1013,7 +1013,7 @@ void makeValid(SbkObject* self) bool hasParentInfo(SbkObject* pyObj) { - return pyObj->d->parentInfo; + return pyObj->d->parentInfo != 0; } void* cppPointer(SbkObject* pyObj, PyTypeObject* desiredType) @@ -1043,7 +1043,7 @@ bool setCppPointer(SbkObject* sbkObj, PyTypeObject* desiredType, void* cptr) if (reinterpret_cast(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 static inline bool isConvertible(PyObject* pyobj) { return PyInt_Check(pyobj); } static inline PyObject* toPython(void* cppobj) { return toPython(*reinterpret_cast(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 e7e9995b4..0b18e49d4 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkconverter.cpp @@ -517,7 +517,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) -- cgit v1.2.3 From 5ff239ac4f1b34e2b3317f0968a61658d8c586d6 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sun, 4 Jun 2017 19:53:50 +0200 Subject: Fix missing headers in PySide custom build PySide itself built fine after the additional includes were added for inheritance. But when a smaller project is built, suddenly header files are not found, because the inherited names are not expected by the deployment. Therefore, we do no longer add more includes, but insert recursive headers for the few relevant cases. So the includes become a little longer, but the names of the include files are those as before the enhanced inheritance. Task-number: PYSIDE-500 Change-Id: Iab456307a3c2365dfe1964dbe222b7d0efac7878 Reviewed-by: Friedemann Kleint Reviewed-by: Alexandru Croitor --- .../shiboken2/generator/shiboken2/cppgenerator.cpp | 11 ------ .../generator/shiboken2/headergenerator.cpp | 39 ++++++++++++++++++---- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 68b62477e..06300fc00 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -251,17 +251,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; foreach (AbstractMetaClass* innerClass, metaClass->innerClasses()) { GeneratorContext innerClassContext(innerClass); diff --git a/sources/shiboken2/generator/shiboken2/headergenerator.cpp b/sources/shiboken2/generator/shiboken2/headergenerator.cpp index 5ef5d5612..27a84f6a9 100644 --- a/sources/shiboken2/generator/shiboken2/headergenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/headergenerator.cpp @@ -107,11 +107,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; @@ -121,10 +122,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; @@ -172,15 +179,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) -- cgit v1.2.3 From 6d8dee0c92dc914a501e2e0fe3a5e044f5d6d872 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 1 Jun 2017 13:46:52 +0200 Subject: utils: Handle Symlinks Try to recreate the .so version symlinks correctly on Linux instead of copying the files. Task-number: PYSIDE-526 Change-Id: I3b015efe4f2f57abe418f171a8631d194ed08f65 Reviewed-by: Christian Tismer --- setup.py | 2 +- utils.py | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index ce309fe34..0b566545f 100644 --- a/setup.py +++ b/setup.py @@ -1217,7 +1217,7 @@ class pyside_build(_build): # Update rpath in PySide2 libs for srcname in pyside_libs: srcpath = os.path.join(package_path, srcname) - if os.path.isdir(srcpath): + if os.path.isdir(srcpath) or os.path.islink(srcpath): continue if not os.path.exists(srcpath): continue diff --git a/utils.py b/utils.py index f7be19d1b..a3f9a41d9 100644 --- a/utils.py +++ b/utils.py @@ -231,9 +231,28 @@ def copyfile(src, dst, force=True, vars=None): log.info("**Skiping copy file %s to %s. Source does not exists." % (src, dst)) return - log.info("Copying file %s to %s." % (src, dst)) - - shutil.copy2(src, dst) + if not os.path.islink(src): + log.info("Copying file %s to %s." % (src, dst)) + shutil.copy2(src, dst) + else: + linkTargetPath = os.path.realpath(src) + if os.path.dirname(linkTargetPath) == os.path.dirname(src): + linkTarget = os.path.basename(linkTargetPath) + linkName = os.path.basename(src) + currentDirectory = os.getcwd() + try: + targetDir = dst if os.path.isdir(dst) else os.path.dirname(dst) + os.chdir(targetDir) + if os.path.exists(linkName): + os.remove(linkName) + log.info("Symlinking %s -> %s in %s." % (linkName, linkTarget, targetDir)) + os.symlink(linkTarget, linkName) + except OSError: + log.error("%s -> %s: Error creating symlink" % (linkName, linkTarget)) + finally: + os.chdir(currentDirectory) + else: + log.error("%s -> %s: Can only create symlinks within the same directory" % (src, linkTargetPath)) return dst -- cgit v1.2.3