From 7ce5f1598186ef652246aefbea498f2dd4f3dcfd Mon Sep 17 00:00:00 2001 From: =?utf8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Tue, 4 Mar 2025 10:38:24 +0100 Subject: [PATCH] [3.12] gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738) (#130757) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738) Move some `#include ` 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 --- .../Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst | 2 ++ Objects/codeobject.c | 4 ++-- Parser/string_parser.c | 4 ++-- Python/assemble.c | 3 +-- Python/compile.c | 4 ++-- Python/flowgraph.c | 5 ++--- Python/opcode_metadata.h | 2 ++ Python/pythonrun.c | 4 ++-- Tools/cases_generator/generate_cases.py | 3 +++ 9 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst 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 000000000000..61d416c69f0c --- /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 7332d4fb848f..6f7b8b54dcfa 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1,5 +1,3 @@ -#include - #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 + static PyObject* code_repr(PyCodeObject *co); static const char * diff --git a/Parser/string_parser.c b/Parser/string_parser.c index 751b56d0ee0e..8607885f2e46 100644 --- a/Parser/string_parser.c +++ b/Parser/string_parser.c @@ -1,11 +1,11 @@ -#include - #include #include "tokenizer.h" #include "pegen.h" #include "string_parser.h" +#include + //// STRING HANDLING FUNCTIONS //// static int diff --git a/Python/assemble.c b/Python/assemble.c index 8789d8ef978c..4aa922848f23 100644 --- a/Python/assemble.c +++ b/Python/assemble.c @@ -1,11 +1,10 @@ -#include - #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 #define DEFAULT_CODE_SIZE 128 #define DEFAULT_LNOTAB_SIZE 16 diff --git a/Python/compile.c b/Python/compile.c index 56fdbfae6f61..cc639ff64fff 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -21,8 +21,6 @@ * objects. */ -#include - #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 + #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 fbbe053ae58e..86b3afe5ae86 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -1,6 +1,3 @@ - -#include - #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 + #undef SUCCESS #undef ERROR diff --git a/Python/opcode_metadata.h b/Python/opcode_metadata.h index f9b1c928cd48..ab351b1b3581 100644 --- a/Python/opcode_metadata.h +++ b/Python/opcode_metadata.h @@ -3,6 +3,8 @@ // Python/bytecodes.c // Do not edit! +#include + #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 ac71e73311f2..89287bace08b 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -8,8 +8,6 @@ /* TODO: Cull includes following phase split */ -#include - #include "Python.h" #include "pycore_ast.h" // PyAST_mod2obj @@ -27,6 +25,8 @@ #include "errcode.h" // E_EOF #include "marshal.h" // PyMarshal_ReadLongFromFile() +#include + #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 62ddeac0265a..40e2fbf3d84f 100644 --- a/Tools/cases_generator/generate_cases.py +++ b/Tools/cases_generator/generate_cases.py @@ -986,6 +986,9 @@ class Analyzer: 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 ") + self.out.write_raw("\n") self.write_stack_effect_functions() -- 2.47.3