Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bpo-36710: Use tstate in pylifecycle.c (GH-14249)
In pylifecycle.c: pass tstate argument, rather than interp argument,
to functions.
  • Loading branch information
vstinner committed Jun 19, 2019
1 parent 35068bd commit b45d259
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 108 deletions.
11 changes: 5 additions & 6 deletions Include/internal/pycore_pylifecycle.h
Expand Up @@ -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
Expand All @@ -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 *);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_pystate.h
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion Objects/unicodeobject.c
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Python/bltinmodule.c
Expand Up @@ -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 ||
Expand Down
9 changes: 5 additions & 4 deletions Python/import.c
Expand Up @@ -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");
Expand All @@ -58,7 +59,7 @@ _PyImport_Init(PyInterpreterState *interp)
}

PyStatus
_PyImportHooks_Init(void)
_PyImportHooks_Init(PyThreadState *tstate)
{
PyObject *v, *path_hooks = NULL;
int err = 0;
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b45d259

Please sign in to comment.