gh-106320: Use _PyInterpreterState_GET() (#106336)

Replace PyInterpreterState_Get() with inlined
_PyInterpreterState_GET().
This commit is contained in:
Victor Stinner 2023-07-02 18:37:37 +02:00 committed by GitHub
parent 9a51a41961
commit bc7eb17084
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 35 deletions

View file

@ -527,7 +527,7 @@ future_init(FutureObj *fut, PyObject *loop)
if (is_true < 0) {
return -1;
}
if (is_true && !_Py_IsInterpreterFinalizing(PyInterpreterState_Get())) {
if (is_true && !_Py_IsInterpreterFinalizing(_PyInterpreterState_GET())) {
/* Only try to capture the traceback if the interpreter is not being
finalized. The original motivation to add a `_Py_IsFinalizing()`
call was to prevent SIGSEGV when a Future is created in a __del__

View file

@ -292,7 +292,7 @@ _enter_buffered_busy(buffered *self)
"reentrant call inside %R", self);
return 0;
}
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
relax_locking = _Py_IsInterpreterFinalizing(interp);
Py_BEGIN_ALLOW_THREADS
if (!relax_locking)

View file

@ -1025,7 +1025,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
int *c_fds_to_keep = NULL;
Py_ssize_t fds_to_keep_len = PyTuple_GET_SIZE(py_fds_to_keep);
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if ((preexec_fn != Py_None) && interp->finalizing) {
PyErr_SetString(PyExc_RuntimeError,
"preexec_fn not supported at interpreter shutdown");

View file

@ -559,7 +559,7 @@ static PyObject *
set_eval_frame_default(PyObject *self, PyObject *Py_UNUSED(args))
{
module_state *state = get_module_state(self);
_PyInterpreterState_SetEvalFrameFunc(PyInterpreterState_Get(), _PyEval_EvalFrameDefault);
_PyInterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(), _PyEval_EvalFrameDefault);
Py_CLEAR(state->record_list);
Py_RETURN_NONE;
}
@ -587,7 +587,7 @@ set_eval_frame_record(PyObject *self, PyObject *list)
return NULL;
}
Py_XSETREF(state->record_list, Py_NewRef(list));
_PyInterpreterState_SetEvalFrameFunc(PyInterpreterState_Get(), record_eval);
_PyInterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(), record_eval);
Py_RETURN_NONE;
}
@ -883,7 +883,7 @@ pending_threadfunc(PyObject *self, PyObject *args, PyObject *kwargs)
{
return NULL;
}
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
/* create the reference for the callbackwhile we hold the lock */
Py_INCREF(callable);

View file

@ -5,8 +5,9 @@
#endif
#include "Python.h"
#include "internal/pycore_interp.h"
#include "internal/pycore_typevarobject.h"
#include "pycore_interp.h"
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_typevarobject.h"
#include "clinic/_typingmodule.c.h"
/*[clinic input]
@ -44,7 +45,7 @@ PyDoc_STRVAR(typing_doc,
static int
_typing_exec(PyObject *m)
{
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
#define EXPORT_TYPE(name, typename) \
if (PyModule_AddObjectRef(m, name, \

View file

@ -36,6 +36,7 @@
#include "Python.h"
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pystate.h" // _PyInterpreterState_GET
#include "structmember.h" // PyMemberDef
@ -133,7 +134,7 @@ overlapped_dealloc(OverlappedObject *self)
{
/* The operation is no longer pending -- nothing to do. */
}
else if (_Py_IsInterpreterFinalizing(PyInterpreterState_Get()))
else if (_Py_IsInterpreterFinalizing(_PyInterpreterState_GET()))
{
/* The operation is still pending -- give a warning. This
will probably only happen on Windows XP. */