From 6486103f57f392824bc4554a4233edcbdfb51099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Sun, 2 Mar 2025 10:56:49 +0100 Subject: [PATCH 1/3] 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`. --- .../Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst | 2 ++ Parser/string_parser.c | 4 ++-- Python/flowgraph.c | 5 ++--- 3 files changed, 6 insertions(+), 5 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 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/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 - #include #include "tokenizer.h" #include "pegen.h" #include "string_parser.h" +#include + //// STRING HANDLING FUNCTIONS //// static int 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 - #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 From 6a3dfb73803f57bd374acf9679970f3d1a0fe370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 2 Mar 2025 11:07:02 +0100 Subject: [PATCH 2/3] backport --- Objects/codeobject.c | 4 ++-- Python/assemble.c | 3 +-- Python/compile.c | 4 ++-- Python/pythonrun.c | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) 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 - #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/Python/assemble.c b/Python/assemble.c index 8789d8ef978c22..4aa922848f23aa 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 56fdbfae6f613e..cc639ff64fff29 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/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 - #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 From efd75da3fa72b827b08fa2cc56a6fc535cde0e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Sun, 2 Mar 2025 11:18:37 +0100 Subject: [PATCH 3/3] include stdbool.h in opcode_metadata.h --- Python/opcode_metadata.h | 2 ++ Tools/cases_generator/generate_cases.py | 3 +++ 2 files changed, 5 insertions(+) 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 + #ifndef NEED_OPCODE_METADATA extern int _PyOpcode_num_popped(int opcode, int oparg, bool jump); #else 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 ") + self.out.write_raw("\n") self.write_stack_effect_functions()