]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-130740: Move some `stdbool.h` includes after `Python.h` (#130738) (#130757)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Tue, 4 Mar 2025 09:38:24 +0000 (10:38 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Mar 2025 09:38:24 +0000 (10:38 +0100)
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 <hugo@beauzee.fr>
Misc/NEWS.d/next/Build/2025-03-01-18-27-42.gh-issue-130740.nDFSHR.rst [new file with mode: 0644]
Objects/codeobject.c
Parser/string_parser.c
Python/assemble.c
Python/compile.c
Python/flowgraph.c
Python/opcode_metadata.h
Python/pythonrun.c
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 (file)
index 0000000..61d416c
--- /dev/null
@@ -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.
index 7332d4fb848fa50b29a4eff57bb49522b99b4a66..6f7b8b54dcfa3c911bd30bc4c10b28e5362acc8a 100644 (file)
@@ -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 *
index 751b56d0ee0e2ccbf860848c0ea99c38c76efd38..8607885f2e46bdfa4825863e898907193fde8ade 100644 (file)
@@ -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
index 8789d8ef978c22be58de375acdc2812c68265327..4aa922848f23aa53e975a9fb2f4e9db8ca7871f6 100644 (file)
@@ -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
index 56fdbfae6f613e9ea21c00ca30aac43791ac5e21..cc639ff64fff29c8d1950e7a18cbe43fc939e76c 100644 (file)
@@ -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
index fbbe053ae58e9732ad3ed2682ac3cdaec2ea3a61..86b3afe5ae86d2c31f54ff363efc8a978b4f5258 100644 (file)
@@ -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
index f9b1c928cd4845b6bdafeac850102249feea8338..ab351b1b3581a159a7e998ede1a9f8514527928b 100644 (file)
@@ -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
index ac71e73311f2971a1ed72d9f37f758de0fe78f51..89287bace08b09178c96bf9821b4b10966aa8c65 100644 (file)
@@ -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
index 62ddeac0265ad8696d30d5acadd53d8f8eb54194..40e2fbf3d84f6fdd03b9437e7124dda74b69008e 100644 (file)
@@ -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 <stdbool.h>")
+            self.out.write_raw("\n")
 
             self.write_stack_effect_functions()