diff options
author | Petr Viktorin <encukou@gmail.com> | 2022-02-25 08:25:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-25 08:25:54 (GMT) |
commit | 2c228a7b8f89e9ed8d390370abd771d4993b79d8 (patch) | |
tree | 6c3316eb466ed4feb1221d4ece109695f01e77aa | |
parent | 98c3bea4d1c7335135e60946d0ec8cd5031fb6c0 (diff) | |
download | cpython-2c228a7b8f89e9ed8d390370abd771d4993b79d8.zip cpython-2c228a7b8f89e9ed8d390370abd771d4993b79d8.tar.gz cpython-2c228a7b8f89e9ed8d390370abd771d4993b79d8.tar.bz2 |
bpo-46748: Don't import <stdbool.h> in public headers (GH-31553)
<stdbool.h> is the standard/modern way to define embedd/extends Python free to define bool, true and false, but there are existing applications that use slightly different redefinitions, which fail if the header is included.
It's OK to use stdbool outside the public headers, though.
https://bugs.python.org/issue46748
-rw-r--r-- | Include/cpython/import.h | 2 | ||||
-rw-r--r-- | Include/cpython/pystate.h | 4 | ||||
-rw-r--r-- | Misc/NEWS.d/next/C API/2022-02-24-13-13-16.bpo-46748.aG1zb3.rst | 2 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 3 | ||||
-rw-r--r-- | Python/frozen.c | 2 | ||||
-rw-r--r-- | Tools/freeze/makefreeze.py | 4 |
6 files changed, 11 insertions, 6 deletions
diff --git a/Include/cpython/import.h b/Include/cpython/import.h index c734802..ef6be68 100644 --- a/Include/cpython/import.h +++ b/Include/cpython/import.h @@ -32,7 +32,7 @@ struct _frozen { const char *name; /* ASCII encoded string */ const unsigned char *code; int size; - bool is_package; + int is_package; PyObject *(*get_code)(void); }; diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 8150d50..248320c 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -2,8 +2,6 @@ # error "this header file must not be included directly" #endif -#include <stdbool.h> - PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *); PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int); @@ -93,7 +91,7 @@ struct _ts { int _initialized; /* Was this thread state statically allocated? */ - bool _static; + int _static; int recursion_remaining; int recursion_limit; diff --git a/Misc/NEWS.d/next/C API/2022-02-24-13-13-16.bpo-46748.aG1zb3.rst b/Misc/NEWS.d/next/C API/2022-02-24-13-13-16.bpo-46748.aG1zb3.rst new file mode 100644 index 0000000..b6b2db1 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-02-24-13-13-16.bpo-46748.aG1zb3.rst @@ -0,0 +1,2 @@ +Python's public headers no longer import ``<stdbool.h>``, leaving code that +embedd/extends Python free to define ``bool``, ``true`` and ``false``. diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 0be42f3..6fa0cce 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -40,6 +40,9 @@ # error "_testcapi must test the public Python C API, not CPython internal C API" #endif +#ifdef bool +# error "The public headers should not include <stdbool.h>, see bpo-46748" +#endif // Forward declarations static struct PyModuleDef _testcapimodule; diff --git a/Python/frozen.c b/Python/frozen.c index c5b36f7..8a2a724 100644 --- a/Python/frozen.c +++ b/Python/frozen.c @@ -38,6 +38,8 @@ #include "Python.h" #include "pycore_import.h" +#include <stdbool.h> + /* Includes for frozen modules: */ /* End includes */ diff --git a/Tools/freeze/makefreeze.py b/Tools/freeze/makefreeze.py index bc5f856..c464f4b 100644 --- a/Tools/freeze/makefreeze.py +++ b/Tools/freeze/makefreeze.py @@ -45,9 +45,9 @@ def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()): print("freezing", mod, "...") str = marshal.dumps(m.__code__) size = len(str) - is_package = 'false' + is_package = '0' if m.__path__: - is_package = 'true' + is_package = '1' done.append((mod, mangled, size, is_package)) writecode(outfp, mangled, str) if debug: |