aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2025-03-17 12:31:55 +0100
committerGitHub <noreply@github.com>2025-03-17 12:31:55 +0100
commit0453e494b6e23c876c1bb097966f2c68ec72fada (patch)
treef6b2bfa25cd3fc35275fa203caa4530fa1371897 /Python/pystate.c
parent80e00ecc399db8aeaa9f3a1c87a2cfb34517d7be (diff)
downloadcpython-0453e494b6e23c876c1bb097966f2c68ec72fada.tar.gz
cpython-0453e494b6e23c876c1bb097966f2c68ec72fada.zip
gh-131238: Convert pycore_pystate.h static inline to functions (#131352)
Convert static inline functions to functions: * _Py_IsMainThread() * _PyInterpreterState_Main() * _Py_IsMainInterpreterFinalizing() * _Py_GetMainConfig()
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 99f8774d446..68a7426a260 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -3137,3 +3137,41 @@ _PyThreadState_ClearMimallocHeaps(PyThreadState *tstate)
}
#endif
}
+
+
+int
+_Py_IsMainThread(void)
+{
+ unsigned long thread = PyThread_get_thread_ident();
+ return (thread == _PyRuntime.main_thread);
+}
+
+
+PyInterpreterState *
+_PyInterpreterState_Main(void)
+{
+ return _PyRuntime.interpreters.main;
+}
+
+
+int
+_Py_IsMainInterpreterFinalizing(PyInterpreterState *interp)
+{
+ /* bpo-39877: Access _PyRuntime directly rather than using
+ tstate->interp->runtime to support calls from Python daemon threads.
+ After Py_Finalize() has been called, tstate can be a dangling pointer:
+ point to PyThreadState freed memory. */
+ return (_PyRuntimeState_GetFinalizing(&_PyRuntime) != NULL &&
+ interp == &_PyRuntime._main_interpreter);
+}
+
+
+const PyConfig *
+_Py_GetMainConfig(void)
+{
+ PyInterpreterState *interp = _PyInterpreterState_Main();
+ if (interp == NULL) {
+ return NULL;
+ }
+ return _PyInterpreterState_GetConfig(interp);
+}