Skip to content

Commit f1b466b

Browse files
jcfrmrbean-bremen
authored andcommitted
fix(PythonQtPythonInclude): conditionally #undef ctype macros only on macOS C++ builds
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 `<locale>` 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).
1 parent e3b4859 commit f1b466b

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/PythonQtPythonInclude.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,27 +142,19 @@
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-
*/
145+
// Avoid clashes with libstdc++ <locale> by undefining ctype macros
146+
// that CPython may introduce on macOS when the UTF-8 ctype quirk is enabled.
147+
// (_PY_PORT_CTYPE_UTF8_ISSUE is defined by CPython’s pyport.h; we apply these
148+
// undefs only in C++ builds.)
149+
#if defined(_PY_PORT_CTYPE_UTF8_ISSUE) && defined(__cplusplus)
159150
#undef isalnum
160151
#undef isalpha
161152
#undef islower
162153
#undef isspace
163154
#undef isupper
164155
#undef tolower
165156
#undef toupper
157+
#endif
166158

167159
#endif
168160

0 commit comments

Comments
 (0)