]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46748: Don't import <stdbool.h> in public headers (GH-31553)
authorPetr Viktorin <encukou@gmail.com>
Fri, 25 Feb 2022 08:25:54 +0000 (09:25 +0100)
committerGitHub <noreply@github.com>
Fri, 25 Feb 2022 08:25:54 +0000 (09:25 +0100)
<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

Include/cpython/import.h
Include/cpython/pystate.h
Misc/NEWS.d/next/C API/2022-02-24-13-13-16.bpo-46748.aG1zb3.rst [new file with mode: 0644]
Modules/_testcapimodule.c
Python/frozen.c
Tools/freeze/makefreeze.py

index c734802ff254b1fb6174656bb2718c0409c66832..ef6be689468ee5bee94db73bf4524e23b5bb2dbe 100644 (file)
@@ -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);
 };
 
index 8150d501d418e6d3a132954b22a26db74d4a7981..248320cceb7169bb378176b882cff4b851c9b00a 100644 (file)
@@ -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 (file)
index 0000000..b6b2db1
--- /dev/null
@@ -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``.
index 0be42f33e23c9d644f14e98e404099fe8bdbd0c3..6fa0cced4ecfb9a08a203e820acb067009891163 100644 (file)
@@ -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;
index c5b36f73b4a47319d9ca55d7568f0a6be69fba4b..8a2a7243537cc545149d00a61ad6d7739f13a474 100644 (file)
@@ -38,6 +38,8 @@
 #include "Python.h"
 #include "pycore_import.h"
 
+#include <stdbool.h>
+
 /* Includes for frozen modules: */
 /* End includes */
 
index bc5f8567448bfd176d0abe3ded74464bdefb8bcb..c464f4bbb2655d307e675216e1b0fe4668f46552 100644 (file)
@@ -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: