]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103323: Remove PyRuntimeState_GetThreadState() (#104171)
authorVictor Stinner <vstinner@python.org>
Thu, 4 May 2023 14:21:01 +0000 (16:21 +0200)
committerGitHub <noreply@github.com>
Thu, 4 May 2023 14:21:01 +0000 (16:21 +0200)
This function no longer makes sense, since its runtime parameter is
no longer used. Use directly _PyThreadState_GET() and
_PyInterpreterState_GET() instead.

Include/internal/pycore_pystate.h
Python/ceval_gil.c
Python/pylifecycle.c
Python/pystate.c
Python/sysmodule.c

index 180ea676bc22eb1b1adda3b3729a58ddebc1809f..daa40cf4bcd855452d6af06742cac83b45107cd3 100644 (file)
@@ -68,7 +68,7 @@ _Py_ThreadCanHandlePendingCalls(void)
 }
 
 
-/* Variable and macro for in-line access to current thread
+/* Variable and static inline functions for in-line access to current thread
    and interpreter state */
 
 #if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)
@@ -93,12 +93,6 @@ _PyThreadState_GET(void)
 #endif
 }
 
-static inline PyThreadState*
-_PyRuntimeState_GetThreadState(_PyRuntimeState *Py_UNUSED(runtime))
-{
-    return _PyThreadState_GET();
-}
-
 
 static inline void
 _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
@@ -118,7 +112,7 @@ _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
 
 /* Get the current interpreter state.
 
-   The macro is unsafe: it does not check for error and it can return NULL.
+   The function is unsafe: it does not check for error and it can return NULL.
 
    The caller must hold the GIL.
 
index 29796be4b80e9311785766a961a608461d6efbba..4d501c8966174322f44f7c569a73c1ee3bcdbd8e 100644 (file)
@@ -546,8 +546,7 @@ _PyEval_Fini(void)
 void
 PyEval_AcquireLock(void)
 {
-    _PyRuntimeState *runtime = &_PyRuntime;
-    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+    PyThreadState *tstate = _PyThreadState_GET();
     _Py_EnsureTstateNotNULL(tstate);
 
     take_gil(tstate);
@@ -557,7 +556,7 @@ void
 PyEval_ReleaseLock(void)
 {
     _PyRuntimeState *runtime = &_PyRuntime;
-    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+    PyThreadState *tstate = _PyThreadState_GET();
     /* This function must succeed when the current thread state is NULL.
        We therefore avoid PyThreadState_Get() which dumps a fatal error
        in debug mode. */
index b9add89b9c6c52bb4a2b7603e9219b6fa47ddb01..97957d3f17e6dbdf5dc931bd1c03290a35425984 100644 (file)
@@ -1303,8 +1303,7 @@ _Py_InitializeMain(void)
     if (_PyStatus_EXCEPTION(status)) {
         return status;
     }
-    _PyRuntimeState *runtime = &_PyRuntime;
-    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+    PyThreadState *tstate = _PyThreadState_GET();
     return pyinit_main(tstate);
 }
 
@@ -1755,7 +1754,7 @@ Py_FinalizeEx(void)
     }
 
     /* Get current thread state and interpreter pointer */
-    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+    PyThreadState *tstate = _PyThreadState_GET();
     // XXX assert(_Py_IsMainInterpreter(tstate->interp));
     // XXX assert(_Py_IsMainThread());
 
@@ -2800,7 +2799,7 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
 
        tss_tstate != tstate if the current Python thread does not hold the GIL.
        */
-    PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+    PyThreadState *tstate = _PyThreadState_GET();
     PyInterpreterState *interp = NULL;
     PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
     if (tstate != NULL) {
index f103a059f0f3696d24a7a7d80887c75eceefc5f8..f09d37657f9c27d2e8908a7f3050b876db108d0c 100644 (file)
@@ -1809,7 +1809,7 @@ int
 PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
 {
     _PyRuntimeState *runtime = &_PyRuntime;
-    PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
+    PyInterpreterState *interp = _PyInterpreterState_GET();
 
     /* Although the GIL is held, a few C API functions can be called
      * without the GIL held, and in particular some that create and
index 781588b0df4eadde884e07960b699a53cece810f..894a3e8a98fd8a29e0a0df9bbbfb9e9bd6c16575 100644 (file)
@@ -365,7 +365,7 @@ PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
     _PyRuntimeState *runtime = &_PyRuntime;
     PyThreadState *tstate;
     if (runtime->initialized) {
-        tstate = _PyRuntimeState_GetThreadState(runtime);
+        tstate = _PyThreadState_GET();
     }
     else {
         tstate = NULL;