diff options
author | Victor Stinner <vstinner@python.org> | 2021-02-19 14:10:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-19 14:10:45 (GMT) |
commit | bcb094b41f7fe4dd1686c50891d85632fcf0d481 (patch) | |
tree | 72ae3916ace264f291a89f288ff199a36ead54f4 /Objects | |
parent | a486054b24658fa623e030ddd4cc0cbfcac54ab0 (diff) | |
download | cpython-bcb094b41f7fe4dd1686c50891d85632fcf0d481.zip cpython-bcb094b41f7fe4dd1686c50891d85632fcf0d481.tar.gz cpython-bcb094b41f7fe4dd1686c50891d85632fcf0d481.tar.bz2 |
bpo-43268: Pass interp rather than tstate to internal functions (GH-24580)
Pass the current interpreter (interp) rather than the current Python
thread state (tstate) to internal functions which only use the
interpreter.
Modified functions:
* _PyXXX_Fini() and _PyXXX_ClearFreeList() functions
* _PyEval_SignalAsyncExc(), make_pending_calls()
* _PySys_GetObject(), sys_set_object(), sys_set_object_id(), sys_set_object_str()
* should_audit(), set_flags_from_config(), make_flags()
* _PyAtExit_Call()
* init_stdio_encoding()
* etc.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytesobject.c | 8 | ||||
-rw-r--r-- | Objects/dictobject.c | 10 | ||||
-rw-r--r-- | Objects/exceptions.c | 8 | ||||
-rw-r--r-- | Objects/floatobject.c | 10 | ||||
-rw-r--r-- | Objects/frameobject.c | 10 | ||||
-rw-r--r-- | Objects/genobject.c | 10 | ||||
-rw-r--r-- | Objects/listobject.c | 10 | ||||
-rw-r--r-- | Objects/longobject.c | 10 | ||||
-rw-r--r-- | Objects/sliceobject.c | 3 | ||||
-rw-r--r-- | Objects/tupleobject.c | 14 | ||||
-rw-r--r-- | Objects/typeobject.c | 6 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 20 |
12 files changed, 59 insertions, 60 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index ccabbdc..5814e8a 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3063,9 +3063,9 @@ error: 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(); } @@ -3074,9 +3074,9 @@ _PyBytes_Init(PyThreadState *tstate) 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]); } diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 35e881f..9b5898d 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -260,9 +260,9 @@ get_dict_state(void) 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)); @@ -275,11 +275,11 @@ _PyDict_ClearFreeList(PyThreadState *tstate) 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 diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 62cec9a..88e2287 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -2529,9 +2529,9 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning, #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)) { \ @@ -2766,9 +2766,9 @@ _PyBuiltins_AddExceptions(PyObject *bltinmod) } 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); } diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 34fb57a..fdeb189 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -2026,9 +2026,9 @@ _PyFloat_Init(void) } 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); @@ -2040,11 +2040,11 @@ _PyFloat_ClearFreeList(PyThreadState *tstate) } 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 } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 5f7fa40..0571bfe 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -1109,9 +1109,9 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) /* 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; @@ -1122,11 +1122,11 @@ _PyFrame_ClearFreeList(PyThreadState *tstate) } 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 } diff --git a/Objects/genobject.c b/Objects/genobject.c index bde92b4..26e27cc 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1489,9 +1489,9 @@ PyAsyncGen_New(PyFrameObject *f, PyObject *name, PyObject *qualname) 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; @@ -1509,11 +1509,11 @@ _PyAsyncGen_ClearFreeLists(PyThreadState *tstate) } 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 diff --git a/Objects/listobject.c b/Objects/listobject.c index ca9df59..415f9a2 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -106,9 +106,9 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size) } 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)); @@ -117,11 +117,11 @@ _PyList_ClearFreeList(PyThreadState *tstate) } 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 } diff --git a/Objects/longobject.c b/Objects/longobject.c index c0b4ce0..02b3603 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -5702,7 +5702,7 @@ PyLong_GetInfo(void) } int -_PyLong_Init(PyThreadState *tstate) +_PyLong_Init(PyInterpreterState *interp) { for (Py_ssize_t i=0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) { sdigit ival = (sdigit)i - NSMALLNEGINTS; @@ -5716,10 +5716,10 @@ _PyLong_Init(PyThreadState *tstate) 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) { @@ -5732,9 +5732,9 @@ _PyLong_Init(PyThreadState *tstate) } 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]); } } diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 02ba033..22fb7c6 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -97,9 +97,8 @@ PyObject _Py_EllipsisObject = { /* 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; diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 41677d7..becdf70 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1007,10 +1007,10 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize) } 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; @@ -1027,9 +1027,9 @@ _PyTuple_ClearFreeList(PyThreadState *tstate) 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(); } @@ -1038,14 +1038,14 @@ _PyTuple_Init(PyThreadState *tstate) 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 diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 9dbb7be..33a7872 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -283,10 +283,10 @@ PyType_ClearCache(void) 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(); } } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 498f393..5e1b6b0 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15682,7 +15682,7 @@ PyTypeObject PyUnicode_Type = { /* Initialize the Unicode implementation */ PyStatus -_PyUnicode_Init(PyThreadState *tstate) +_PyUnicode_Init(PyInterpreterState *interp) { /* XXX - move this array to unicodectype.c ? */ const Py_UCS2 linebreak[] = { @@ -15696,12 +15696,12 @@ _PyUnicode_Init(PyThreadState *tstate) 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, @@ -15813,9 +15813,9 @@ PyUnicode_InternFromString(const char *cp) 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; } @@ -16093,10 +16093,10 @@ error: 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"); @@ -16189,7 +16189,7 @@ _PyUnicode_InitEncodings(PyThreadState *tstate) return status; } - return init_stdio_encoding(tstate); + return init_stdio_encoding(tstate->interp); } @@ -16233,9 +16233,9 @@ _PyUnicode_EnableLegacyWindowsFSEncoding(void) 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); |