]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Use _PyInterpreterState_GET() (#106336)
authorVictor Stinner <vstinner@python.org>
Sun, 2 Jul 2023 16:37:37 +0000 (18:37 +0200)
committerGitHub <noreply@github.com>
Sun, 2 Jul 2023 16:37:37 +0000 (16:37 +0000)
Replace PyInterpreterState_Get() with inlined
_PyInterpreterState_GET().

Modules/_asynciomodule.c
Modules/_io/bufferedio.c
Modules/_posixsubprocess.c
Modules/_testinternalcapi.c
Modules/_typingmodule.c
Modules/_winapi.c
Objects/typevarobject.c
Python/codecs.c
Python/instrumentation.c
Python/optimizer.c
Python/pystate.c

index 5b28f2dd28a2212253c7a40506cbceae4d30ea72..05f94ef9ed281608c03248124733b228492a26c8 100644 (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__
index 25376f82042836dd5717d8826a4565db408703a0..9c6a9cddba225801ae55d94061265bedd9783e75 100644 (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)
index 52e1d2faf3e9faaf345192be1249e8899b112f0c..6caa4b8852911e3cce761b1f1e3cbdbddf75790a 100644 (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");
index 971b8efb5fd9a4e775a7e4c3262479f52c8c0d74..4875ee7bed1683f952264e3d37197d69bcfc2528 100644 (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);
index 39a124a26adf3166c80accc1e4c97dc761b6da95..59d3a80a9305db9e74e40e71a4598af795a65d0a 100644 (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, \
index a7e6bb582fc64db60d87858bbece98c31fd9d030..d4291f557b6a669e049b4b1bf50c63c4de95348a 100644 (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. */
index 406a6eb76e3a8a7cadacef83e94f87d1f7481f6d..0b44f84b6f01d2fd6d2a8380e5ad2b84b46cfa14 100644 (file)
@@ -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"
@@ -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)) {
@@ -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)) {
@@ -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) {
@@ -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);
@@ -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);
@@ -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);
 }
 
@@ -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;
@@ -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;
@@ -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;
index 1983f56ba204c178ef8d04ab6502054b9e7be95f..f9f23005debb1f1a0423fc182c1bc124aa3ae463 100644 (file)
@@ -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>
@@ -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) {
index 3253a0ea13033c58b5377b236ad5f40dd1da8591..03d7d2f215af7c13902b5e1255a618f4f0c7802d 100644 (file)
@@ -1,5 +1,3 @@
-
-
 #include "Python.h"
 #include "pycore_call.h"
 #include "pycore_frame.h"
@@ -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
@@ -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);
@@ -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);
@@ -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);
 }
index 9d77ab4ff879bb1c3bbc77f8c476de17f58680e8..b00825ade16e0710ac2fd48c2b1b264d17c10ce1 100644 (file)
@@ -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>
@@ -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;
     }
@@ -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;
     }
@@ -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;
     }
index 50ce1d06602106d58839602af88f9bdbb4ec5ede..a9b404bd5c93e32591e6515ab6d7577939d9a6f0 100644 (file)
@@ -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)) {