Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit d535c74

Browse files
author
Anselm Kruis
committed
Stackless issue #254: Make PyInterpreterState an opaque type in the
public API. Adapt Stackless to bpo-35886 and move the definition of PyStacklessInterpreterState from cpython/slp_tstate.h to internal/pycore_slp_pystate.h
1 parent 0f62f5b commit d535c74

File tree

4 files changed

+47
-44
lines changed

4 files changed

+47
-44
lines changed

Include/cpython/pystate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ struct _ts {
162162

163163
/* XXX signal handlers should also be here */
164164

165+
#ifdef STACKLESS
166+
PyStacklessState st;
167+
#endif
165168
};
166169

167170
/* Get the current interpreter state.

Include/cpython/slp_tstate.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,6 @@ struct _ts;
1010

1111
typedef int (slp_schedule_hook_func) (struct _tasklet *from, struct _tasklet *to);
1212

13-
typedef struct {
14-
struct _cstack * cstack_chain; /* the chain of all C-stacks of this interpreter. This is an uncounted/borrowed ref. */
15-
PyObject * reduce_frame_func; /* a function used to pickle frames */
16-
PyObject * error_handler; /* the Stackless error handler */
17-
PyObject * channel_hook; /* the channel callback function */
18-
struct _bomb * mem_bomb; /* a permanent bomb to use for memory errors */
19-
PyObject * schedule_hook; /* the schedule callback function */
20-
slp_schedule_hook_func * schedule_fasthook; /* the fast C-only schedule_hook */
21-
struct _ts * initial_tstate; /* recording the main thread state */
22-
uint8_t enable_softswitch; /* the flag which decides whether we try to use soft switching */
23-
uint8_t pickleflags; /* flags for pickling / unpickling */
24-
} PyStacklessInterpreterState;
25-
26-
#ifdef Py_BUILD_CORE
27-
#define SLP_INITIAL_TSTATE(tstate) \
28-
(assert(tstate), \
29-
assert((tstate)->interp->st.initial_tstate), \
30-
(tstate)->interp->st.initial_tstate)
31-
32-
#define SPL_INTERPRETERSTATE_NEW(interp) \
33-
(interp)->st.cstack_chain = NULL; \
34-
(interp)->st.reduce_frame_func = NULL; \
35-
(interp)->st.error_handler = NULL; \
36-
(interp)->st.channel_hook = NULL; \
37-
(interp)->st.mem_bomb = NULL; \
38-
(interp)->st.schedule_hook = NULL; \
39-
(interp)->st.schedule_fasthook = NULL; \
40-
(interp)->st.initial_tstate = NULL; \
41-
(interp)->st.enable_softswitch = 1; \
42-
(interp)->st.pickleflags = 0;
43-
44-
#define SPL_INTERPRETERSTATE_CLEAR(interp) \
45-
(interp)->st.cstack_chain = NULL; /* uncounted ref */ \
46-
Py_CLEAR((interp)->st.reduce_frame_func); \
47-
Py_CLEAR((interp)->st.error_handler); \
48-
Py_CLEAR((interp)->st.mem_bomb); \
49-
Py_CLEAR((interp)->st.channel_hook); \
50-
Py_CLEAR((interp)->st.schedule_hook); \
51-
(interp)->st.schedule_fasthook = NULL; \
52-
(interp)->st.enable_softswitch = 1; \
53-
(interp)->st.pickleflags = 0;
54-
55-
#endif /* #ifdef Py_BUILD_CORE */
56-
5713
struct _frame; /* Avoid including frameobject.h */
5814

5915
typedef struct _sts {

Include/internal/pycore_pystate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ struct _is {
8181
PyObject *pyexitmodule;
8282

8383
uint64_t tstate_next_unique_id;
84+
#ifdef STACKLESS
85+
PyStacklessInterpreterState st;
86+
#endif
8487
};
8588

8689
PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(PY_INT64_T);

Include/internal/pycore_slp_pystate.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,47 @@
2626
#define SLP_CSTACK_SLOTS 1024
2727
#endif
2828

29+
typedef struct {
30+
struct _cstack * cstack_chain; /* the chain of all C-stacks of this interpreter. This is an uncounted/borrowed ref. */
31+
PyObject * reduce_frame_func; /* a function used to pickle frames */
32+
PyObject * error_handler; /* the Stackless error handler */
33+
PyObject * channel_hook; /* the channel callback function */
34+
struct _bomb * mem_bomb; /* a permanent bomb to use for memory errors */
35+
PyObject * schedule_hook; /* the schedule callback function */
36+
slp_schedule_hook_func * schedule_fasthook; /* the fast C-only schedule_hook */
37+
struct _ts * initial_tstate; /* recording the main thread state */
38+
uint8_t enable_softswitch; /* the flag which decides whether we try to use soft switching */
39+
uint8_t pickleflags; /* flags for pickling / unpickling */
40+
} PyStacklessInterpreterState;
41+
42+
#define SLP_INITIAL_TSTATE(tstate) \
43+
(assert(tstate), \
44+
assert((tstate)->interp->st.initial_tstate), \
45+
(tstate)->interp->st.initial_tstate)
46+
47+
#define SPL_INTERPRETERSTATE_NEW(interp) \
48+
(interp)->st.cstack_chain = NULL; \
49+
(interp)->st.reduce_frame_func = NULL; \
50+
(interp)->st.error_handler = NULL; \
51+
(interp)->st.channel_hook = NULL; \
52+
(interp)->st.mem_bomb = NULL; \
53+
(interp)->st.schedule_hook = NULL; \
54+
(interp)->st.schedule_fasthook = NULL; \
55+
(interp)->st.initial_tstate = NULL; \
56+
(interp)->st.enable_softswitch = 1; \
57+
(interp)->st.pickleflags = 0;
58+
59+
#define SPL_INTERPRETERSTATE_CLEAR(interp) \
60+
(interp)->st.cstack_chain = NULL; /* uncounted ref */ \
61+
Py_CLEAR((interp)->st.reduce_frame_func); \
62+
Py_CLEAR((interp)->st.error_handler); \
63+
Py_CLEAR((interp)->st.mem_bomb); \
64+
Py_CLEAR((interp)->st.channel_hook); \
65+
Py_CLEAR((interp)->st.schedule_hook); \
66+
(interp)->st.schedule_fasthook = NULL; \
67+
(interp)->st.enable_softswitch = 1; \
68+
(interp)->st.pickleflags = 0;
69+
2970
/*
3071
* Stackless runtime state
3172
*

0 commit comments

Comments
 (0)