mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-46008: Add _PyInterpreterState_Main(). (gh-29978)
PyInterpreterState_Main() is a plain function exposed in the public C-API. For internal usage we can take the more efficient approach in this PR. https://bugs.python.org/issue46008
This commit is contained in:
parent
1f384e3184
commit
758b74e71e
4 changed files with 13 additions and 9 deletions
|
@ -21,19 +21,23 @@ _Py_IsMainThread(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline PyInterpreterState *
|
||||||
|
_PyInterpreterState_Main(void)
|
||||||
|
{
|
||||||
|
return _PyRuntime.interpreters.main;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
_Py_IsMainInterpreter(PyInterpreterState *interp)
|
_Py_IsMainInterpreter(PyInterpreterState *interp)
|
||||||
{
|
{
|
||||||
/* Use directly _PyRuntime rather than tstate->interp->runtime, since
|
return (interp == _PyInterpreterState_Main());
|
||||||
this function is used in performance critical code path (ceval) */
|
|
||||||
return (interp == _PyRuntime.interpreters.main);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline const PyConfig *
|
static inline const PyConfig *
|
||||||
_Py_GetMainConfig(void)
|
_Py_GetMainConfig(void)
|
||||||
{
|
{
|
||||||
PyInterpreterState *interp = _PyRuntime.interpreters.main;
|
PyInterpreterState *interp = _PyInterpreterState_Main();
|
||||||
if (interp == NULL) {
|
if (interp == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +49,7 @@ _Py_GetMainConfig(void)
|
||||||
static inline int
|
static inline int
|
||||||
_Py_ThreadCanHandleSignals(PyInterpreterState *interp)
|
_Py_ThreadCanHandleSignals(PyInterpreterState *interp)
|
||||||
{
|
{
|
||||||
return (_Py_IsMainThread() && interp == _PyRuntime.interpreters.main);
|
return (_Py_IsMainThread() && _Py_IsMainInterpreter(interp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6696,7 +6696,7 @@ os_fork1_impl(PyObject *module)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (_PyInterpreterState_GET() != PyInterpreterState_Main()) {
|
if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
|
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -7348,7 +7348,7 @@ os_forkpty_impl(PyObject *module)
|
||||||
int master_fd = -1;
|
int master_fd = -1;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (_PyInterpreterState_GET() != PyInterpreterState_Main()) {
|
if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
|
PyErr_SetString(PyExc_RuntimeError, "fork not supported for subinterpreters");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1953,7 +1953,7 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* No current thread state, copy from the main interpreter */
|
/* No current thread state, copy from the main interpreter */
|
||||||
PyInterpreterState *main_interp = PyInterpreterState_Main();
|
PyInterpreterState *main_interp = _PyInterpreterState_Main();
|
||||||
config = _PyInterpreterState_GetConfig(main_interp);
|
config = _PyInterpreterState_GetConfig(main_interp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1204,7 +1204,7 @@ PyInterpreterState_Head(void)
|
||||||
PyInterpreterState *
|
PyInterpreterState *
|
||||||
PyInterpreterState_Main(void)
|
PyInterpreterState_Main(void)
|
||||||
{
|
{
|
||||||
return _PyRuntime.interpreters.main;
|
return _PyInterpreterState_Main();
|
||||||
}
|
}
|
||||||
|
|
||||||
PyInterpreterState *
|
PyInterpreterState *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue