mirror of
https://github.com/python/cpython.git
synced 2024-11-23 09:54:58 +08:00
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
This commit is contained in:
parent
98c3bea4d1
commit
2c228a7b8f
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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``.
|
@ -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;
|
||||
|
@ -38,6 +38,8 @@
|
||||
#include "Python.h"
|
||||
#include "pycore_import.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Includes for frozen modules: */
|
||||
/* End includes */
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user