From 5662706937bd6a1449538539e3a503c6cbc45399 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 5 Jul 2018 17:50:34 +0200 Subject: Fix macOS build when building inside Homebrew environment A brew build environment sets up a clang shim (fake clang ruby script that sets up additional compiler flags), which passes all brew formula dependency include paths as system include paths (via -isystem). This also includes the Qt dependency. Because our clang parser currently ignores system headers (see Builder::visitLocation in clangbuilder.cpp) and because Qt include statements inside header files would resolve to the system header location, this would result in no Qt classes being recognized by the API extractor, and thus fail the build. Fix this by checking for an environment variable that brew sets inside its build environment, to filter out the unnecessary -isystem flags. This way the Qt include path would be passed as a non-system include path from CMake, and thus correctly complete the build. Task-number: PYSIDE-731 Change-Id: I9b543eddc85270f1e8a90d9f30194b2a862e80d7 Reviewed-by: Christian Tismer Reviewed-by: Alberto Sottile --- .../ApiExtractor/clangparser/compilersupport.cpp | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp index 820909713..0d98999b1 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp @@ -95,6 +95,36 @@ static bool runProcess(const QString &program, const QStringList &arguments, static QByteArray frameworkPath() { return QByteArrayLiteral(" (framework directory)"); } +#if defined(Q_OS_MACOS) +static void filterHomebrewHeaderPaths(HeaderPaths &headerPaths) +{ + QByteArray homebrewPrefix = qgetenv("HOMEBREW_OPT"); + + // If HOMEBREW_OPT is found we assume that the build is happening + // inside a brew environment, which means we need to filter out + // the -isystem flags added by the brew clang shim. This is needed + // because brew passes the Qt include paths as system include paths + // and because our parser ignores system headers, Qt classes won't + // be found and thus compilation errors will occur. + if (homebrewPrefix.isEmpty()) + return; + + qCInfo(lcShiboken) << "Found HOMEBREW_OPT with value:" << homebrewPrefix + << "Assuming homebrew build environment."; + + HeaderPaths::iterator it = headerPaths.begin(); + while (it != headerPaths.end()) { + if (it->path.startsWith(homebrewPrefix)) { + qCInfo(lcShiboken) << "Filtering out homebrew include path: " + << it->path; + it = headerPaths.erase(it); + } else { + ++it; + } + } +} +#endif + // Determine g++'s internal include paths from the output of // g++ -E -x c++ - -v Date: Sun, 8 Jul 2018 18:40:33 +0200 Subject: Fix Limited API and Signature Glitches in Python 3.7 When the homebrew version of Python 3.7 appeared so unforeseen early, I felt inclined to fix these glitches, immediately: In Python 3.7, the typing module was more changed than expected. Since we don't support versions below 3.5, it was easy to fix by avoiding to copy typing.py for version 3.x, altogether. It stays there for Python 2.7 . Furthermore, the Python issue 33738 will later be solved than the code expected, so I fixed that one for all by a macro definition. Task-number: PYSIDE-741 Change-Id: Ia56ccd1ef20cb9536b1d39f190e011e5dccf1f22 Reviewed-by: Friedemann Kleint --- sources/shiboken2/libshiboken/pep384impl.cpp | 2 +- sources/shiboken2/libshiboken/pep384impl.h | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/libshiboken/pep384impl.cpp b/sources/shiboken2/libshiboken/pep384impl.cpp index dcd844ed6..f0e8f3457 100644 --- a/sources/shiboken2/libshiboken/pep384impl.cpp +++ b/sources/shiboken2/libshiboken/pep384impl.cpp @@ -449,7 +449,7 @@ check_PepTypeObject_valid(void) #ifdef Py_LIMITED_API -#if PY_VERSION_HEX < 0x03070000 +#if PY_VERSION_HEX < PY_ISSUE33738_SOLVED #include "pep384_issue33738.cpp" #endif diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h index bfc603f69..d5b0c7654 100644 --- a/sources/shiboken2/libshiboken/pep384impl.h +++ b/sources/shiboken2/libshiboken/pep384impl.h @@ -134,10 +134,9 @@ typedef struct _peptypeobject { } PepTypeObject; // This was a macro error in the limited API from the beginning. -// It was fixed in Python 3.7 . -// XXX The commit did go to master, but did not make it to 3.7, yet. -//#if PY_VERSION_HEX < 0x03070000 -#if PY_VERSION_HEX < 0x03080000 +// It was fixed in Python master, but did make it only in Python 3.8 . +#define PY_ISSUE33738_SOLVED 0x03080000 +#if PY_VERSION_HEX < PY_ISSUE33738_SOLVED #undef PyIndex_Check LIBSHIBOKEN_API int PyIndex_Check(PyObject *obj); #endif -- cgit v1.2.3 From 49bc243b3d681ce302e2f37d44cf2e1bf10b0418 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Sun, 8 Jul 2018 19:13:27 +0200 Subject: Adapt Licenses to Python 3.7.0 Certain Python files were no longer used when moved to Python 3.7.0 . To finish that, these files are now also removed from the source. As a consequence, qt-attribution files needed to be changed. I took the chance to also update the license files to the new version. Change-Id: If058d1013f1d8cb937ee0305a5eb21ae2ebdd4e0 Reviewed-by: Friedemann Kleint --- sources/shiboken2/libshiboken/bufferprocs27.h | 25 ++++++++++++----------- sources/shiboken2/libshiboken/qt_attribution.json | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/libshiboken/bufferprocs27.h b/sources/shiboken2/libshiboken/bufferprocs27.h index 83c4a4750..6fc7a3ece 100644 --- a/sources/shiboken2/libshiboken/bufferprocs27.h +++ b/sources/shiboken2/libshiboken/bufferprocs27.h @@ -38,35 +38,36 @@ ****************************************************************************/ /* -PSF LICENSE AGREEMENT FOR PYTHON 3.6.5¶ +PSF LICENSE AGREEMENT FOR PYTHON 3.7.0 + 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and the Individual or Organization ("Licensee") accessing and otherwise using Python - 3.6.2 software in source or binary form and its associated documentation. + 3.7.0 software in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, - distribute, and otherwise use Python 3.6.2 alone or in any derivative + distribute, and otherwise use Python 3.7.0 alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of - copyright, i.e., "Copyright © 2001-2017 Python Software Foundation; All Rights - Reserved" are retained in Python 3.6.2 alone or in any derivative version + copyright, i.e., "Copyright © 2001-2018 Python Software Foundation; All Rights + Reserved" are retained in Python 3.7.0 alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or - incorporates Python 3.6.2 or any part thereof, and wants to make the + incorporates Python 3.7.0 or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python - 3.6.2. + 3.7.0. -4. PSF is making Python 3.6.2 available to Licensee on an "AS IS" basis. +4. PSF is making Python 3.7.0 available to Licensee on an "AS IS" basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE - USE OF PYTHON 3.6.2 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. + USE OF PYTHON 3.7.0 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. -5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.6.2 +5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.7.0 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF - MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.6.2, OR ANY DERIVATIVE + MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.7.0, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of @@ -78,7 +79,7 @@ PSF LICENSE AGREEMENT FOR PYTHON 3.6.5¶ trademark sense to endorse or promote products or services of Licensee, or any third party. -8. By copying, installing or otherwise using Python 3.6.2, Licensee agrees +8. By copying, installing or otherwise using Python 3.7.0, Licensee agrees to be bound by the terms and conditions of this License Agreement. */ diff --git a/sources/shiboken2/libshiboken/qt_attribution.json b/sources/shiboken2/libshiboken/qt_attribution.json index a90cc604b..14695a4d2 100644 --- a/sources/shiboken2/libshiboken/qt_attribution.json +++ b/sources/shiboken2/libshiboken/qt_attribution.json @@ -5,8 +5,8 @@ "QtUsage": "Used for Qt for Python in the signature extension.", "Description": "Qt for Python is an add-on for Python. The libshiboken packages of PySide uses certain parts of the source files (typespec.cpp, typespec.h, bufferprocs27.cpp, bufferprocs27.h). See the folder sources/shiboken2/libshiboken .", "Homepage": "http://www.python.org/", - "Version": "3.6.5", - "License": "PSF LICENSE AGREEMENT FOR PYTHON 3.6.5", + "Version": "3.7.0", + "License": "PSF LICENSE AGREEMENT FOR PYTHON 3.7.0", "LicenseFile": "bufferprocs27.h", "Copyright": "© Copyright 2001-2018, Python Software Foundation." } -- cgit v1.2.3 From 2313b5247def794216acb1afde93f2c33c2b7aa0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 9 Jul 2018 11:38:01 +0200 Subject: shiboken: Provide g++ internal headers for CentOS, too Extend the check introduced by 4725008aeea407ae55cfd66de802dd9e06412efc to CentOS. Task-number: PYSIDE-733 Change-Id: Iaaf2b8af0fa03684d4a3cbd5c5e70e141d125139 Reviewed-by: Alexandru Croitor --- .../ApiExtractor/clangparser/compilersupport.cpp | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp index 0d98999b1..74cad05ae 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/compilersupport.cpp @@ -182,12 +182,36 @@ static void detectVulkan(HeaderPaths *headerPaths) } #if defined(Q_CC_GNU) -static inline bool isRedHat74() +enum class LinuxDistribution { RedHat, CentOs, Other }; + +static LinuxDistribution linuxDistribution() +{ + const QString &productType = QSysInfo::productType(); + if (productType == QLatin1String("rhel")) + return LinuxDistribution::RedHat; + if (productType == QLatin1String("centos")) + return LinuxDistribution::CentOs; + return LinuxDistribution::Other; +} + +static bool checkProductVersion(const QVersionNumber &minimum, + const QVersionNumber &excludedMaximum) { - if (QSysInfo::productType() != QLatin1String("rhel")) - return false; const QVersionNumber osVersion = QVersionNumber::fromString(QSysInfo::productVersion()); - return osVersion.isNull() || osVersion >= QVersionNumber(7, 4); + return osVersion.isNull() || (osVersion >= minimum && osVersion < excludedMaximum); +} + +static inline bool needsGppInternalHeaders() +{ + const LinuxDistribution distro = linuxDistribution(); + switch (distro) { + case LinuxDistribution::RedHat: + case LinuxDistribution::CentOs: + return checkProductVersion(QVersionNumber(7), QVersionNumber(8)); + case LinuxDistribution::Other: + break; + } + return false; } #endif // Q_CC_GNU @@ -294,9 +318,10 @@ QByteArrayList emulatedCompilerOptions() #endif // NEED_CLANG_BUILTIN_INCLUDES // Append the c++ include paths since Clang is unable to find etc - // on RHEL 7.4 with g++ 6.3. A fix for this has been added to Clang 5.0, - // so, the code can be removed once Clang 5.0 is the minimum version. - if (isRedHat74()) { + // on RHEL 7 with g++ 6.3 or CentOS 7.2. + // A fix for this has been added to Clang 5.0, so, the code can be removed + // once Clang 5.0 is the minimum version. + if (needsGppInternalHeaders()) { const HeaderPaths gppPaths = gppInternalIncludePaths(QStringLiteral("g++")); for (const HeaderPath &h : gppPaths) { if (h.path.contains("c++")) -- cgit v1.2.3 From 5829cbbf60529448e63e5b7103a007d08d9387d8 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Tue, 10 Jul 2018 12:27:15 +0200 Subject: Fix limited API incompatibility with Python 3.7 When Python 3.7 appeared, the structure of pystate.h was changed, substantially. Unfortunately this structure contains the trashcan code, which is only available as a macro and not part of the limited API. This code is normally not used by application programs. It prevents crashes when chains of millions of objects are deallocated. I disabled this for now when the limited API is active. As soon as somebody complains about crashes, I will try to implement it again in a safe way, but I am not sure if it is worth it in the first place. Task-number: PYSIDE-737 Change-Id: Id0daf391448ddcb9df3d299f859ef024714fa736 Reviewed-by: Friedemann Kleint --- sources/shiboken2/libshiboken/basewrapper.cpp | 4 ++ sources/shiboken2/libshiboken/pep384impl.h | 77 --------------------------- sources/shiboken2/libshiboken/sbkenum.cpp | 4 ++ 3 files changed, 8 insertions(+), 77 deletions(-) (limited to 'sources/shiboken2') diff --git a/sources/shiboken2/libshiboken/basewrapper.cpp b/sources/shiboken2/libshiboken/basewrapper.cpp index ae6b2a68a..122e60e41 100644 --- a/sources/shiboken2/libshiboken/basewrapper.cpp +++ b/sources/shiboken2/libshiboken/basewrapper.cpp @@ -259,7 +259,9 @@ void SbkObjectTypeDealloc(PyObject* pyObj) PyTypeObject *type = reinterpret_cast(pyObj); PyObject_GC_UnTrack(pyObj); +#ifndef Py_LIMITED_API Py_TRASHCAN_SAFE_BEGIN(pyObj); +#endif if (sotp) { if (sotp->user_data && sotp->d_func) { sotp->d_func(sotp->user_data); @@ -272,7 +274,9 @@ void SbkObjectTypeDealloc(PyObject* pyObj) delete sotp; sotp = nullptr; } +#ifndef Py_LIMITED_API Py_TRASHCAN_SAFE_END(pyObj); +#endif } PyObject* SbkObjectTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds) diff --git a/sources/shiboken2/libshiboken/pep384impl.h b/sources/shiboken2/libshiboken/pep384impl.h index d5b0c7654..8f14c853a 100644 --- a/sources/shiboken2/libshiboken/pep384impl.h +++ b/sources/shiboken2/libshiboken/pep384impl.h @@ -286,83 +286,6 @@ typedef struct _pycfunc PyCFunctionObject; typedef struct _methoddescr PyMethodDescrObject; #endif -/***************************************************************************** - * - * RESOLVED: pystate.h - * - */ - -/* - * pystate provides the data structure that is needed for the trashcan - * algorithm. Unfortunately, it is not included in the limited API. - * We have two options: - * - * (1) ignore trashcan and live without secured deeply nested structures, - * (2) maintain the structure ourselves and make sure it does not change. - * - * I have chosen the second option. - * - * When a new python version appears, you need to check compatibility of - * the PyThreadState structure (pystate.h) and the trashcan macros at the - * end of object.h . - */ - -#ifdef Py_LIMITED_API - -#define Py_TRASH_MIN_COMPATIBLE 0x03020400 -#define Py_TRASH_MAX_COMPATIBLE 0x0307FFFF - -#if PY_VERSION_HEX >= Py_TRASH_MIN_COMPATIBLE && \ - PY_VERSION_HEX <= Py_TRASH_MAX_COMPATIBLE -typedef int (*Py_tracefunc)(PyObject *, struct _frame *, int, PyObject *); - -// This structure has the trashcan variables since Python 3.2.4. -// We renamed all but the trashcan fields to make sure that we don't use -// anything else somewhere. - -typedef struct _ts { - struct _ts *Pep_prev; - struct _ts *Pep_next; - PyInterpreterState *Pep_interp; - - struct _frame *Pep_frame; - int Pep_recursion_depth; - char Pep_overflowed; - char Pep_recursion_critical; - - int Pep_tracing; - int Pep_use_tracing; - - Py_tracefunc Pep_c_profilefunc; - Py_tracefunc Pep_c_tracefunc; - PyObject *Pep_c_profileobj; - PyObject *Pep_c_traceobj; - - PyObject *Pep_curexc_type; - PyObject *Pep_curexc_value; - PyObject *Pep_curexc_traceback; - - PyObject *Pep_exc_type; - PyObject *Pep_exc_value; - PyObject *Pep_exc_traceback; - - PyObject *Pep_dict; - - int Pep_gilstate_counter; - - PyObject *Pep_async_exc; - long Pep_thread_id; - // These two variables only are of interest to us. - int trash_delete_nesting; - PyObject *trash_delete_later; - // Here we cut away the rest of the reduced structure. -} PyThreadState; -#else -#error *** Please check compatibility of the trashcan code, see Pep.h *** -#endif - -#endif // Py_LIMITED_API - /***************************************************************************** * * RESOLVED: pythonrun.h diff --git a/sources/shiboken2/libshiboken/sbkenum.cpp b/sources/shiboken2/libshiboken/sbkenum.cpp index 5f753293c..119591215 100644 --- a/sources/shiboken2/libshiboken/sbkenum.cpp +++ b/sources/shiboken2/libshiboken/sbkenum.cpp @@ -312,11 +312,15 @@ void SbkEnumTypeDealloc(PyObject* pyObj) SbkEnumType* sbkType = reinterpret_cast(pyObj); PyObject_GC_UnTrack(pyObj); +#ifndef Py_LIMITED_API Py_TRASHCAN_SAFE_BEGIN(pyObj); +#endif if (PepType_SETP(sbkType)->converter) { Shiboken::Conversions::deleteConverter(PepType_SETP(sbkType)->converter); } +#ifndef Py_LIMITED_API Py_TRASHCAN_SAFE_END(pyObj); +#endif } PyObject* SbkEnumTypeTpNew(PyTypeObject* metatype, PyObject* args, PyObject* kwds) -- cgit v1.2.3