https://github.com/python/cpython/commit/7ce5f1598186ef652246aefbea498f2dd4f3dcfd commit: 7ce5f1598186ef652246aefbea498f2dd4f3dcfd branch: 3.12 author: Bénédikt Tran <10796600+picn...@users.noreply.github.com> committer: picnixz <10796600+picn...@users.noreply.github.com> date: 2025-03-04T10:38:24+01:00 summary:
[3.12] gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738) (#130757) gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738) Move some `#include <stdbool.h>` after `#include "Python.h"` when `pyconfig.h` is not included first and when we are in a platform-agnostic context. This is to avoid having features defined by `stdbool.h` before those decided by `Python.h` (this caused some build failures when compiling CPython with `zig cc`). (cherry-picked from commit 214562ed4ddc248b007f718ed92ebcc0c3669611) --------- Co-authored-by: Hugo Beauzée-Luyssen <h...@beauzee.fr> files: A Misc/NEWS.d/next/Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst M Objects/codeobject.c M Parser/string_parser.c M Python/assemble.c M Python/compile.c M Python/flowgraph.c M Python/opcode_metadata.h M Python/pythonrun.c M Tools/cases_generator/generate_cases.py diff --git a/Misc/NEWS.d/next/Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst b/Misc/NEWS.d/next/Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst new file mode 100644 index 00000000000000..61d416c69f0c30 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst @@ -0,0 +1,2 @@ +Ensure that ``Python.h`` is included before ``stdbool.h`` unless ``pyconfig.h`` +is included before or in some platform-specific contexts. diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 7332d4fb848fa5..6f7b8b54dcfa3c 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1,5 +1,3 @@ -#include <stdbool.h> - #include "Python.h" #include "opcode.h" #include "structmember.h" // PyMemberDef @@ -11,6 +9,8 @@ #include "pycore_tuple.h" // _PyTuple_ITEMS() #include "clinic/codeobject.c.h" +#include <stdbool.h> + static PyObject* code_repr(PyCodeObject *co); static const char * diff --git a/Parser/string_parser.c b/Parser/string_parser.c index 751b56d0ee0e2c..8607885f2e46bd 100644 --- a/Parser/string_parser.c +++ b/Parser/string_parser.c @@ -1,11 +1,11 @@ -#include <stdbool.h> - #include <Python.h> #include "tokenizer.h" #include "pegen.h" #include "string_parser.h" +#include <stdbool.h> + //// STRING HANDLING FUNCTIONS //// static int diff --git a/Python/assemble.c b/Python/assemble.c index 8789d8ef978c22..4aa922848f23aa 100644 --- a/Python/assemble.c +++ b/Python/assemble.c @@ -1,11 +1,10 @@ -#include <stdbool.h> - #include "Python.h" #include "pycore_code.h" // write_location_entry_start() #include "pycore_compile.h" #include "pycore_opcode.h" // _PyOpcode_Caches[] and opcode category macros #include "pycore_pymem.h" // _PyMem_IsPtrFreed() +#include <stdbool.h> #define DEFAULT_CODE_SIZE 128 #define DEFAULT_LNOTAB_SIZE 16 diff --git a/Python/compile.c b/Python/compile.c index 56fdbfae6f613e..cc639ff64fff29 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -21,8 +21,6 @@ * objects. */ -#include <stdbool.h> - #include "Python.h" #include "pycore_ast.h" // _PyAST_GetDocString() #define NEED_OPCODE_TABLES @@ -38,6 +36,8 @@ #include "opcode_metadata.h" // _PyOpcode_opcode_metadata, _PyOpcode_num_popped/pushed +#include <stdbool.h> + #define DEFAULT_CODE_SIZE 128 #define DEFAULT_LNOTAB_SIZE 16 #define DEFAULT_CNOTAB_SIZE 32 diff --git a/Python/flowgraph.c b/Python/flowgraph.c index fbbe053ae58e97..86b3afe5ae86d2 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -1,6 +1,3 @@ - -#include <stdbool.h> - #include "Python.h" #include "pycore_flowgraph.h" #include "pycore_compile.h" @@ -11,6 +8,8 @@ #include "opcode_metadata.h" // _PyOpcode_opcode_metadata, _PyOpcode_num_popped/pushed #undef NEED_OPCODE_METADATA +#include <stdbool.h> + #undef SUCCESS #undef ERROR diff --git a/Python/opcode_metadata.h b/Python/opcode_metadata.h index f9b1c928cd4845..ab351b1b3581a1 100644 --- a/Python/opcode_metadata.h +++ b/Python/opcode_metadata.h @@ -3,6 +3,8 @@ // Python/bytecodes.c // Do not edit! +#include <stdbool.h> + #ifndef NEED_OPCODE_METADATA extern int _PyOpcode_num_popped(int opcode, int oparg, bool jump); #else diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ac71e73311f297..89287bace08b09 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -8,8 +8,6 @@ /* TODO: Cull includes following phase split */ -#include <stdbool.h> - #include "Python.h" #include "pycore_ast.h" // PyAST_mod2obj @@ -27,6 +25,8 @@ #include "errcode.h" // E_EOF #include "marshal.h" // PyMarshal_ReadLongFromFile() +#include <stdbool.h> + #ifdef MS_WINDOWS # include "malloc.h" // alloca() #endif diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py index 62ddeac0265ad8..40e2fbf3d84f6f 100644 --- a/Tools/cases_generator/generate_cases.py +++ b/Tools/cases_generator/generate_cases.py @@ -986,6 +986,9 @@ def write_metadata(self) -> None: self.out.write_raw(self.from_source_files()) self.out.write_raw(f"// Do not edit!\n") + self.out.write_raw("\n") + self.out.write_raw("#include <stdbool.h>") + self.out.write_raw("\n") self.write_stack_effect_functions() _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com