Skip to content

Commit 8056e58

Browse files
pieperjcfr
authored andcommitted
fix(PythonQtPythonInclude): Undefine C <ctype> macros after Python.h to avoid libstdc++ <locale> clashes
On older Apple toolchains (e.g., macOS 10.7.4/Xcode 4.3.3 with libstdc++ 4.2.1), including <Python.h> pulls in <ctype.h>, which defines macros like isspace/isalnum. When C++ headers such as <locale> (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 <ctype.h> 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@4ce028d)
1 parent d62d412 commit 8056e58

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/PythonQtPythonInclude.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,27 @@
142142
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
143143
#endif
144144

145+
/*
146+
* The following undefs for C standard library macros prevent
147+
* build errors of the following type on macOS 10.7.4 and XCode 4.3.3
148+
*
149+
/usr/include/c++/4.2.1/bits/localefwd.h:57:21: error: too many arguments provided to function-like macro invocation
150+
isspace(_CharT, const locale&);
151+
^
152+
/usr/include/c++/4.2.1/bits/localefwd.h:56:5: error: 'inline' can only appear on functions
153+
inline bool
154+
^
155+
/usr/include/c++/4.2.1/bits/localefwd.h:57:5: error: variable 'isspace' declared as a template
156+
isspace(_CharT, const locale&);
157+
^
158+
*/
159+
#undef isalnum
160+
#undef isalpha
161+
#undef islower
162+
#undef isspace
163+
#undef isupper
164+
#undef tolower
165+
#undef toupper
166+
145167
#endif
168+

0 commit comments

Comments
 (0)