Skip to content

Commit 838f264

Browse files
authored
bpo-36710: Pass explicitly tstate in sysmodule.c (GH-14060)
* Replace global var Py_VerboseFlag with interp->config.verbose. * Add _PyErr_NoMemory(tstate) function. * Add tstate parameter to _PyEval_SetCoroutineOriginTrackingDepth() and move the function to the internal API. * Replace _PySys_InitMain(runtime, interp) with _PySys_InitMain(runtime, tstate).
1 parent 3498c64 commit 838f264

File tree

8 files changed

+262
-178
lines changed

8 files changed

+262
-178
lines changed

Include/ceval.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ PyAPI_FUNC(PyObject *) PyEval_CallMethod(PyObject *obj,
3131
#ifndef Py_LIMITED_API
3232
PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
3333
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
34-
PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(int new_depth);
3534
PyAPI_FUNC(int) _PyEval_GetCoroutineOriginTrackingDepth(void);
3635
PyAPI_FUNC(void) _PyEval_SetAsyncGenFirstiter(PyObject *);
3736
PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFirstiter(void);

Include/internal/pycore_ceval.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ PyAPI_FUNC(void) _PyEval_SignalAsyncExc(
2727
struct _ceval_runtime_state *ceval);
2828
PyAPI_FUNC(void) _PyEval_ReInitThreads(
2929
_PyRuntimeState *runtime);
30+
PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
31+
PyThreadState *tstate,
32+
int new_depth);
3033

3134
/* Private function */
3235
void _PyEval_Fini(void);

Include/internal/pycore_pyerrors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);
3939

4040
PyAPI_FUNC(void) _PyErr_SetNone(PyThreadState *tstate, PyObject *exception);
4141

42+
PyAPI_FUNC(PyObject *) _PyErr_NoMemory(PyThreadState *tstate);
43+
4244
PyAPI_FUNC(void) _PyErr_SetString(
4345
PyThreadState *tstate,
4446
PyObject *exception,

Include/internal/pycore_pylifecycle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern PyStatus _PySys_Create(
4545
extern PyStatus _PySys_SetPreliminaryStderr(PyObject *sysdict);
4646
extern int _PySys_InitMain(
4747
_PyRuntimeState *runtime,
48-
PyInterpreterState *interp);
48+
PyThreadState *tstate);
4949
extern PyStatus _PyImport_Init(PyInterpreterState *interp);
5050
extern PyStatus _PyExc_Init(void);
5151
extern PyStatus _PyErr_Init(void);

Python/ceval.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,10 +4728,9 @@ PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
47284728
}
47294729

47304730
void
4731-
_PyEval_SetCoroutineOriginTrackingDepth(int new_depth)
4731+
_PyEval_SetCoroutineOriginTrackingDepth(PyThreadState *tstate, int new_depth)
47324732
{
47334733
assert(new_depth >= 0);
4734-
PyThreadState *tstate = _PyThreadState_GET();
47354734
tstate->coroutine_origin_tracking_depth = new_depth;
47364735
}
47374736

Python/errors.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,8 @@ PyErr_BadArgument(void)
547547
}
548548

549549
PyObject *
550-
PyErr_NoMemory(void)
550+
_PyErr_NoMemory(PyThreadState *tstate)
551551
{
552-
PyThreadState *tstate = _PyThreadState_GET();
553552
if (Py_TYPE(PyExc_MemoryError) == NULL) {
554553
/* PyErr_NoMemory() has been called before PyExc_MemoryError has been
555554
initialized by _PyExc_Init() */
@@ -560,6 +559,13 @@ PyErr_NoMemory(void)
560559
return NULL;
561560
}
562561

562+
PyObject *
563+
PyErr_NoMemory(void)
564+
{
565+
PyThreadState *tstate = _PyThreadState_GET();
566+
return _PyErr_NoMemory(tstate);
567+
}
568+
563569
PyObject *
564570
PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
565571
{

Python/pylifecycle.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ pyinit_main(_PyRuntimeState *runtime, PyInterpreterState *interp)
899899
}
900900

901901
/* Configure the main interpreter */
902+
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
902903
PyConfig *config = &interp->config;
903904

904905
if (runtime->initialized) {
@@ -919,7 +920,7 @@ pyinit_main(_PyRuntimeState *runtime, PyInterpreterState *interp)
919920
return _PyStatus_ERR("can't initialize time");
920921
}
921922

922-
if (_PySys_InitMain(runtime, interp) < 0) {
923+
if (_PySys_InitMain(runtime, tstate) < 0) {
923924
return _PyStatus_ERR("can't finish initializing sys");
924925
}
925926

@@ -1456,7 +1457,7 @@ new_interpreter(PyThreadState **tstate_p)
14561457
}
14571458
Py_INCREF(interp->sysdict);
14581459
PyDict_SetItemString(interp->sysdict, "modules", modules);
1459-
if (_PySys_InitMain(runtime, interp) < 0) {
1460+
if (_PySys_InitMain(runtime, tstate) < 0) {
14601461
return _PyStatus_ERR("can't finish initializing sys");
14611462
}
14621463
}

0 commit comments

Comments
 (0)