Commit b45d259b authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-36710: Use tstate in pylifecycle.c (GH-14249)

In pylifecycle.c: pass tstate argument, rather than interp argument,
to functions.
parent 35068bd0
......@@ -21,7 +21,7 @@ extern int _Py_SetFileSystemEncoding(
const char *encoding,
const char *errors);
extern void _Py_ClearFileSystemEncoding(void);
extern PyStatus _PyUnicode_InitEncodings(PyInterpreterState *interp);
extern PyStatus _PyUnicode_InitEncodings(PyThreadState *tstate);
#ifdef MS_WINDOWS
extern int _PyUnicode_EnableLegacyWindowsFSEncoding(void);
#endif
......@@ -37,20 +37,20 @@ extern int _PyStructSequence_Init(void);
extern int _PyLong_Init(void);
extern PyStatus _PyFaulthandler_Init(int enable);
extern int _PyTraceMalloc_Init(int enable);
extern PyObject * _PyBuiltin_Init(void);
extern PyObject * _PyBuiltin_Init(PyThreadState *tstate);
extern PyStatus _PySys_Create(
_PyRuntimeState *runtime,
PyInterpreterState *interp,
PyThreadState *tstate,
PyObject **sysmod_p);
extern PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict);
extern int _PySys_InitMain(
_PyRuntimeState *runtime,
PyThreadState *tstate);
extern PyStatus _PyImport_Init(PyInterpreterState *interp);
extern PyStatus _PyImport_Init(PyThreadState *tstate);
extern PyStatus _PyExc_Init(void);
extern PyStatus _PyErr_Init(void);
extern PyStatus _PyBuiltins_AddExceptions(PyObject * bltinmod);
extern PyStatus _PyImportHooks_Init(void);
extern PyStatus _PyImportHooks_Init(PyThreadState *tstate);
extern int _PyFloat_Init(void);
extern PyStatus _Py_HashRandomization_Init(const PyConfig *);
......@@ -88,7 +88,6 @@ extern void _PyWarnings_Fini(PyInterpreterState *interp);
extern void _PyGILState_Init(
_PyRuntimeState *runtime,
PyInterpreterState *interp,
PyThreadState *tstate);
extern void _PyGILState_Fini(_PyRuntimeState *runtime);
......
......@@ -310,7 +310,7 @@ PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap(
PyAPI_FUNC(PyStatus) _PyInterpreterState_Enable(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime);
/* Used by PyImport_Cleanup() */
/* Used by _PyImport_Cleanup() */
extern void _PyInterpreterState_ClearModules(PyInterpreterState *interp);
PyAPI_FUNC(void) _PyGILState_Reinit(_PyRuntimeState *runtime);
......
......@@ -15792,8 +15792,10 @@ init_fs_encoding(PyInterpreterState *interp)
PyStatus
_PyUnicode_InitEncodings(PyInterpreterState *interp)
_PyUnicode_InitEncodings(PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
PyStatus status = init_fs_encoding(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
......
......@@ -2769,11 +2769,11 @@ static struct PyModuleDef builtinsmodule = {
PyObject *
_PyBuiltin_Init(void)
_PyBuiltin_Init(PyThreadState *tstate)
{
PyObject *mod, *dict, *debug;
const PyConfig *config = &_PyInterpreterState_GET_UNSAFE()->config;
const PyConfig *config = &tstate->interp->config;
if (PyType_Ready(&PyFilter_Type) < 0 ||
PyType_Ready(&PyMap_Type) < 0 ||
......
......@@ -48,8 +48,9 @@ module _imp
/* Initialize things */
PyStatus
_PyImport_Init(PyInterpreterState *interp)
_PyImport_Init(PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
interp->builtins_copy = PyDict_Copy(interp->builtins);
if (interp->builtins_copy == NULL) {
return _PyStatus_ERR("Can't backup builtins dict");
......@@ -58,7 +59,7 @@ _PyImport_Init(PyInterpreterState *interp)
}
PyStatus
_PyImportHooks_Init(void)
_PyImportHooks_Init(PyThreadState *tstate)
{
PyObject *v, *path_hooks = NULL;
int err = 0;
......@@ -89,7 +90,7 @@ _PyImportHooks_Init(void)
return _PyStatus_OK();
error:
PyErr_Print();
_PyErr_Print(tstate);
return _PyStatus_ERR("initializing sys.meta_path, sys.path_hooks, "
"or path_importer_cache failed");
}
......@@ -554,7 +555,7 @@ _PyImport_Cleanup(PyThreadState *tstate)
}
Py_XDECREF(dict);
/* Clear module dict copies stored in the interpreter state */
_PyInterpreterState_ClearModules(tstate->interp);
_PyInterpreterState_ClearModules(interp);
/* Collect references */
_PyGC_CollectNoFail();
/* Dump GC stats before it's too late, since it uses the warnings
......
This diff is collapsed.
......@@ -1143,19 +1143,18 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
Py_Initialize/Py_FinalizeEx
*/
void
_PyGILState_Init(_PyRuntimeState *runtime,
PyInterpreterState *interp, PyThreadState *tstate)
_PyGILState_Init(_PyRuntimeState *runtime, PyThreadState *tstate)
{
/* must init with valid states */
assert(interp != NULL);
assert(tstate != NULL);
assert(tstate->interp != NULL);
struct _gilstate_runtime_state *gilstate = &runtime->gilstate;
if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) {
Py_FatalError("Could not allocate TSS entry");
}
gilstate->autoInterpreterState = interp;
gilstate->autoInterpreterState = tstate->interp;
assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL);
assert(tstate->gilstate_counter == 0);
......
......@@ -3036,10 +3036,10 @@ error:
/* Create sys module without all attributes: _PySys_InitMain() should be called
later to add remaining attributes. */
PyStatus
_PySys_Create(_PyRuntimeState *runtime, PyInterpreterState *interp,
_PySys_Create(_PyRuntimeState *runtime, PyThreadState *tstate,
PyObject **sysmod_p)
{
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
PyInterpreterState *interp = tstate->interp;
PyObject *modules = PyDict_New();
if (modules == NULL) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment