https://github.com/python/cpython/commit/0453e494b6e23c876c1bb097966f2c68ec72fada
commit: 0453e494b6e23c876c1bb097966f2c68ec72fada
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-03-17T12:31:55+01:00
summary:
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()
files:
M Include/internal/pycore_pystate.h
M Python/pystate.c
diff --git a/Include/internal/pycore_pystate.h
b/Include/internal/pycore_pystate.h
index d4867a7b96bfeb..4c873a44e3e124 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -51,19 +51,10 @@ extern "C" {
/* Check if the current thread is the main thread.
Use _Py_IsMainInterpreter() to check if it's the main interpreter. */
-static inline int
-_Py_IsMainThread(void)
-{
- unsigned long thread = PyThread_get_thread_ident();
- return (thread == _PyRuntime.main_thread);
-}
-
+extern int _Py_IsMainThread(void);
-static inline PyInterpreterState *
-_PyInterpreterState_Main(void)
-{
- return _PyRuntime.interpreters.main;
-}
+// Export for '_testinternalcapi' shared extension
+PyAPI_FUNC(PyInterpreterState*) _PyInterpreterState_Main(void);
static inline int
_Py_IsMainInterpreter(PyInterpreterState *interp)
@@ -71,16 +62,7 @@ _Py_IsMainInterpreter(PyInterpreterState *interp)
return (interp == _PyInterpreterState_Main());
}
-static inline 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);
-}
+extern int _Py_IsMainInterpreterFinalizing(PyInterpreterState *interp);
// Export for _interpreters module.
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
@@ -93,17 +75,7 @@ PyAPI_FUNC(void) _PyErr_SetInterpreterAlreadyRunning(void);
extern int _PyThreadState_IsRunningMain(PyThreadState *);
extern void _PyInterpreterState_ReinitRunningMain(PyThreadState *);
-
-
-static inline const PyConfig *
-_Py_GetMainConfig(void)
-{
- PyInterpreterState *interp = _PyInterpreterState_Main();
- if (interp == NULL) {
- return NULL;
- }
- return _PyInterpreterState_GetConfig(interp);
-}
+extern const PyConfig* _Py_GetMainConfig(void);
/* Only handle signals on the main thread of the main interpreter. */
diff --git a/Python/pystate.c b/Python/pystate.c
index 99f8774d446986..68a7426a2601d3 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);
+}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]