mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
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()
This commit is contained in:
parent
80e00ecc39
commit
0453e494b6
2 changed files with 43 additions and 33 deletions
|
@ -51,19 +51,10 @@ extern "C" {
|
||||||
|
|
||||||
/* Check if the current thread is the main thread.
|
/* Check if the current thread is the main thread.
|
||||||
Use _Py_IsMainInterpreter() to check if it's the main interpreter. */
|
Use _Py_IsMainInterpreter() to check if it's the main interpreter. */
|
||||||
static inline int
|
extern int _Py_IsMainThread(void);
|
||||||
_Py_IsMainThread(void)
|
|
||||||
{
|
|
||||||
unsigned long thread = PyThread_get_thread_ident();
|
|
||||||
return (thread == _PyRuntime.main_thread);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Export for '_testinternalcapi' shared extension
|
||||||
static inline PyInterpreterState *
|
PyAPI_FUNC(PyInterpreterState*) _PyInterpreterState_Main(void);
|
||||||
_PyInterpreterState_Main(void)
|
|
||||||
{
|
|
||||||
return _PyRuntime.interpreters.main;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
_Py_IsMainInterpreter(PyInterpreterState *interp)
|
_Py_IsMainInterpreter(PyInterpreterState *interp)
|
||||||
|
@ -71,16 +62,7 @@ _Py_IsMainInterpreter(PyInterpreterState *interp)
|
||||||
return (interp == _PyInterpreterState_Main());
|
return (interp == _PyInterpreterState_Main());
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
extern int _Py_IsMainInterpreterFinalizing(PyInterpreterState *interp);
|
||||||
_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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Export for _interpreters module.
|
// Export for _interpreters module.
|
||||||
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
|
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
|
||||||
|
@ -93,17 +75,7 @@ PyAPI_FUNC(void) _PyErr_SetInterpreterAlreadyRunning(void);
|
||||||
|
|
||||||
extern int _PyThreadState_IsRunningMain(PyThreadState *);
|
extern int _PyThreadState_IsRunningMain(PyThreadState *);
|
||||||
extern void _PyInterpreterState_ReinitRunningMain(PyThreadState *);
|
extern void _PyInterpreterState_ReinitRunningMain(PyThreadState *);
|
||||||
|
extern const PyConfig* _Py_GetMainConfig(void);
|
||||||
|
|
||||||
static inline const PyConfig *
|
|
||||||
_Py_GetMainConfig(void)
|
|
||||||
{
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_Main();
|
|
||||||
if (interp == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return _PyInterpreterState_GetConfig(interp);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Only handle signals on the main thread of the main interpreter. */
|
/* Only handle signals on the main thread of the main interpreter. */
|
||||||
|
|
|
@ -3137,3 +3137,41 @@ _PyThreadState_ClearMimallocHeaps(PyThreadState *tstate)
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue