aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2018-01-12 15:31:40 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2018-01-15 15:19:03 +0000
commit4e024076fe9562b939d7936b6bf22c25507b2120 (patch)
treee270382cfd51066514f8aaedb7a51e394e184a89 /sources
parent38ca3c64de743e294a95f43a71a79e81ada41851 (diff)
Fix system header inclusions for proper support of C primitive types
In order for GL types like GLint64 to be available on macOS, the macOS-specific system header "gltypes.h" has to be parsed by libclang. Before this change, shiboken skipped parsing system headers (except for gl.h) because there are issues when trying to parse C++ std headers (ostream for example). The file "gltypes.h" contains the typedef declarations for GL numeric types. A few other system headers like "cstdint" are also needed (which contain the actual typedefs from int32_t to int for example). A few different system headers are also needed on Linux (also for GL -> numeric typedefs). This system header exclusion mechanism is far from a clean solution, but it seems like current versions of libclang do not provide enough preprocessor information to be able to limit the parsing to specific chunks of code (for example everything included by gltypes.h), thus we need to limit ourselves to exclusion by file paths. Change-Id: I58c151e2cb083e16f7cafb3dc9df2d757442bb59 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/PySide2/QtCore/typesystem_core_common.xml11
-rw-r--r--sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp23
2 files changed, 22 insertions, 12 deletions
diff --git a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
index ca7531f0a..0ff1c681a 100644
--- a/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
+++ b/sources/pyside2/PySide2/QtCore/typesystem_core_common.xml
@@ -216,17 +216,6 @@
<include file-name="signalmanager.h" location="global"/>
</primitive-type>
- <!-- Among other use cases, these types are necessary for OpenGL "GLint"-like typedefs on macOS.
- -->
- <primitive-type name="int64_t" />
- <primitive-type name="int32_t" />
- <primitive-type name="int16_t" />
- <primitive-type name="int8_t" />
- <primitive-type name="uint64_t" />
- <primitive-type name="uint32_t" />
- <primitive-type name="uint16_t" />
- <primitive-type name="uint8_t" />
-
<primitive-type name="bool" target-lang-api-name="PyBool">
<conversion-rule>
<native-to-target>
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
index 171adc2d6..1ed054d91 100644
--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
@@ -533,6 +533,13 @@ static inline bool compareHeaderName(const char *haystack, const char *needle)
#endif
}
+#ifdef Q_OS_UNIX
+static bool cStringStartsWith(const char *prefix, const char *str)
+{
+ return strncmp(prefix, str, strlen(prefix)) == 0;
+}
+#endif
+
bool Builder::visitLocation(const CXSourceLocation &location) const
{
if (clang_Location_isInSystemHeader(location) == 0)
@@ -546,7 +553,21 @@ bool Builder::visitLocation(const CXSourceLocation &location) const
// Has been observed to be 0 for invalid locations
if (const char *cFileName = clang_getCString(cxFileName)) {
// Resolve OpenGL typedefs although the header is considered a system header.
- const bool visitHeader = compareHeaderName(cFileName, "gl.h");
+ const bool visitHeader = compareHeaderName(cFileName, "gl.h")
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
+ || cStringStartsWith("/usr/include/stdint.h", cFileName)
+#endif
+#if defined(Q_OS_LINUX)
+ || cStringStartsWith("/usr/include/stdlib.h", cFileName)
+ || cStringStartsWith("/usr/include/sys/types.h", cFileName)
+#elif defined(Q_OS_MACOS)
+ // Parse the following system headers to get the correct typdefs for types like
+ // int32_t, which are used in the macOS implementation of OpenGL framework.
+ || compareHeaderName(cFileName, "gltypes.h")
+ || cStringStartsWith("/usr/include/_types", cFileName)
+ || cStringStartsWith("/usr/include/sys/_types", cFileName)
+#endif
+ ;
clang_disposeString(cxFileName);
if (visitHeader)
return true;