Skip to content

[3.12] gh-130740: Move some stdbool.h includes after Python.h (#130738) #130757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <stdbool.h>

#include "Python.h"
#include "opcode.h"
#include "structmember.h" // PyMemberDef
Expand All @@ -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 *
Expand Down
4 changes: 2 additions & 2 deletions Parser/string_parser.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions Python/assemble.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
* objects.
*/

#include <stdbool.h>

#include "Python.h"
#include "pycore_ast.h" // _PyAST_GetDocString()
#define NEED_OPCODE_TABLES
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

#include <stdbool.h>

#include "Python.h"
#include "pycore_flowgraph.h"
#include "pycore_compile.h"
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

/* TODO: Cull includes following phase split */

#include <stdbool.h>

#include "Python.h"

#include "pycore_ast.h" // PyAST_mod2obj
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,9 @@ def write_metadata(self) -> None:
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>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you add <stdbool.h> include?

Copy link
Member Author

@picnixz picnixz Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are some bool inside the generate_metadata.h file which, without this include, doesn't compile. Previously, it was because we included stdbool.h before including this file so it was impliticitly available (see https://github.com/python/cpython/actions/runs/13614386994/job/38055588576?pr=130757)

self.out.write_raw("\n")

self.write_stack_effect_functions()

Expand Down
Loading