Skip to content

Commit 3cbf8cb

Browse files
encukouasvetlov
authored andcommitted
bpo-46748: Don't import <stdbool.h> in public headers (GH-31553)
<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
1 parent d28df6d commit 3cbf8cb

File tree

6 files changed

+11
-6
lines changed

6 files changed

+11
-6
lines changed

Include/cpython/import.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct _frozen {
3232
const char *name; /* ASCII encoded string */
3333
const unsigned char *code;
3434
int size;
35-
bool is_package;
35+
int is_package;
3636
PyObject *(*get_code)(void);
3737
};
3838

Include/cpython/pystate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# error "this header file must not be included directly"
33
#endif
44

5-
#include <stdbool.h>
6-
75

86
PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *);
97
PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int);
@@ -93,7 +91,7 @@ struct _ts {
9391
int _initialized;
9492

9593
/* Was this thread state statically allocated? */
96-
bool _static;
94+
int _static;
9795

9896
int recursion_remaining;
9997
int recursion_limit;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Python's public headers no longer import ``<stdbool.h>``, leaving code that
2+
embedd/extends Python free to define ``bool``, ``true`` and ``false``.

Modules/_testcapimodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
# error "_testcapi must test the public Python C API, not CPython internal C API"
4141
#endif
4242

43+
#ifdef bool
44+
# error "The public headers should not include <stdbool.h>, see bpo-46748"
45+
#endif
4346

4447
// Forward declarations
4548
static struct PyModuleDef _testcapimodule;

Python/frozen.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "Python.h"
3939
#include "pycore_import.h"
4040

41+
#include <stdbool.h>
42+
4143
/* Includes for frozen modules: */
4244
/* End includes */
4345

Tools/freeze/makefreeze.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def makefreeze(base, dict, debug=0, entry_point=None, fail_import=()):
4545
print("freezing", mod, "...")
4646
str = marshal.dumps(m.__code__)
4747
size = len(str)
48-
is_package = 'false'
48+
is_package = '0'
4949
if m.__path__:
50-
is_package = 'true'
50+
is_package = '1'
5151
done.append((mod, mangled, size, is_package))
5252
writecode(outfp, mangled, str)
5353
if debug:

0 commit comments

Comments
 (0)