Skip to content

Commit 6827c51

Browse files
authored
gh-131238: Move pycore_obmalloc.h include to pycore_runtime_structs.h (#131482)
Move pycore_obmalloc.h include from pycore_interp_structs.h to pycore_runtime_structs.h. Add also comment explaining the purpose of each include in pycore_interp_structs.h, pycore_runtime_structs.h and pycore_structs.h. Remove <stdbool.h> and <stddef.h> from pycore_structs.h.
1 parent a741102 commit 6827c51

File tree

4 files changed

+28
-40
lines changed

4 files changed

+28
-40
lines changed

Include/internal/pycore_backoff.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ extern "C" {
1010
#endif
1111

1212
#include <assert.h>
13-
#include "pycore_structs.h" // _Py_BackoffCounter
13+
#include <stdbool.h>
14+
#include "pycore_structs.h" // _Py_BackoffCounter
1415

1516
/* 16-bit countdown counters using exponential backoff.
1617

Include/internal/pycore_interp_structs.h

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* This file contains the struct definitions for interpreter state
2+
* and other necessary structs */
3+
14
#ifndef Py_INTERNAL_INTERP_STRUCTS_H
25
#define Py_INTERNAL_INTERP_STRUCTS_H
36
#ifdef __cplusplus
@@ -12,9 +15,6 @@ extern "C" {
1215
#include "pycore_typedefs.h" // _PyRuntimeState
1316

1417

15-
/* This file contains the struct definitions for interpreter state
16-
* and other necessary structs */
17-
1818
#define CODE_MAX_WATCHERS 8
1919
#define CONTEXT_MAX_WATCHERS 8
2020
#define FUNC_MAX_WATCHERS 8
@@ -247,13 +247,7 @@ struct _gc_runtime_state {
247247
#endif
248248
};
249249

250-
#include "pycore_gil.h"
251-
252-
/****** Thread state **************/
253-
#include "pytypedefs.h"
254-
#include "pystate.h"
255-
#include "pycore_tstate.h"
256-
250+
#include "pycore_gil.h" // struct _gil_runtime_state
257251

258252
/**** Import ********/
259253

@@ -327,8 +321,8 @@ struct _import_state {
327321

328322
/********** Interpreter state **************/
329323

330-
#include "pycore_object_state.h"
331-
#include "pycore_crossinterp.h"
324+
#include "pycore_object_state.h" // struct _py_object_state
325+
#include "pycore_crossinterp.h" // _PyXI_state_t
332326

333327

334328
struct _Py_long_state {
@@ -453,8 +447,8 @@ struct _py_func_state {
453447
struct _func_version_cache_item func_version_cache[FUNC_VERSION_CACHE_SIZE];
454448
};
455449

456-
#include "pycore_dict_state.h"
457-
#include "pycore_exceptions.h"
450+
#include "pycore_dict_state.h" // struct _Py_dict_state
451+
#include "pycore_exceptions.h" // struct _Py_exc_state
458452

459453

460454
/****** type state *********/
@@ -635,7 +629,7 @@ struct _Py_unicode_ids {
635629
PyObject **array;
636630
};
637631

638-
#include "pycore_ucnhash.h"
632+
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
639633

640634
struct _Py_unicode_state {
641635
struct _Py_unicode_fs_codec fs_codec;
@@ -654,8 +648,6 @@ struct callable_cache {
654648
PyObject *object__getattribute__;
655649
};
656650

657-
#include "pycore_obmalloc.h"
658-
659651
/* Length of array of slotdef pointers used to store slots with the
660652
same __name__. There should be at most MAX_EQUIV-1 slotdef entries with
661653
the same __name__, for any __name__. Since that's a static property, it is
@@ -696,7 +688,7 @@ struct _Py_interp_static_objects {
696688
} singletons;
697689
};
698690

699-
#include "pycore_instruments.h"
691+
#include "pycore_instruments.h" // PY_MONITORING_TOOL_IDS
700692

701693

702694
#ifdef Py_GIL_DISABLED
@@ -955,7 +947,6 @@ struct _is {
955947
};
956948

957949

958-
959950
#ifdef __cplusplus
960951
}
961952
#endif

Include/internal/pycore_runtime_structs.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
/* This file contains the struct definitions for the runtime, interpreter
2+
* and thread states, plus all smaller structs contained therein */
3+
14
#ifndef Py_INTERNAL_RUNTIME_STRUCTS_H
25
#define Py_INTERNAL_RUNTIME_STRUCTS_H
36
#ifdef __cplusplus
47
extern "C" {
58
#endif
69

7-
/* This file contains the struct definitions for the runtime, interpreter
8-
* and thread states, plus all smaller structs contained therein */
9-
10-
#include "pycore_structs.h"
11-
#include "pycore_interp_structs.h"
10+
#include "pycore_interp_structs.h" // _PyGC_Head_UNUSED
11+
#include "pycore_obmalloc.h" // struct _obmalloc_global_state
1212

1313
/************ Runtime state ************/
1414

@@ -58,17 +58,16 @@ struct pyhash_runtime_state {
5858
} urandom_cache;
5959
};
6060

61-
#include "pycore_tracemalloc.h"
61+
#include "pycore_tracemalloc.h" // struct _tracemalloc_runtime_state
6262

6363
struct _fileutils_state {
6464
int force_ascii;
6565
};
6666

67-
#include "pycore_debug_offsets.h"
68-
#include "pycore_signal.h"
69-
#include "pycore_faulthandler.h"
70-
#include "pycore_pythread.h"
71-
#include "pycore_ast.h"
67+
#include "pycore_debug_offsets.h" // _Py_DebugOffsets
68+
#include "pycore_signal.h" // struct _signals_runtime_state
69+
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state
70+
#include "pycore_ast.h" // struct _expr
7271

7372
#ifdef Py_DEBUG
7473
#define _PYPEGEN_NSTATISTICS 2000
@@ -109,7 +108,7 @@ struct _Py_cached_objects {
109108
#define _PY_NSMALLPOSINTS 257
110109
#define _PY_NSMALLNEGINTS 5
111110

112-
#include "pycore_global_strings.h"
111+
#include "pycore_global_strings.h" // struct _Py_global_strings
113112

114113
struct _Py_static_objects {
115114
struct {
@@ -310,7 +309,6 @@ struct pyruntimestate {
310309
};
311310

312311

313-
314312
#ifdef __cplusplus
315313
}
316314
#endif

Include/internal/pycore_structs.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1+
/* This files contains various key structs that are widely used
2+
* and do not depend on other headers. */
3+
14
#ifndef Py_INTERNAL_STRUCTS_H
25
#define Py_INTERNAL_STRUCTS_H
36
#ifdef __cplusplus
47
extern "C" {
58
#endif
69

7-
/* This files contains various key structs that are widely used
8-
* and do not depend on other headers. */
9-
10-
#include <stddef.h>
11-
#include <stdint.h>
12-
#include <stdbool.h>
10+
#include <stdint.h> // uint16_t
1311

1412

1513
typedef struct {
@@ -54,7 +52,7 @@ typedef struct {
5452
PyObject *b_array[1];
5553
} PyHamtNode_Bitmap;
5654

57-
#include "pycore_context.h"
55+
#include "pycore_context.h" // _PyContextTokenMissing
5856

5957
// Define this to get precise tracking of stackrefs.
6058
// #define Py_STACKREF_DEBUG 1

0 commit comments

Comments
 (0)