PyInterpreterState *interp,
int (*func)(void *),
void *arg);
-PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyThreadState *tstate);
+PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
#ifdef HAVE_FORK
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
#endif
extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
#endif
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
-extern void _PyEval_FiniGIL(PyThreadState *tstate);
+extern void _PyEval_FiniGIL(PyInterpreterState *interp);
extern void _PyEval_ReleaseLock(PyThreadState *tstate);
int _PyContext_Init(void);
-void _PyContext_Fini(PyThreadState *tstate);
+void _PyContext_Fini(PyInterpreterState *interp);
#endif /* !Py_INTERNAL_CONTEXT_H */
// Functions to clear types free lists
-extern void _PyFrame_ClearFreeList(PyThreadState *tstate);
-extern void _PyTuple_ClearFreeList(PyThreadState *tstate);
-extern void _PyFloat_ClearFreeList(PyThreadState *tstate);
-extern void _PyList_ClearFreeList(PyThreadState *tstate);
-extern void _PyDict_ClearFreeList(PyThreadState *tstate);
-extern void _PyAsyncGen_ClearFreeLists(PyThreadState *tstate);
-extern void _PyContext_ClearFreeList(PyThreadState *tstate);
+extern void _PyFrame_ClearFreeList(PyInterpreterState *interp);
+extern void _PyTuple_ClearFreeList(PyInterpreterState *interp);
+extern void _PyFloat_ClearFreeList(PyInterpreterState *interp);
+extern void _PyList_ClearFreeList(PyInterpreterState *interp);
+extern void _PyDict_ClearFreeList(PyInterpreterState *interp);
+extern void _PyAsyncGen_ClearFreeLists(PyInterpreterState *interp);
+extern void _PyContext_ClearFreeList(PyInterpreterState *interp);
#ifdef __cplusplus
}
/* Various one-time initializers */
-extern PyStatus _PyUnicode_Init(PyThreadState *tstate);
-extern PyStatus _PyBytes_Init(PyThreadState *tstate);
+extern PyStatus _PyUnicode_Init(PyInterpreterState *interp);
+extern PyStatus _PyBytes_Init(PyInterpreterState *interp);
extern int _PyStructSequence_Init(void);
-extern int _PyLong_Init(PyThreadState *tstate);
-extern PyStatus _PyTuple_Init(PyThreadState *tstate);
+extern int _PyLong_Init(PyInterpreterState *interp);
+extern PyStatus _PyTuple_Init(PyInterpreterState *interp);
extern PyStatus _PyFaulthandler_Init(int enable);
extern int _PyTraceMalloc_Init(int enable);
-extern PyObject * _PyBuiltin_Init(PyThreadState *tstate);
+extern PyObject * _PyBuiltin_Init(PyInterpreterState *interp);
extern PyStatus _PySys_Create(
PyThreadState *tstate,
PyObject **sysmod_p);
extern PyStatus _PySys_ReadPreinitWarnOptions(PyWideStringList *options);
extern PyStatus _PySys_ReadPreinitXOptions(PyConfig *config);
extern int _PySys_UpdateConfig(PyThreadState *tstate);
-extern PyStatus _PyExc_Init(PyThreadState *tstate);
+extern PyStatus _PyExc_Init(PyInterpreterState *interp);
extern PyStatus _PyErr_Init(void);
extern PyStatus _PyBuiltins_AddExceptions(PyObject * bltinmod);
extern int _PyFloat_Init(void);
extern PyStatus _PyTypes_Init(void);
extern PyStatus _PyTypes_InitSlotDefs(void);
extern PyStatus _PyImportZip_Init(PyThreadState *tstate);
-extern PyStatus _PyGC_Init(PyThreadState *tstate);
-extern PyStatus _PyAtExit_Init(PyThreadState *tstate);
+extern PyStatus _PyGC_Init(PyInterpreterState *interp);
+extern PyStatus _PyAtExit_Init(PyInterpreterState *interp);
/* Various internal finalizers */
-extern void _PyFrame_Fini(PyThreadState *tstate);
-extern void _PyDict_Fini(PyThreadState *tstate);
-extern void _PyTuple_Fini(PyThreadState *tstate);
-extern void _PyList_Fini(PyThreadState *tstate);
-extern void _PyBytes_Fini(PyThreadState *tstate);
-extern void _PyFloat_Fini(PyThreadState *tstate);
-extern void _PySlice_Fini(PyThreadState *tstate);
-extern void _PyAsyncGen_Fini(PyThreadState *tstate);
+extern void _PyFrame_Fini(PyInterpreterState *interp);
+extern void _PyDict_Fini(PyInterpreterState *interp);
+extern void _PyTuple_Fini(PyInterpreterState *interp);
+extern void _PyList_Fini(PyInterpreterState *interp);
+extern void _PyBytes_Fini(PyInterpreterState *interp);
+extern void _PyFloat_Fini(PyInterpreterState *interp);
+extern void _PySlice_Fini(PyInterpreterState *interp);
+extern void _PyAsyncGen_Fini(PyInterpreterState *interp);
extern int _PySignal_Init(int install_signal_handlers);
extern void _PySignal_Fini(void);
-extern void _PyExc_Fini(PyThreadState *tstate);
+extern void _PyExc_Fini(PyInterpreterState *interp);
extern void _PyImport_Fini(void);
extern void _PyImport_Fini2(void);
-extern void _PyGC_Fini(PyThreadState *tstate);
-extern void _PyType_Fini(PyThreadState *tstate);
+extern void _PyGC_Fini(PyInterpreterState *interp);
+extern void _PyType_Fini(PyInterpreterState *interp);
extern void _Py_HashRandomization_Fini(void);
-extern void _PyUnicode_Fini(PyThreadState *tstate);
-extern void _PyUnicode_ClearInterned(PyThreadState *tstate);
-extern void _PyLong_Fini(PyThreadState *tstate);
+extern void _PyUnicode_Fini(PyInterpreterState *interp);
+extern void _PyUnicode_ClearInterned(PyInterpreterState *interp);
+extern void _PyLong_Fini(PyInterpreterState *interp);
extern void _PyFaulthandler_Fini(void);
extern void _PyHash_Fini(void);
extern void _PyTraceMalloc_Fini(void);
extern void _PyAtExit_Fini(PyInterpreterState *interp);
extern PyStatus _PyGILState_Init(PyThreadState *tstate);
-extern void _PyGILState_Fini(PyThreadState *tstate);
+extern void _PyGILState_Fini(PyInterpreterState *interp);
-PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyThreadState *tstate);
+PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyInterpreterState *interp);
PyAPI_FUNC(PyStatus) _Py_PreInitializeFromPyArgv(
const PyPreConfig *src_config,
PyAPI_FUNC(void) _PyThreadState_DeleteCurrent(PyThreadState *tstate);
-extern void _PyAtExit_Call(PyThreadState *tstate);
+extern void _PyAtExit_Call(PyInterpreterState *interp);
#ifdef __cplusplus
}
long filters_version;
};
-extern int _PyWarnings_InitState(PyThreadState *tstate);
+extern int _PyWarnings_InitState(PyInterpreterState *interp);
#ifdef __cplusplus
}
PyStatus
-_PyAtExit_Init(PyThreadState *tstate)
+_PyAtExit_Init(PyInterpreterState *interp)
{
- struct atexit_state *state = &tstate->interp->atexit;
+ struct atexit_state *state = &interp->atexit;
// _PyAtExit_Init() must only be called once
assert(state->callbacks == NULL);
void
-_PyAtExit_Call(PyThreadState *tstate)
+_PyAtExit_Call(PyInterpreterState *interp)
{
- struct atexit_state *state = &tstate->interp->atexit;
+ struct atexit_state *state = &interp->atexit;
atexit_callfuncs(state);
}
PyStatus
-_PyGC_Init(PyThreadState *tstate)
+_PyGC_Init(PyInterpreterState *interp)
{
- GCState *gcstate = &tstate->interp->gc;
+ GCState *gcstate = &interp->gc;
gcstate->garbage = PyList_New(0);
if (gcstate->garbage == NULL) {
* Clearing the free lists may give back memory to the OS earlier.
*/
static void
-clear_freelists(PyThreadState *tstate)
+clear_freelists(PyInterpreterState *interp)
{
- _PyFrame_ClearFreeList(tstate);
- _PyTuple_ClearFreeList(tstate);
- _PyFloat_ClearFreeList(tstate);
- _PyList_ClearFreeList(tstate);
- _PyDict_ClearFreeList(tstate);
- _PyAsyncGen_ClearFreeLists(tstate);
- _PyContext_ClearFreeList(tstate);
+ _PyFrame_ClearFreeList(interp);
+ _PyTuple_ClearFreeList(interp);
+ _PyFloat_ClearFreeList(interp);
+ _PyList_ClearFreeList(interp);
+ _PyDict_ClearFreeList(interp);
+ _PyAsyncGen_ClearFreeLists(interp);
+ _PyContext_ClearFreeList(interp);
}
// Show stats for objects in each generations
/* Clear free list only during the collection of the highest
* generation */
if (generation == NUM_GENERATIONS-1) {
- clear_freelists(tstate);
+ clear_freelists(tstate->interp);
}
if (_PyErr_Occurred(tstate)) {
}
void
-_PyGC_DumpShutdownStats(PyThreadState *tstate)
+_PyGC_DumpShutdownStats(PyInterpreterState *interp)
{
- GCState *gcstate = &tstate->interp->gc;
+ GCState *gcstate = &interp->gc;
if (!(gcstate->debug & DEBUG_SAVEALL)
&& gcstate->garbage != NULL && PyList_GET_SIZE(gcstate->garbage) > 0) {
const char *message;
}
void
-_PyGC_Fini(PyThreadState *tstate)
+_PyGC_Fini(PyInterpreterState *interp)
{
- GCState *gcstate = &tstate->interp->gc;
+ GCState *gcstate = &interp->gc;
Py_CLEAR(gcstate->garbage);
Py_CLEAR(gcstate->callbacks);
}
PyStatus
-_PyBytes_Init(PyThreadState *tstate)
+_PyBytes_Init(PyInterpreterState *interp)
{
- struct _Py_bytes_state *state = &tstate->interp->bytes;
+ struct _Py_bytes_state *state = &interp->bytes;
if (bytes_create_empty_string_singleton(state) < 0) {
return _PyStatus_NO_MEMORY();
}
void
-_PyBytes_Fini(PyThreadState *tstate)
+_PyBytes_Fini(PyInterpreterState *interp)
{
- struct _Py_bytes_state* state = &tstate->interp->bytes;
+ struct _Py_bytes_state* state = &interp->bytes;
for (int i = 0; i < UCHAR_MAX + 1; i++) {
Py_CLEAR(state->characters[i]);
}
void
-_PyDict_ClearFreeList(PyThreadState *tstate)
+_PyDict_ClearFreeList(PyInterpreterState *interp)
{
- struct _Py_dict_state *state = &tstate->interp->dict_state;
+ struct _Py_dict_state *state = &interp->dict_state;
while (state->numfree) {
PyDictObject *op = state->free_list[--state->numfree];
assert(PyDict_CheckExact(op));
void
-_PyDict_Fini(PyThreadState *tstate)
+_PyDict_Fini(PyInterpreterState *interp)
{
- _PyDict_ClearFreeList(tstate);
+ _PyDict_ClearFreeList(interp);
#ifdef Py_DEBUG
- struct _Py_dict_state *state = get_dict_state();
+ struct _Py_dict_state *state = &interp->dict_state;
state->numfree = -1;
state->keys_numfree = -1;
#endif
#endif /* MS_WINDOWS */
PyStatus
-_PyExc_Init(PyThreadState *tstate)
+_PyExc_Init(PyInterpreterState *interp)
{
- struct _Py_exc_state *state = &tstate->interp->exc_state;
+ struct _Py_exc_state *state = &interp->exc_state;
#define PRE_INIT(TYPE) \
if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
}
void
-_PyExc_Fini(PyThreadState *tstate)
+_PyExc_Fini(PyInterpreterState *interp)
{
- struct _Py_exc_state *state = &tstate->interp->exc_state;
+ struct _Py_exc_state *state = &interp->exc_state;
free_preallocated_memerrors(state);
Py_CLEAR(state->errnomap);
}
}
void
-_PyFloat_ClearFreeList(PyThreadState *tstate)
+_PyFloat_ClearFreeList(PyInterpreterState *interp)
{
- struct _Py_float_state *state = &tstate->interp->float_state;
+ struct _Py_float_state *state = &interp->float_state;
PyFloatObject *f = state->free_list;
while (f != NULL) {
PyFloatObject *next = (PyFloatObject*) Py_TYPE(f);
}
void
-_PyFloat_Fini(PyThreadState *tstate)
+_PyFloat_Fini(PyInterpreterState *interp)
{
- _PyFloat_ClearFreeList(tstate);
+ _PyFloat_ClearFreeList(interp);
#ifdef Py_DEBUG
- struct _Py_float_state *state = &tstate->interp->float_state;
+ struct _Py_float_state *state = &interp->float_state;
state->numfree = -1;
#endif
}
/* Clear out the free list */
void
-_PyFrame_ClearFreeList(PyThreadState *tstate)
+_PyFrame_ClearFreeList(PyInterpreterState *interp)
{
- struct _Py_frame_state *state = &tstate->interp->frame;
+ struct _Py_frame_state *state = &interp->frame;
while (state->free_list != NULL) {
PyFrameObject *f = state->free_list;
state->free_list = state->free_list->f_back;
}
void
-_PyFrame_Fini(PyThreadState *tstate)
+_PyFrame_Fini(PyInterpreterState *interp)
{
- _PyFrame_ClearFreeList(tstate);
+ _PyFrame_ClearFreeList(interp);
#ifdef Py_DEBUG
- struct _Py_frame_state *state = &tstate->interp->frame;
+ struct _Py_frame_state *state = &interp->frame;
state->numfree = -1;
#endif
}
void
-_PyAsyncGen_ClearFreeLists(PyThreadState *tstate)
+_PyAsyncGen_ClearFreeLists(PyInterpreterState *interp)
{
- struct _Py_async_gen_state *state = &tstate->interp->async_gen;
+ struct _Py_async_gen_state *state = &interp->async_gen;
while (state->value_numfree) {
_PyAsyncGenWrappedValue *o;
}
void
-_PyAsyncGen_Fini(PyThreadState *tstate)
+_PyAsyncGen_Fini(PyInterpreterState *interp)
{
- _PyAsyncGen_ClearFreeLists(tstate);
+ _PyAsyncGen_ClearFreeLists(interp);
#ifdef Py_DEBUG
- struct _Py_async_gen_state *state = &tstate->interp->async_gen;
+ struct _Py_async_gen_state *state = &interp->async_gen;
state->value_numfree = -1;
state->asend_numfree = -1;
#endif
}
void
-_PyList_ClearFreeList(PyThreadState *tstate)
+_PyList_ClearFreeList(PyInterpreterState *interp)
{
- struct _Py_list_state *state = &tstate->interp->list;
+ struct _Py_list_state *state = &interp->list;
while (state->numfree) {
PyListObject *op = state->free_list[--state->numfree];
assert(PyList_CheckExact(op));
}
void
-_PyList_Fini(PyThreadState *tstate)
+_PyList_Fini(PyInterpreterState *interp)
{
- _PyList_ClearFreeList(tstate);
+ _PyList_ClearFreeList(interp);
#ifdef Py_DEBUG
- struct _Py_list_state *state = &tstate->interp->list;
+ struct _Py_list_state *state = &interp->list;
state->numfree = -1;
#endif
}
}
int
-_PyLong_Init(PyThreadState *tstate)
+_PyLong_Init(PyInterpreterState *interp)
{
for (Py_ssize_t i=0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) {
sdigit ival = (sdigit)i - NSMALLNEGINTS;
Py_SET_SIZE(v, size);
v->ob_digit[0] = (digit)abs(ival);
- tstate->interp->small_ints[i] = v;
+ interp->small_ints[i] = v;
}
- if (_Py_IsMainInterpreter(tstate->interp)) {
+ if (_Py_IsMainInterpreter(interp)) {
/* initialize int_info */
if (Int_InfoType.tp_name == NULL) {
if (PyStructSequence_InitType2(&Int_InfoType, &int_info_desc) < 0) {
}
void
-_PyLong_Fini(PyThreadState *tstate)
+_PyLong_Fini(PyInterpreterState *interp)
{
for (Py_ssize_t i = 0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) {
- Py_CLEAR(tstate->interp->small_ints[i]);
+ Py_CLEAR(interp->small_ints[i]);
}
}
/* Slice object implementation */
-void _PySlice_Fini(PyThreadState *tstate)
+void _PySlice_Fini(PyInterpreterState *interp)
{
- PyInterpreterState *interp = tstate->interp;
PySliceObject *obj = interp->slice_cache;
if (obj != NULL) {
interp->slice_cache = NULL;
}
void
-_PyTuple_ClearFreeList(PyThreadState *tstate)
+_PyTuple_ClearFreeList(PyInterpreterState *interp)
{
#if PyTuple_MAXSAVESIZE > 0
- struct _Py_tuple_state *state = &tstate->interp->tuple;
+ struct _Py_tuple_state *state = &interp->tuple;
for (Py_ssize_t i = 1; i < PyTuple_MAXSAVESIZE; i++) {
PyTupleObject *p = state->free_list[i];
state->free_list[i] = NULL;
PyStatus
-_PyTuple_Init(PyThreadState *tstate)
+_PyTuple_Init(PyInterpreterState *interp)
{
- struct _Py_tuple_state *state = &tstate->interp->tuple;
+ struct _Py_tuple_state *state = &interp->tuple;
if (tuple_create_empty_tuple_singleton(state) < 0) {
return _PyStatus_NO_MEMORY();
}
void
-_PyTuple_Fini(PyThreadState *tstate)
+_PyTuple_Fini(PyInterpreterState *interp)
{
#if PyTuple_MAXSAVESIZE > 0
- struct _Py_tuple_state *state = &tstate->interp->tuple;
+ struct _Py_tuple_state *state = &interp->tuple;
// The empty tuple singleton must not be tracked by the GC
assert(!_PyObject_GC_IS_TRACKED(state->free_list[0]));
Py_CLEAR(state->free_list[0]);
- _PyTuple_ClearFreeList(tstate);
+ _PyTuple_ClearFreeList(interp);
#ifdef Py_DEBUG
state->numfree[0] = -1;
#endif
void
-_PyType_Fini(PyThreadState *tstate)
+_PyType_Fini(PyInterpreterState *interp)
{
- _PyType_ClearCache(&tstate->interp->type_cache);
- if (_Py_IsMainInterpreter(tstate->interp)) {
+ _PyType_ClearCache(&interp->type_cache);
+ if (_Py_IsMainInterpreter(interp)) {
clear_slotdefs();
}
}
/* Initialize the Unicode implementation */
PyStatus
-_PyUnicode_Init(PyThreadState *tstate)
+_PyUnicode_Init(PyInterpreterState *interp)
{
/* XXX - move this array to unicodectype.c ? */
const Py_UCS2 linebreak[] = {
0x2029, /* PARAGRAPH SEPARATOR */
};
- struct _Py_unicode_state *state = &tstate->interp->unicode;
+ struct _Py_unicode_state *state = &interp->unicode;
if (unicode_create_empty_string_singleton(state) < 0) {
return _PyStatus_NO_MEMORY();
}
- if (_Py_IsMainInterpreter(tstate->interp)) {
+ if (_Py_IsMainInterpreter(interp)) {
/* initialize the linebreak bloom filter */
bloom_linebreak = make_bloom_mask(
PyUnicode_2BYTE_KIND, linebreak,
void
-_PyUnicode_ClearInterned(PyThreadState *tstate)
+_PyUnicode_ClearInterned(PyInterpreterState *interp)
{
- struct _Py_unicode_state *state = &tstate->interp->unicode;
+ struct _Py_unicode_state *state = &interp->unicode;
if (state->interned == NULL) {
return;
}
static PyStatus
-init_stdio_encoding(PyThreadState *tstate)
+init_stdio_encoding(PyInterpreterState *interp)
{
/* Update the stdio encoding to the normalized Python codec name. */
- PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(tstate->interp);
+ PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(interp);
if (config_get_codec_name(&config->stdio_encoding) < 0) {
return _PyStatus_ERR("failed to get the Python codec name "
"of the stdio encoding");
return status;
}
- return init_stdio_encoding(tstate);
+ return init_stdio_encoding(tstate->interp);
}
void
-_PyUnicode_Fini(PyThreadState *tstate)
+_PyUnicode_Fini(PyInterpreterState *interp)
{
- struct _Py_unicode_state *state = &tstate->interp->unicode;
+ struct _Py_unicode_state *state = &interp->unicode;
// _PyUnicode_ClearInterned() must be called before
assert(state->interned == NULL);
/* Initialize the given warnings module state. */
int
-_PyWarnings_InitState(PyThreadState *tstate)
+_PyWarnings_InitState(PyInterpreterState *interp)
{
- WarningsState *st = &tstate->interp->warnings;
+ WarningsState *st = &interp->warnings;
if (st->filters == NULL) {
st->filters = init_filters();
PyObject *
-_PyBuiltin_Init(PyThreadState *tstate)
+_PyBuiltin_Init(PyInterpreterState *interp)
{
PyObject *mod, *dict, *debug;
- const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
+ const PyConfig *config = _PyInterpreterState_GetConfig(interp);
if (PyType_Ready(&PyFilter_Type) < 0 ||
PyType_Ready(&PyMap_Type) < 0 ||
}
void
-_PyEval_FiniGIL(PyThreadState *tstate)
+_PyEval_FiniGIL(PyInterpreterState *interp)
{
#ifndef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- if (!_Py_IsMainInterpreter(tstate->interp)) {
+ if (!_Py_IsMainInterpreter(interp)) {
/* Currently, the GIL is shared by all interpreters,
and only the main interpreter is responsible to create
and destroy it. */
#endif
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
- struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;
+ struct _gil_runtime_state *gil = &interp->ceval.gil;
#else
- struct _gil_runtime_state *gil = &tstate->interp->runtime->ceval.gil;
+ struct _gil_runtime_state *gil = &interp->runtime->ceval.gil;
#endif
if (!gil_created(gil)) {
/* First Py_InitializeFromConfig() call: the GIL doesn't exist
raised. */
void
-_PyEval_SignalAsyncExc(PyThreadState *tstate)
+_PyEval_SignalAsyncExc(PyInterpreterState *interp)
{
- assert(is_tstate_valid(tstate));
- SIGNAL_ASYNC_EXC(tstate->interp);
+ SIGNAL_ASYNC_EXC(interp);
}
PyThreadState *
}
static int
-make_pending_calls(PyThreadState *tstate)
+make_pending_calls(PyInterpreterState *interp)
{
- assert(is_tstate_valid(tstate));
-
/* only execute pending calls on main thread */
if (!_Py_ThreadCanHandlePendingCalls()) {
return 0;
/* unsignal before starting to call callbacks, so that any callback
added in-between re-signals */
- UNSIGNAL_PENDING_CALLS(tstate->interp);
+ UNSIGNAL_PENDING_CALLS(interp);
int res = 0;
/* perform a bounded number of calls, in case of recursion */
- struct _pending_calls *pending = &tstate->interp->ceval.pending;
+ struct _pending_calls *pending = &interp->ceval.pending;
for (int i=0; i<NPENDINGCALLS; i++) {
int (*func)(void *) = NULL;
void *arg = NULL;
error:
busy = 0;
- SIGNAL_PENDING_CALLS(tstate->interp);
+ SIGNAL_PENDING_CALLS(interp);
return res;
}
_Py_FinishPendingCalls(PyThreadState *tstate)
{
assert(PyGILState_Check());
+ assert(is_tstate_valid(tstate));
struct _pending_calls *pending = &tstate->interp->ceval.pending;
return;
}
- if (make_pending_calls(tstate) < 0) {
+ if (make_pending_calls(tstate->interp) < 0) {
PyObject *exc, *val, *tb;
_PyErr_Fetch(tstate, &exc, &val, &tb);
PyErr_BadInternalCall();
assert(PyGILState_Check());
PyThreadState *tstate = _PyThreadState_GET();
+ assert(is_tstate_valid(tstate));
/* Python signal handler doesn't really queue a callback: it only signals
that a signal was received, see _PyEval_SignalReceived(). */
return res;
}
- res = make_pending_calls(tstate);
+ res = make_pending_calls(tstate->interp);
if (res != 0) {
return res;
}
/* Pending calls */
struct _ceval_state *ceval2 = &tstate->interp->ceval;
if (_Py_atomic_load_relaxed(&ceval2->pending.calls_to_do)) {
- if (make_pending_calls(tstate) != 0) {
+ if (make_pending_calls(tstate->interp) != 0) {
return -1;
}
}
/* Don't access tstate if the thread must exit */
if (tstate->async_exc != NULL) {
- _PyEval_SignalAsyncExc(tstate);
+ _PyEval_SignalAsyncExc(tstate->interp);
}
MUTEX_UNLOCK(gil->mutex);
void
-_PyContext_ClearFreeList(PyThreadState *tstate)
+_PyContext_ClearFreeList(PyInterpreterState *interp)
{
- struct _Py_context_state *state = &tstate->interp->context;
+ struct _Py_context_state *state = &interp->context;
for (; state->numfree; state->numfree--) {
PyContext *ctx = state->freelist;
state->freelist = (PyContext *)ctx->ctx_weakreflist;
void
-_PyContext_Fini(PyThreadState *tstate)
+_PyContext_Fini(PyInterpreterState *interp)
{
- if (_Py_IsMainInterpreter(tstate->interp)) {
+ if (_Py_IsMainInterpreter(interp)) {
Py_CLEAR(_token_missing);
}
- _PyContext_ClearFreeList(tstate);
+ _PyContext_ClearFreeList(interp);
#ifdef Py_DEBUG
- struct _Py_context_state *state = &tstate->interp->context;
+ struct _Py_context_state *state = &interp->context;
state->numfree = -1;
#endif
_PyHamt_Fini();
int
_PyImport_SetModule(PyObject *name, PyObject *m)
{
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *modules = tstate->interp->modules;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyObject *modules = interp->modules;
return PyObject_SetItem(modules, name, m);
}
int
_PyImport_SetModuleString(const char *name, PyObject *m)
{
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *modules = tstate->interp->modules;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyObject *modules = interp->modules;
return PyMapping_SetItemString(modules, name, m);
}
static int
-import_ensure_initialized(PyThreadState *tstate, PyObject *mod, PyObject *name)
+import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *name)
{
- PyInterpreterState *interp = tstate->interp;
PyObject *spec;
_Py_IDENTIFIER(_lock_unlock_module);
mod = import_get_module(tstate, name);
if (mod != NULL && mod != Py_None) {
- if (import_ensure_initialized(tstate, mod, name) < 0) {
+ if (import_ensure_initialized(tstate->interp, mod, name) < 0) {
Py_DECREF(mod);
remove_importlib_frames(tstate);
return NULL;
}
if (mod != NULL && mod != Py_None) {
- if (import_ensure_initialized(tstate, mod, name) < 0) {
+ if (import_ensure_initialized(tstate->interp, mod, name) < 0) {
goto error;
}
}
Py_CLEAR(dict);
/* pre config */
- PyThreadState *tstate = _PyThreadState_GET();
- const PyPreConfig *pre_config = &tstate->interp->runtime->preconfig;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ const PyPreConfig *pre_config = &interp->runtime->preconfig;
dict = _PyPreConfig_AsDict(pre_config);
if (dict == NULL) {
goto error;
Py_CLEAR(dict);
/* core config */
- const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
+ const PyConfig *config = _PyInterpreterState_GetConfig(interp);
dict = _PyConfig_AsDict(config);
if (dict == NULL) {
goto error;
/* finalize_interp_delete() comment explains why _PyEval_FiniGIL() is
only called here. */
- _PyEval_FiniGIL(tstate);
+ _PyEval_FiniGIL(tstate->interp);
/* Auto-thread-state API */
status = _PyGILState_Init(tstate);
static PyStatus
-pycore_init_types(PyThreadState *tstate)
+pycore_init_types(PyInterpreterState *interp)
{
PyStatus status;
- int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
+ int is_main_interp = _Py_IsMainInterpreter(interp);
- status = _PyGC_Init(tstate);
+ status = _PyGC_Init(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
// Create the empty tuple singleton. It must be created before the first
// PyType_Ready() call since PyType_Ready() creates tuples, for tp_bases
// for example.
- status = _PyTuple_Init(tstate);
+ status = _PyTuple_Init(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
}
- if (!_PyLong_Init(tstate)) {
+ if (!_PyLong_Init(interp)) {
return _PyStatus_ERR("can't init longs");
}
- status = _PyUnicode_Init(tstate);
+ status = _PyUnicode_Init(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- status = _PyBytes_Init(tstate);
+ status = _PyBytes_Init(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- status = _PyExc_Init(tstate);
+ status = _PyExc_Init(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
}
- if (_PyWarnings_InitState(tstate) < 0) {
+ if (_PyWarnings_InitState(interp) < 0) {
return _PyStatus_ERR("can't initialize warnings");
}
- status = _PyAtExit_Init(tstate);
+ status = _PyAtExit_Init(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
static PyStatus
-pycore_init_builtins(PyThreadState *tstate)
+pycore_init_builtins(PyInterpreterState *interp)
{
- assert(!_PyErr_Occurred(tstate));
-
- PyObject *bimod = _PyBuiltin_Init(tstate);
+ PyObject *bimod = _PyBuiltin_Init(interp);
if (bimod == NULL) {
goto error;
}
- PyInterpreterState *interp = tstate->interp;
if (_PyImport_FixupBuiltin(bimod, "builtins", interp->modules) < 0) {
goto error;
}
}
interp->import_func = Py_NewRef(import_func);
- assert(!_PyErr_Occurred(tstate));
-
return _PyStatus_OK();
error:
PyStatus status;
PyObject *sysmod = NULL;
- status = pycore_init_types(tstate);
+ status = pycore_init_types(tstate->interp);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
goto done;
}
- status = pycore_init_builtins(tstate);
+ assert(!_PyErr_Occurred(tstate));
+
+ status = pycore_init_builtins(tstate->interp);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
+ assert(!_PyErr_Occurred(tstate));
+
const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
if (config->_install_importlib) {
/* This call sets up builtin and frozen import support */
// Dump GC stats before it's too late, since it uses the warnings
// machinery.
- _PyGC_DumpShutdownStats(tstate);
+ _PyGC_DumpShutdownStats(interp);
if (weaklist != NULL) {
// Now, if there are any modules left alive, clear their globals to
static void
-finalize_interp_types(PyThreadState *tstate)
+finalize_interp_types(PyInterpreterState *interp)
{
- _PyExc_Fini(tstate);
- _PyFrame_Fini(tstate);
- _PyAsyncGen_Fini(tstate);
- _PyContext_Fini(tstate);
- _PyType_Fini(tstate);
+ _PyExc_Fini(interp);
+ _PyFrame_Fini(interp);
+ _PyAsyncGen_Fini(interp);
+ _PyContext_Fini(interp);
+ _PyType_Fini(interp);
// Call _PyUnicode_ClearInterned() before _PyDict_Fini() since it uses
// a dict internally.
- _PyUnicode_ClearInterned(tstate);
+ _PyUnicode_ClearInterned(interp);
- _PyDict_Fini(tstate);
- _PyList_Fini(tstate);
- _PyTuple_Fini(tstate);
+ _PyDict_Fini(interp);
+ _PyList_Fini(interp);
+ _PyTuple_Fini(interp);
- _PySlice_Fini(tstate);
+ _PySlice_Fini(interp);
- _PyBytes_Fini(tstate);
- _PyUnicode_Fini(tstate);
- _PyFloat_Fini(tstate);
- _PyLong_Fini(tstate);
+ _PyBytes_Fini(interp);
+ _PyUnicode_Fini(interp);
+ _PyFloat_Fini(interp);
+ _PyLong_Fini(interp);
}
_Py_ClearFileSystemEncoding();
}
- finalize_interp_types(tstate);
+ finalize_interp_types(tstate->interp);
}
static void
-finalize_interp_delete(PyThreadState *tstate)
+finalize_interp_delete(PyInterpreterState *interp)
{
- if (_Py_IsMainInterpreter(tstate->interp)) {
+ if (_Py_IsMainInterpreter(interp)) {
/* Cleanup auto-thread-state */
- _PyGILState_Fini(tstate);
+ _PyGILState_Fini(interp);
}
/* We can't call _PyEval_FiniGIL() here because destroying the GIL lock can
created GIL, which ensures that Py_Initialize / Py_FinalizeEx can be
called multiple times. */
- PyInterpreterState_Delete(tstate->interp);
+ PyInterpreterState_Delete(interp);
}
* the threads created via Threading.
*/
- _PyAtExit_Call(tstate);
+ _PyAtExit_Call(tstate->interp);
/* Copy the core config, PyInterpreterState_Delete() free
the core config memory */
#endif /* Py_TRACE_REFS */
finalize_interp_clear(tstate);
- finalize_interp_delete(tstate);
+ finalize_interp_delete(tstate->interp);
#ifdef Py_TRACE_REFS
/* Display addresses (& refcnts) of all objects still alive.
// Wrap up existing "threading"-module-created, non-daemon threads.
wait_for_thread_shutdown(tstate);
- _PyAtExit_Call(tstate);
+ _PyAtExit_Call(tstate->interp);
if (tstate != interp->tstate_head || tstate->next != NULL) {
Py_FatalError("not the last thread");
finalize_modules(tstate);
finalize_interp_clear(tstate);
- finalize_interp_delete(tstate);
+ finalize_interp_delete(tstate->interp);
}
/* Add the __main__ module */
/* Last garbage collection on this interpreter */
_PyGC_CollectNoFail(tstate);
- _PyGC_Fini(tstate);
+ _PyGC_Fini(interp);
/* We don't clear sysdict and builtins until the end of this function.
Because clearing other attributes can execute arbitrary Python code
HEAD_UNLOCK(runtime);
Py_XDECREF(old_exc);
- _PyEval_SignalAsyncExc(tstate);
+ _PyEval_SignalAsyncExc(tstate->interp);
return 1;
}
HEAD_UNLOCK(runtime);
}
void
-_PyGILState_Fini(PyThreadState *tstate)
+_PyGILState_Fini(PyInterpreterState *interp)
{
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
+ struct _gilstate_runtime_state *gilstate = &interp->runtime->gilstate;
PyThread_tss_delete(&gilstate->autoTSSkey);
gilstate->autoInterpreterState = NULL;
}
}
static PyObject *
-_PySys_GetObject(PyThreadState *tstate, const char *name)
+_PySys_GetObject(PyInterpreterState *interp, const char *name)
{
- PyObject *sysdict = tstate->interp->sysdict;
+ PyObject *sysdict = interp->sysdict;
if (sysdict == NULL) {
return NULL;
}
PyObject *exc_type, *exc_value, *exc_tb;
_PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb);
- PyObject *value = _PySys_GetObject(tstate, name);
+ PyObject *value = _PySys_GetObject(tstate->interp, name);
/* XXX Suppress a new exception if it was raised and restore
* the old one. */
_PyErr_Restore(tstate, exc_type, exc_value, exc_tb);
}
static int
-sys_set_object(PyThreadState *tstate, PyObject *key, PyObject *v)
+sys_set_object(PyInterpreterState *interp, PyObject *key, PyObject *v)
{
if (key == NULL) {
return -1;
}
- PyObject *sd = tstate->interp->sysdict;
+ PyObject *sd = interp->sysdict;
if (v == NULL) {
v = _PyDict_Pop(sd, key, Py_None);
if (v == NULL) {
}
static int
-sys_set_object_id(PyThreadState *tstate, _Py_Identifier *key, PyObject *v)
+sys_set_object_id(PyInterpreterState *interp, _Py_Identifier *key, PyObject *v)
{
- return sys_set_object(tstate, _PyUnicode_FromId(key), v);
+ return sys_set_object(interp, _PyUnicode_FromId(key), v);
}
int
_PySys_SetObjectId(_Py_Identifier *key, PyObject *v)
{
- PyThreadState *tstate = _PyThreadState_GET();
- return sys_set_object_id(tstate, key, v);
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ return sys_set_object_id(interp, key, v);
}
static int
-sys_set_object_str(PyThreadState *tstate, const char *name, PyObject *v)
+sys_set_object_str(PyInterpreterState *interp, const char *name, PyObject *v)
{
PyObject *key = v ? PyUnicode_InternFromString(name)
: PyUnicode_FromString(name);
- int r = sys_set_object(tstate, key, v);
+ int r = sys_set_object(interp, key, v);
Py_XDECREF(key);
return r;
}
int
PySys_SetObject(const char *name, PyObject *v)
{
- PyThreadState *tstate = _PyThreadState_GET();
- return sys_set_object_str(tstate, name, v);
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ return sys_set_object_str(interp, name, v);
}
static int
-should_audit(PyInterpreterState *is)
+should_audit(PyInterpreterState *interp)
{
- /* tstate->interp cannot be NULL, but test it just in case
- for extra safety */
- assert(is != NULL);
- if (!is) {
+ /* interp must not be NULL, but test it just in case for extra safety */
+ assert(interp != NULL);
+ if (!interp) {
return 0;
}
- return (is->runtime->audit_hook_head
- || is->audit_hooks
+ return (interp->runtime->audit_hook_head
+ || interp->audit_hooks
|| PyDTrace_AUDIT_ENABLED());
}
return NULL;
}
- PyInterpreterState *is = tstate->interp;
- if (is->audit_hooks == NULL) {
- is->audit_hooks = PyList_New(0);
- if (is->audit_hooks == NULL) {
+ PyInterpreterState *interp = tstate->interp;
+ if (interp->audit_hooks == NULL) {
+ interp->audit_hooks = PyList_New(0);
+ if (interp->audit_hooks == NULL) {
return NULL;
}
}
- if (PyList_Append(is->audit_hooks, hook) < 0) {
+ if (PyList_Append(interp->audit_hooks, hook) < 0) {
return NULL;
}
sys_setdlopenflags_impl(PyObject *module, int new_val)
/*[clinic end generated code: output=ec918b7fe0a37281 input=4c838211e857a77f]*/
{
- PyThreadState *tstate = _PyThreadState_GET();
- tstate->interp->dlopenflags = new_val;
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ interp->dlopenflags = new_val;
Py_RETURN_NONE;
}
sys_getdlopenflags_impl(PyObject *module)
/*[clinic end generated code: output=e92cd1bc5005da6e input=dc4ea0899c53b4b6]*/
{
- PyThreadState *tstate = _PyThreadState_GET();
- return PyLong_FromLong(tstate->interp->dlopenflags);
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ return PyLong_FromLong(interp->dlopenflags);
}
#endif /* HAVE_DLOPEN */
if (warnoptions == NULL) {
return NULL;
}
- if (sys_set_object_id(tstate, &PyId_warnoptions, warnoptions)) {
+ if (sys_set_object_id(tstate->interp, &PyId_warnoptions, warnoptions)) {
Py_DECREF(warnoptions);
return NULL;
}
if (xoptions == NULL) {
return NULL;
}
- if (sys_set_object_id(tstate, &PyId__xoptions, xoptions)) {
+ if (sys_set_object_id(tstate->interp, &PyId__xoptions, xoptions)) {
Py_DECREF(xoptions);
return NULL;
}
};
static int
-set_flags_from_config(PyObject *flags, PyThreadState *tstate)
+set_flags_from_config(PyInterpreterState *interp, PyObject *flags)
{
- PyInterpreterState *interp = tstate->interp;
const PyPreConfig *preconfig = &interp->runtime->preconfig;
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
static PyObject*
-make_flags(PyThreadState *tstate)
+make_flags(PyInterpreterState *interp)
{
PyObject *flags = PyStructSequence_New(&FlagsType);
if (flags == NULL) {
return NULL;
}
- if (set_flags_from_config(flags, tstate) < 0) {
+ if (set_flags_from_config(interp, flags) < 0) {
Py_DECREF(flags);
return NULL;
}
goto type_init_failed;
}
}
- SET_SYS("flags", make_flags(tstate));
+ SET_SYS("flags", make_flags(tstate->interp));
/* prevent user from creating new instances */
FlagsType.tp_init = NULL;
FlagsType.tp_new = NULL;
int
_PySys_UpdateConfig(PyThreadState *tstate)
{
- PyObject *sysdict = tstate->interp->sysdict;
- const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp);
+ PyInterpreterState *interp = tstate->interp;
+ PyObject *sysdict = interp->sysdict;
+ const PyConfig *config = _PyInterpreterState_GetConfig(interp);
int res;
#define COPY_LIST(KEY, VALUE) \
#undef COPY_WSTR
// sys.flags
- PyObject *flags = _PySys_GetObject(tstate, "flags"); // borrowed ref
+ PyObject *flags = _PySys_GetObject(interp, "flags"); // borrowed ref
if (flags == NULL) {
return -1;
}
- if (set_flags_from_config(flags, tstate) < 0) {
+ if (set_flags_from_config(interp, flags) < 0) {
return -1;
}
PyObject *v;
if ((v = makepathobject(path, DELIM)) == NULL)
Py_FatalError("can't create sys.path");
- PyThreadState *tstate = _PyThreadState_GET();
- if (sys_set_object_id(tstate, &PyId_path, v) != 0) {
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (sys_set_object_id(interp, &PyId_path, v) != 0) {
Py_FatalError("can't assign sys.path");
}
Py_DECREF(v);
if (av == NULL) {
Py_FatalError("no mem for sys.argv");
}
- if (sys_set_object_str(tstate, "argv", av) != 0) {
+ if (sys_set_object_str(tstate->interp, "argv", av) != 0) {
Py_DECREF(av);
Py_FatalError("can't assign sys.argv");
}