From 8056e585a0ceed832031f5cee6d4a384cb5cbbea Mon Sep 17 00:00:00 2001 From: Steve Pieper Date: Thu, 12 Jul 2012 16:11:06 -0400 Subject: [PATCH 1/2] fix(PythonQtPythonInclude): Undefine C macros after Python.h to avoid libstdc++ clashes On older Apple toolchains (e.g., macOS 10.7.4/Xcode 4.3.3 with libstdc++ 4.2.1), including pulls in , which defines macros like isspace/isalnum. When C++ headers such as (transitively included by moc-generated code) declare the templated overloads (e.g., `bool std::isspace(_CharT, const std::locale&)`), those C macros expand and break compilation with errors. In `PythonQtPythonInclude.h`, explicitly `#undef` the problematic macros (isalnum, isalpha, islower, isspace, isupper, tolower, toupper) after including Python headers. This keeps macro pollution out of downstream C++ includes and lets the std:: functions/ overloads compile cleanly. It fixes error like the following: ``` /usr/include/c++/4.2.1/bits/localefwd.h:57:21: error: too many arguments provided to function-like macro invocation isspace(_CharT, const locale&); ``` ``` moc_PythonQtStdDecorators.cxx:152:25: error: expected unqualified-id case 4: _t->emit((*reinterpret_cast< QObject*(*)>(_a[1])),(*reinterpret_cast< const ` ``` (cherry picked from commit commontk/PythonQt@4ce028d2ddac637ad44d8faf52f4e2fc5966a784) --- src/PythonQtPythonInclude.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h index 673db874f..827272995 100644 --- a/src/PythonQtPythonInclude.h +++ b/src/PythonQtPythonInclude.h @@ -142,4 +142,27 @@ #define PyBytes_FromStringAndSize PyString_FromStringAndSize #endif +/* + * The following undefs for C standard library macros prevent + * build errors of the following type on macOS 10.7.4 and XCode 4.3.3 + * +/usr/include/c++/4.2.1/bits/localefwd.h:57:21: error: too many arguments provided to function-like macro invocation + isspace(_CharT, const locale&); + ^ +/usr/include/c++/4.2.1/bits/localefwd.h:56:5: error: 'inline' can only appear on functions + inline bool + ^ +/usr/include/c++/4.2.1/bits/localefwd.h:57:5: error: variable 'isspace' declared as a template + isspace(_CharT, const locale&); + ^ +*/ +#undef isalnum +#undef isalpha +#undef islower +#undef isspace +#undef isupper +#undef tolower +#undef toupper + #endif + From 03cc7a42e8c68217c51bd7d6634f54c4dd2faa75 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 4 Sep 2025 13:54:05 -0400 Subject: [PATCH 2/2] fix(PythonQtPythonInclude): conditionally #undef ctype macros only on macOS C++ builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CPython’s `pyport.h` defines `_PY_PORT_CTYPE_UTF8_ISSUE` on macOS to work around BSD libc ctype behavior in UTF-8 locales. Those ctype names can surface as macros and collide with libstdc++’s `` templated overloads (e.g., `std::isspace`), leading to compilation errors. Previously we unconditionally `#undef`’d several ctype macros. Restrict this to the affected environment by guarding with `_PY_PORT_CTYPE_UTF8_ISSUE` and `__cplusplus`. This keeps macOS C++ builds healthy while avoiding unnecessary macro tampering elsewhere. Adapted from kitware/VTK@a4fa448099 ("Remove the toupper macro defined by Python.h.", 2015-11-12). --- src/PythonQtPythonInclude.h | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h index 827272995..90569ddd5 100644 --- a/src/PythonQtPythonInclude.h +++ b/src/PythonQtPythonInclude.h @@ -142,20 +142,11 @@ #define PyBytes_FromStringAndSize PyString_FromStringAndSize #endif -/* - * The following undefs for C standard library macros prevent - * build errors of the following type on macOS 10.7.4 and XCode 4.3.3 - * -/usr/include/c++/4.2.1/bits/localefwd.h:57:21: error: too many arguments provided to function-like macro invocation - isspace(_CharT, const locale&); - ^ -/usr/include/c++/4.2.1/bits/localefwd.h:56:5: error: 'inline' can only appear on functions - inline bool - ^ -/usr/include/c++/4.2.1/bits/localefwd.h:57:5: error: variable 'isspace' declared as a template - isspace(_CharT, const locale&); - ^ -*/ +// Avoid clashes with libstdc++ by undefining ctype macros +// that CPython may introduce on macOS when the UTF-8 ctype quirk is enabled. +// (_PY_PORT_CTYPE_UTF8_ISSUE is defined by CPython’s pyport.h; we apply these +// undefs only in C++ builds.) +#if defined(_PY_PORT_CTYPE_UTF8_ISSUE) && defined(__cplusplus) #undef isalnum #undef isalpha #undef islower @@ -163,6 +154,7 @@ #undef isupper #undef tolower #undef toupper +#endif #endif