Skip to content

Commit 6131707

Browse files
authored
gh-131238: Add pycore_interpframe_structs.h header (#131553)
Add an explicit include to pycore_interpframe_structs.h in pycore_runtime_structs.h to fix a dependency cycle.
1 parent 1a08208 commit 6131707

File tree

7 files changed

+99
-81
lines changed

7 files changed

+99
-81
lines changed

Include/internal/pycore_genobject.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,9 @@ extern "C" {
99
#endif
1010

1111
#include "pycore_interpframe.h" // _PyInterpreterFrame
12+
#include "pycore_interpframe_structs.h" // _PyGenObject
1213

1314

14-
/* _PyGenObject_HEAD defines the initial segment of generator
15-
and coroutine objects. */
16-
#define _PyGenObject_HEAD(prefix) \
17-
PyObject_HEAD \
18-
/* List of weak reference. */ \
19-
PyObject *prefix##_weakreflist; \
20-
/* Name of the generator. */ \
21-
PyObject *prefix##_name; \
22-
/* Qualified name of the generator. */ \
23-
PyObject *prefix##_qualname; \
24-
_PyErr_StackItem prefix##_exc_state; \
25-
PyObject *prefix##_origin_or_finalizer; \
26-
char prefix##_hooks_inited; \
27-
char prefix##_closed; \
28-
char prefix##_running_async; \
29-
/* The frame */ \
30-
int8_t prefix##_frame_state; \
31-
_PyInterpreterFrame prefix##_iframe; \
32-
33-
struct _PyGenObject {
34-
/* The gi_ prefix is intended to remind of generator-iterator. */
35-
_PyGenObject_HEAD(gi)
36-
};
37-
38-
struct _PyCoroObject {
39-
_PyGenObject_HEAD(cr)
40-
};
41-
42-
struct _PyAsyncGenObject {
43-
_PyGenObject_HEAD(ag)
44-
};
45-
46-
#undef _PyGenObject_HEAD
47-
4815
static inline
4916
PyGenObject *_PyGen_GetGeneratorFromFrame(_PyInterpreterFrame *frame)
5017
{

Include/internal/pycore_interpframe.h

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/* See InternalDocs/frames.md for an explanation of the frame stack
2-
* including explanation of the PyFrameObject and _PyInterpreterFrame
3-
* structs. */
4-
51
#ifndef Py_INTERNAL_INTERP_FRAME_H
62
#define Py_INTERNAL_INTERP_FRAME_H
73

@@ -10,50 +6,14 @@
106
#endif
117

128
#include "pycore_code.h" // _PyCode_CODE()
9+
#include "pycore_interpframe_structs.h" // _PyInterpreterFrame
1310
#include "pycore_stackref.h" // PyStackRef_AsPyObjectBorrow()
1411
#include "pycore_stats.h" // CALL_STAT_INC()
15-
#include "pycore_structs.h" // _PyStackRef
16-
#include "pycore_typedefs.h" // _PyInterpreterFrame
17-
1812

1913
#ifdef __cplusplus
2014
extern "C" {
2115
#endif
2216

23-
enum _frameowner {
24-
FRAME_OWNED_BY_THREAD = 0,
25-
FRAME_OWNED_BY_GENERATOR = 1,
26-
FRAME_OWNED_BY_FRAME_OBJECT = 2,
27-
FRAME_OWNED_BY_INTERPRETER = 3,
28-
FRAME_OWNED_BY_CSTACK = 4,
29-
};
30-
31-
struct _PyInterpreterFrame {
32-
_PyStackRef f_executable; /* Deferred or strong reference (code object or None) */
33-
struct _PyInterpreterFrame *previous;
34-
_PyStackRef f_funcobj; /* Deferred or strong reference. Only valid if not on C stack */
35-
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
36-
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
37-
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
38-
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
39-
_Py_CODEUNIT *instr_ptr; /* Instruction currently executing (or about to begin) */
40-
_PyStackRef *stackpointer;
41-
#ifdef Py_GIL_DISABLED
42-
/* Index of thread-local bytecode containing instr_ptr. */
43-
int32_t tlbc_index;
44-
#endif
45-
uint16_t return_offset; /* Only relevant during a function call */
46-
char owner;
47-
#ifdef Py_DEBUG
48-
uint8_t visited:1;
49-
uint8_t lltrace:7;
50-
#else
51-
uint8_t visited;
52-
#endif
53-
/* Locals and stack */
54-
_PyStackRef localsplus[1];
55-
};
56-
5717
#define _PyInterpreterFrame_LASTI(IF) \
5818
((int)((IF)->instr_ptr - _PyFrame_GetBytecode((IF))))
5919

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* Structures used by pycore_debug_offsets.h.
2+
*
3+
* See InternalDocs/frames.md for an explanation of the frame stack
4+
* including explanation of the PyFrameObject and _PyInterpreterFrame
5+
* structs.
6+
*/
7+
8+
#ifndef Py_INTERNAL_INTERP_FRAME_STRUCTS_H
9+
#define Py_INTERNAL_INTERP_FRAME_STRUCTS_H
10+
11+
#ifndef Py_BUILD_CORE
12+
# error "this header requires Py_BUILD_CORE define"
13+
#endif
14+
15+
#include "pycore_structs.h" // _PyStackRef
16+
#include "pycore_typedefs.h" // _PyInterpreterFrame
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
enum _frameowner {
23+
FRAME_OWNED_BY_THREAD = 0,
24+
FRAME_OWNED_BY_GENERATOR = 1,
25+
FRAME_OWNED_BY_FRAME_OBJECT = 2,
26+
FRAME_OWNED_BY_INTERPRETER = 3,
27+
FRAME_OWNED_BY_CSTACK = 4,
28+
};
29+
30+
struct _PyInterpreterFrame {
31+
_PyStackRef f_executable; /* Deferred or strong reference (code object or None) */
32+
struct _PyInterpreterFrame *previous;
33+
_PyStackRef f_funcobj; /* Deferred or strong reference. Only valid if not on C stack */
34+
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
35+
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
36+
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
37+
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
38+
_Py_CODEUNIT *instr_ptr; /* Instruction currently executing (or about to begin) */
39+
_PyStackRef *stackpointer;
40+
#ifdef Py_GIL_DISABLED
41+
/* Index of thread-local bytecode containing instr_ptr. */
42+
int32_t tlbc_index;
43+
#endif
44+
uint16_t return_offset; /* Only relevant during a function call */
45+
char owner;
46+
#ifdef Py_DEBUG
47+
uint8_t visited:1;
48+
uint8_t lltrace:7;
49+
#else
50+
uint8_t visited;
51+
#endif
52+
/* Locals and stack */
53+
_PyStackRef localsplus[1];
54+
};
55+
56+
57+
/* _PyGenObject_HEAD defines the initial segment of generator
58+
and coroutine objects. */
59+
#define _PyGenObject_HEAD(prefix) \
60+
PyObject_HEAD \
61+
/* List of weak reference. */ \
62+
PyObject *prefix##_weakreflist; \
63+
/* Name of the generator. */ \
64+
PyObject *prefix##_name; \
65+
/* Qualified name of the generator. */ \
66+
PyObject *prefix##_qualname; \
67+
_PyErr_StackItem prefix##_exc_state; \
68+
PyObject *prefix##_origin_or_finalizer; \
69+
char prefix##_hooks_inited; \
70+
char prefix##_closed; \
71+
char prefix##_running_async; \
72+
/* The frame */ \
73+
int8_t prefix##_frame_state; \
74+
_PyInterpreterFrame prefix##_iframe; \
75+
76+
struct _PyGenObject {
77+
/* The gi_ prefix is intended to remind of generator-iterator. */
78+
_PyGenObject_HEAD(gi)
79+
};
80+
81+
struct _PyCoroObject {
82+
_PyGenObject_HEAD(cr)
83+
};
84+
85+
struct _PyAsyncGenObject {
86+
_PyGenObject_HEAD(ag)
87+
};
88+
89+
#undef _PyGenObject_HEAD
90+
91+
92+
#ifdef __cplusplus
93+
}
94+
#endif
95+
#endif // !Py_INTERNAL_INTERP_FRAME_STRUCTS_H

Include/internal/pycore_runtime_structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct _fileutils_state {
6464
int force_ascii;
6565
};
6666

67+
#include "pycore_interpframe_structs.h" // _PyInterpreterFrame
6768
#include "pycore_debug_offsets.h" // _Py_DebugOffsets
6869
#include "pycore_signal.h" // struct _signals_runtime_state
6970
#include "pycore_faulthandler.h" // struct _faulthandler_runtime_state

Objects/genobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#define _PY_INTERPRETER
44

55
#include "Python.h"
6-
#include "pycore_genobject.h"
7-
86
#include "pycore_call.h" // _PyObject_CallNoArgs()
97
#include "pycore_ceval.h" // _PyEval_EvalFrame()
108
#include "pycore_frame.h" // _PyInterpreterFrame
119
#include "pycore_freelist.h" // _Py_FREELIST_FREE(), _Py_FREELIST_POP()
1210
#include "pycore_gc.h" // _PyGC_CLEAR_FINALIZED()
11+
#include "pycore_genobject.h"
1312
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
1413
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
1514
#include "pycore_opcode_utils.h" // RESUME_AFTER_YIELD_FROM

Python/pylifecycle.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* Python interpreter top-level routines, including init/exit */
22

33
#include "Python.h"
4-
#include "pycore_genobject.h" // included first to break dependency cycle
5-
64
#include "pycore_audit.h" // _PySys_ClearAuditHooks()
75
#include "pycore_call.h" // _PyObject_CallMethod()
86
#include "pycore_ceval.h" // _PyEval_FiniGIL()

Python/pystate.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/* Thread and interpreter state structures and their interfaces */
33

44
#include "Python.h"
5-
#include "pycore_genobject.h" // included first to break dependency cycle
6-
75
#include "pycore_abstract.h" // _PyIndex_Check()
86
#include "pycore_audit.h" // _Py_AuditHookEntry
97
#include "pycore_ceval.h" // _PyEval_AcquireLock()

0 commit comments

Comments
 (0)