bpo-35886: Make PyInterpreterState an opaque type in the public API. … · python/cpython@be3b295 (original) (raw)
`@@ -17,37 +17,74 @@ extern "C" {
`
17
17
`#include "pycore_warnings.h"
`
18
18
``
19
19
``
20
``
`-
/* GIL state */
`
``
20
`+
/* interpreter state */
`
21
21
``
22
``
`-
struct _gilstate_runtime_state {
`
23
``
`-
int check_enabled;
`
24
``
`-
/* Assuming the current thread holds the GIL, this is the
`
25
``
`-
PyThreadState for the current thread. */
`
26
``
`-
_Py_atomic_address tstate_current;
`
27
``
`-
PyThreadFrameGetter getframe;
`
28
``
`-
/* The single PyInterpreterState used by this process'
`
29
``
`-
GILState implementation
`
30
``
`-
*/
`
31
``
`-
/* TODO: Given interp_main, it may be possible to kill this ref */
`
32
``
`-
PyInterpreterState *autoInterpreterState;
`
33
``
`-
Py_tss_t autoTSSkey;
`
34
``
`-
};
`
``
22
`+
typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
`
``
23
+
``
24
`+
// The PyInterpreterState typedef is in Include/pystate.h.
`
``
25
`+
struct _is {
`
``
26
+
``
27
`+
struct _is *next;
`
``
28
`+
struct _ts *tstate_head;
`
``
29
+
``
30
`+
int64_t id;
`
``
31
`+
int64_t id_refcount;
`
``
32
`+
PyThread_type_lock id_mutex;
`
``
33
+
``
34
`+
PyObject *modules;
`
``
35
`+
PyObject *modules_by_index;
`
``
36
`+
PyObject *sysdict;
`
``
37
`+
PyObject *builtins;
`
``
38
`+
PyObject *importlib;
`
``
39
+
``
40
`+
/* Used in Python/sysmodule.c. */
`
``
41
`+
int check_interval;
`
``
42
+
``
43
`+
/* Used in Modules/_threadmodule.c. */
`
``
44
`+
long num_threads;
`
``
45
`+
/* Support for runtime thread stack size tuning.
`
``
46
`+
A value of 0 means using the platform's default stack size
`
``
47
`+
or the size specified by the THREAD_STACK_SIZE macro. */
`
``
48
`+
/* Used in Python/thread.c. */
`
``
49
`+
size_t pythread_stacksize;
`
``
50
+
``
51
`+
PyObject *codec_search_path;
`
``
52
`+
PyObject *codec_search_cache;
`
``
53
`+
PyObject *codec_error_registry;
`
``
54
`+
int codecs_initialized;
`
``
55
`+
int fscodec_initialized;
`
``
56
+
``
57
`+
_PyCoreConfig core_config;
`
``
58
`+
_PyMainInterpreterConfig config;
`
``
59
`+
#ifdef HAVE_DLOPEN
`
``
60
`+
int dlopenflags;
`
``
61
`+
#endif
`
35
62
``
36
``
`-
/* hook for PyEval_GetFrame(), requested for Psyco */
`
37
``
`-
#define _PyThreadState_GetFrame _PyRuntime.gilstate.getframe
`
``
63
`+
PyObject *builtins_copy;
`
``
64
`+
PyObject *import_func;
`
``
65
`+
/* Initialized to PyEval_EvalFrameDefault(). */
`
``
66
`+
_PyFrameEvalFunction eval_frame;
`
38
67
``
39
``
`-
/* Issue #26558: Flag to disable PyGILState_Check().
`
40
``
`-
If set to non-zero, PyGILState_Check() always return 1. */
`
41
``
`-
#define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
`
``
68
`+
Py_ssize_t co_extra_user_count;
`
``
69
`+
freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS];
`
42
70
``
``
71
`+
#ifdef HAVE_FORK
`
``
72
`+
PyObject *before_forkers;
`
``
73
`+
PyObject *after_forkers_parent;
`
``
74
`+
PyObject *after_forkers_child;
`
``
75
`+
#endif
`
``
76
`+
/* AtExit module */
`
``
77
`+
void (*pyexitfunc)(PyObject *);
`
``
78
`+
PyObject *pyexitmodule;
`
43
79
``
44
``
`-
/* interpreter state */
`
``
80
`+
uint64_t tstate_next_unique_id;
`
``
81
`+
};
`
45
82
``
46
``
`-
PyAPI_FUNC(PyInterpreterState *) _PyInterpreterState_LookUpID(PY_INT64_T);
`
``
83
`+
PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(PY_INT64_T);
`
47
84
``
48
``
`-
PyAPI_FUNC(int) _PyInterpreterState_IDInitref(PyInterpreterState *);
`
49
``
`-
PyAPI_FUNC(void) _PyInterpreterState_IDIncref(PyInterpreterState *);
`
50
``
`-
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(PyInterpreterState *);
`
``
85
`+
PyAPI_FUNC(int) _PyInterpreterState_IDInitref(struct _is *);
`
``
86
`+
PyAPI_FUNC(void) _PyInterpreterState_IDIncref(struct _is *);
`
``
87
`+
PyAPI_FUNC(void) _PyInterpreterState_IDDecref(struct _is *);
`
51
88
``
52
89
``
53
90
`/* cross-interpreter data */
`
`@@ -119,6 +156,30 @@ struct _xidregitem {
`
119
156
`};
`
120
157
``
121
158
``
``
159
`+
/* GIL state */
`
``
160
+
``
161
`+
struct _gilstate_runtime_state {
`
``
162
`+
int check_enabled;
`
``
163
`+
/* Assuming the current thread holds the GIL, this is the
`
``
164
`+
PyThreadState for the current thread. */
`
``
165
`+
_Py_atomic_address tstate_current;
`
``
166
`+
PyThreadFrameGetter getframe;
`
``
167
`+
/* The single PyInterpreterState used by this process'
`
``
168
`+
GILState implementation
`
``
169
`+
*/
`
``
170
`+
/* TODO: Given interp_main, it may be possible to kill this ref */
`
``
171
`+
PyInterpreterState *autoInterpreterState;
`
``
172
`+
Py_tss_t autoTSSkey;
`
``
173
`+
};
`
``
174
+
``
175
`+
/* hook for PyEval_GetFrame(), requested for Psyco */
`
``
176
`+
#define _PyThreadState_GetFrame _PyRuntime.gilstate.getframe
`
``
177
+
``
178
`+
/* Issue #26558: Flag to disable PyGILState_Check().
`
``
179
`+
If set to non-zero, PyGILState_Check() always return 1. */
`
``
180
`+
#define _PyGILState_check_enabled _PyRuntime.gilstate.check_enabled
`
``
181
+
``
182
+
122
183
`/* Full Python runtime state */
`
123
184
``
124
185
`typedef struct pyruntimestate {
`