]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
PyOS_AfterFork_Child() pass tstate to _PyEval_ReInitThreads() (GH-20598)
authorVictor Stinner <vstinner@python.org>
Tue, 2 Jun 2020 16:44:54 +0000 (18:44 +0200)
committerGitHub <noreply@github.com>
Tue, 2 Jun 2020 16:44:54 +0000 (18:44 +0200)
Include/internal/pycore_ceval.h
Modules/posixmodule.c
Python/ceval.c

index 2da0154525b1ce9132d294665e6d10c90fb3a138..aafb533b57d5f048c1ba15adcbb15e99a9bf8423 100644 (file)
@@ -25,7 +25,7 @@ PyAPI_FUNC(int) _PyEval_AddPendingCall(
     void *arg);
 PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyThreadState *tstate);
 #ifdef HAVE_FORK
-extern PyStatus _PyEval_ReInitThreads(struct pyruntimestate *runtime);
+extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
 #endif
 PyAPI_FUNC(void) _PyEval_SetCoroutineOriginTrackingDepth(
     PyThreadState *tstate,
index afb6d183077a1f4fd17acbfa45b709d2ec9cfe0c..79779bfdeafd3ad9f5f3512da75f9b4b8b4a6b32 100644 (file)
@@ -470,7 +470,10 @@ PyOS_AfterFork_Child(void)
         goto fatal_error;
     }
 
-    status = _PyEval_ReInitThreads(runtime);
+    PyThreadState *tstate = _PyThreadState_GET();
+    _Py_EnsureTstateNotNULL(tstate);
+
+    status = _PyEval_ReInitThreads(tstate);
     if (_PyStatus_EXCEPTION(status)) {
         goto fatal_error;
     }
@@ -491,8 +494,9 @@ PyOS_AfterFork_Child(void)
     if (_PyStatus_EXCEPTION(status)) {
         goto fatal_error;
     }
+    assert(_PyThreadState_GET() == tstate);
 
-    run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);
+    run_at_forkers(tstate->interp->after_forkers_child, 0);
     return;
 
 fatal_error:
index 5edcfe354054a62240cd64c064d0d39e3351125c..9ab8329d6d8e7ade1d0c65cd5749599aad06464e 100644 (file)
@@ -436,10 +436,9 @@ PyEval_ReleaseThread(PyThreadState *tstate)
    which are not running in the child process, and clear internal locks
    which might be held by those threads. */
 PyStatus
-_PyEval_ReInitThreads(_PyRuntimeState *runtime)
+_PyEval_ReInitThreads(PyThreadState *tstate)
 {
-    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
-    _Py_EnsureTstateNotNULL(tstate);
+    _PyRuntimeState *runtime = tstate->interp->runtime;
 
 #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
     struct _gil_runtime_state *gil = &tstate->interp->ceval.gil;