Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-106320: Use _PyInterpreterState_GET() #106336

Merged
merged 1 commit into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions Modules/_typingmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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, \
Expand Down
3 changes: 2 additions & 1 deletion Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "Python.h"
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pystate.h" // _PyInterpreterState_GET
#include "structmember.h" // PyMemberDef


Expand Down Expand Up @@ -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. */
Expand Down
22 changes: 11 additions & 11 deletions Objects/typevarobject.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TypeVar, TypeVarTuple, and ParamSpec
#include "Python.h"
#include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK
#include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK
#include "pycore_typevarobject.h"
#include "pycore_unionobject.h" // _Py_union_type_or
#include "structmember.h"
Expand Down Expand Up @@ -144,7 +144,7 @@ static int
contains_typevartuple(PyTupleObject *params)
{
Py_ssize_t n = PyTuple_GET_SIZE(params);
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevartuple_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevartuple_type;
for (Py_ssize_t i = 0; i < n; i++) {
PyObject *param = PyTuple_GET_ITEM(params, i);
if (Py_IS_TYPE(param, tp)) {
Expand All @@ -165,7 +165,7 @@ unpack_typevartuples(PyObject *params)
if (new_params == NULL) {
return NULL;
}
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevartuple_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevartuple_type;
for (Py_ssize_t i = 0; i < n; i++) {
PyObject *param = PyTuple_GET_ITEM(params, i);
if (Py_IS_TYPE(param, tp)) {
Expand Down Expand Up @@ -291,7 +291,7 @@ typevar_alloc(PyObject *name, PyObject *bound, PyObject *evaluate_bound,
bool covariant, bool contravariant, bool infer_variance,
PyObject *module)
{
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevar_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevar_type;
assert(tp != NULL);
typevarobject *tv = PyObject_GC_New(typevarobject, tp);
if (tv == NULL) {
Expand Down Expand Up @@ -576,7 +576,7 @@ paramspecargs_repr(PyObject *self)
{
paramspecattrobject *psa = (paramspecattrobject *)self;

PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspec_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspec_type;
if (Py_IS_TYPE(psa->__origin__, tp)) {
return PyUnicode_FromFormat("%U.args",
((paramspecobject *)psa->__origin__)->name);
Expand Down Expand Up @@ -656,7 +656,7 @@ paramspeckwargs_repr(PyObject *self)
{
paramspecattrobject *psk = (paramspecattrobject *)self;

PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspec_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspec_type;
if (Py_IS_TYPE(psk->__origin__, tp)) {
return PyUnicode_FromFormat("%U.kwargs",
((paramspecobject *)psk->__origin__)->name);
Expand Down Expand Up @@ -789,14 +789,14 @@ static PyMemberDef paramspec_members[] = {
static PyObject *
paramspec_args(PyObject *self, void *unused)
{
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspecargs_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspecargs_type;
return (PyObject *)paramspecattr_new(tp, self);
}

static PyObject *
paramspec_kwargs(PyObject *self, void *unused)
{
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspeckwargs_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspeckwargs_type;
return (PyObject *)paramspecattr_new(tp, self);
}

Expand All @@ -810,7 +810,7 @@ static paramspecobject *
paramspec_alloc(PyObject *name, PyObject *bound, bool covariant,
bool contravariant, bool infer_variance, PyObject *module)
{
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspec_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspec_type;
paramspecobject *ps = PyObject_GC_New(paramspecobject, tp);
if (ps == NULL) {
return NULL;
Expand Down Expand Up @@ -1059,7 +1059,7 @@ static PyMemberDef typevartuple_members[] = {
static typevartupleobject *
typevartuple_alloc(PyObject *name, PyObject *module)
{
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevartuple_type;
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevartuple_type;
typevartupleobject *tvt = PyObject_GC_New(typevartupleobject, tp);
if (tvt == NULL) {
return NULL;
Expand Down Expand Up @@ -1598,7 +1598,7 @@ _Py_subscript_generic(PyThreadState* unused, PyObject *params)
{
params = unpack_typevartuples(params);

PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->cached_objects.generic_type == NULL) {
PyErr_SetString(PyExc_SystemError, "Cannot find Generic type");
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Copyright (c) Corporation for National Research Initiatives.
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
#include <ctype.h>
Expand Down Expand Up @@ -55,7 +55,7 @@ int PyCodec_Register(PyObject *search_function)
int
PyCodec_Unregister(PyObject *search_function)
{
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *codec_search_path = interp->codec_search_path;
/* Do nothing if codec_search_path is not created yet or was cleared. */
if (codec_search_path == NULL) {
Expand Down
10 changes: 4 additions & 6 deletions Python/instrumentation.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include "Python.h"
#include "pycore_call.h"
#include "pycore_frame.h"
Expand All @@ -9,7 +7,7 @@
#include "pycore_object.h"
#include "pycore_opcode.h"
#include "pycore_pyerrors.h"
#include "pycore_pystate.h"
#include "pycore_pystate.h" // _PyInterpreterState_GET()

/* Uncomment this to dump debugging output when assertions fail */
// #define INSTRUMENT_DEBUG 1
Expand Down Expand Up @@ -390,7 +388,7 @@ dump_instrumentation_data(PyCodeObject *code, int star, FILE*out)
fprintf(out, "NULL\n");
return;
}
dump_monitors("Global", PyInterpreterState_Get()->monitors, out);
dump_monitors("Global", _PyInterpreterState_GET()->monitors, out);
dump_monitors("Code", data->local_monitors, out);
dump_monitors("Active", data->active_monitors, out);
int code_len = (int)Py_SIZE(code);
Expand Down Expand Up @@ -449,7 +447,7 @@ sanity_check_instrumentation(PyCodeObject *code)
if (data == NULL) {
return;
}
_Py_Monitors active_monitors = PyInterpreterState_Get()->monitors;
_Py_Monitors active_monitors = _PyInterpreterState_GET()->monitors;
if (code->_co_monitoring) {
_Py_Monitors local_monitors = code->_co_monitoring->local_monitors;
active_monitors = monitors_or(active_monitors, local_monitors);
Expand Down Expand Up @@ -740,7 +738,7 @@ remove_tools(PyCodeObject * code, int offset, int event, int tools)
static bool
tools_is_subset_for_event(PyCodeObject * code, int event, int tools)
{
int global_tools = PyInterpreterState_Get()->monitors.tools[event];
int global_tools = _PyInterpreterState_GET()->monitors.tools[event];
int local_tools = code->_co_monitoring->local_monitors.tools[event];
return tools == ((global_tools | local_tools) & tools);
}
Expand Down
9 changes: 4 additions & 5 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

#include "Python.h"
#include "opcode.h"
#include "pycore_interp.h"
#include "pycore_opcode.h"
#include "opcode_metadata.h"
#include "pycore_pystate.h"
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_uops.h"
#include "cpython/optimizer.h"
#include <stdbool.h>
Expand Down Expand Up @@ -125,7 +124,7 @@ _PyOptimizerObject _PyOptimizer_Default = {
_PyOptimizerObject *
PyUnstable_GetOptimizer(void)
{
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->optimizer == &_PyOptimizer_Default) {
return NULL;
}
Expand All @@ -138,7 +137,7 @@ PyUnstable_GetOptimizer(void)
void
PyUnstable_SetOptimizer(_PyOptimizerObject *optimizer)
{
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if (optimizer == NULL) {
optimizer = &_PyOptimizer_Default;
}
Expand All @@ -155,7 +154,7 @@ _PyOptimizer_BackEdge(_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNI
{
PyCodeObject *code = (PyCodeObject *)frame->f_executable;
assert(PyCode_Check(code));
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();
if (!has_space_for_executor(code, src)) {
goto jump_to_destination;
}
Expand Down
2 changes: 1 addition & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,7 @@ _PyInterpreterState_GetConfig(PyInterpreterState *interp)
int
_PyInterpreterState_GetConfigCopy(PyConfig *config)
{
PyInterpreterState *interp = PyInterpreterState_Get();
PyInterpreterState *interp = _PyInterpreterState_GET();

PyStatus status = _PyConfig_Copy(config, &interp->config);
if (PyStatus_Exception(status)) {
Expand Down