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>
--- /dev/null
+Ensure that ``Python.h`` is included before ``stdbool.h`` unless ``pyconfig.h``
+is included before or in some platform-specific contexts.
# define Py_BUILD_CORE_MODULE 1
#endif
-#include <stdbool.h>
#include "Python.h"
#include "pycore_strhex.h" // _Py_strhex()
+#include <stdbool.h>
+
#include "../hashlib.h"
#include "blake2module.h"
# define Py_BUILD_CORE_MODULE 1
#endif
-#include <stdbool.h>
#include "Python.h"
#include "pycore_strhex.h" // _Py_strhex()
+#include <stdbool.h>
+
#include "../hashlib.h"
#include "blake2module.h"
# define Py_BUILD_CORE_MODULE 1
#endif
-#include <stdbool.h>
#include "Python.h"
#include "pycore_hashtable.h"
#include "pycore_pyhash.h" // _Py_HashBytes()
#include <openssl/objects.h>
#include <openssl/err.h>
+#include <stdbool.h>
#ifndef OPENSSL_THREADS
# error "OPENSSL_THREADS is not defined, Python requires thread-safe OpenSSL"
-#include <stdbool.h>
-
#include <Python.h>
#include "pycore_bytesobject.h" // _PyBytes_DecodeEscape()
#include "pycore_unicodeobject.h" // _PyUnicode_DecodeUnicodeEscapeInternal()
#include "pegen.h"
#include "string_parser.h"
+#include <stdbool.h>
+
//// STRING HANDLING FUNCTIONS ////
static int
-
-#include <stdbool.h>
-
#include "Python.h"
#include "pycore_flowgraph.h"
#include "pycore_compile.h"
#include "pycore_opcode_utils.h"
#include "pycore_opcode_metadata.h" // OPCODE_HAS_ARG, etc
+#include <stdbool.h>
+
#undef SUCCESS
#undef ERROR
*/
-#include <stdbool.h>
-
#include "Python.h"
#include "pycore_compile.h" // _PyCompile_EnsureArrayLargeEnough
#include "clinic/instruction_sequence.c.h"
+#include <stdbool.h>
+
#undef SUCCESS
#undef ERROR
#define SUCCESS 0