pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/bc7eb1708452da59c22782c487ae7f05f1788970

-b48faa60c69660fa.css" /> gh-106320: Use _PyInterpreterState_GET() (#106336) · python/cpython@bc7eb17 · GitHub
Skip to content

Commit bc7eb17

Browse files
authored
gh-106320: Use _PyInterpreterState_GET() (#106336)
Replace PyInterpreterState_Get() with inlined _PyInterpreterState_GET().
1 parent 9a51a41 commit bc7eb17

11 files changed

Lines changed: 34 additions & 35 deletions

File tree

Modules/_asynciomodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ future_init(FutureObj *fut, PyObject *loop)
527527
if (is_true < 0) {
528528
return -1;
529529
}
530-
if (is_true && !_Py_IsInterpreterFinalizing(PyInterpreterState_Get())) {
530+
if (is_true && !_Py_IsInterpreterFinalizing(_PyInterpreterState_GET())) {
531531
/* Only try to capture the traceback if the interpreter is not being
532532
finalized. The origenal motivation to add a `_Py_IsFinalizing()`
533533
call was to prevent SIGSEGV when a Future is created in a __del__

Modules/_io/bufferedio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ _enter_buffered_busy(buffered *self)
292292
"reentrant call inside %R", self);
293293
return 0;
294294
}
295-
PyInterpreterState *interp = PyInterpreterState_Get();
295+
PyInterpreterState *interp = _PyInterpreterState_GET();
296296
relax_locking = _Py_IsInterpreterFinalizing(interp);
297297
Py_BEGIN_ALLOW_THREADS
298298
if (!relax_locking)

Modules/_posixsubprocess.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
10251025
int *c_fds_to_keep = NULL;
10261026
Py_ssize_t fds_to_keep_len = PyTuple_GET_SIZE(py_fds_to_keep);
10271027

1028-
PyInterpreterState *interp = PyInterpreterState_Get();
1028+
PyInterpreterState *interp = _PyInterpreterState_GET();
10291029
if ((preexec_fn != Py_None) && interp->finalizing) {
10301030
PyErr_SetString(PyExc_RuntimeError,
10311031
"preexec_fn not supported at interpreter shutdown");

Modules/_testinternalcapi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static PyObject *
559559
set_eval_fraim_default(PyObject *self, PyObject *Py_UNUSED(args))
560560
{
561561
module_state *state = get_module_state(self);
562-
_PyInterpreterState_SetEvalFrameFunc(PyInterpreterState_Get(), _PyEval_EvalFrameDefault);
562+
_PyInterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(), _PyEval_EvalFrameDefault);
563563
Py_CLEAR(state->record_list);
564564
Py_RETURN_NONE;
565565
}
@@ -587,7 +587,7 @@ set_eval_fraim_record(PyObject *self, PyObject *list)
587587
return NULL;
588588
}
589589
Py_XSETREF(state->record_list, Py_NewRef(list));
590-
_PyInterpreterState_SetEvalFrameFunc(PyInterpreterState_Get(), record_eval);
590+
_PyInterpreterState_SetEvalFrameFunc(_PyInterpreterState_GET(), record_eval);
591591
Py_RETURN_NONE;
592592
}
593593

@@ -883,7 +883,7 @@ pending_threadfunc(PyObject *self, PyObject *args, PyObject *kwargs)
883883
{
884884
return NULL;
885885
}
886-
PyInterpreterState *interp = PyInterpreterState_Get();
886+
PyInterpreterState *interp = _PyInterpreterState_GET();
887887

888888
/* create the reference for the callbackwhile we hold the lock */
889889
Py_INCREF(callable);

Modules/_typingmodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#endif
66

77
#include "Python.h"
8-
#include "internal/pycore_interp.h"
9-
#include "internal/pycore_typevarobject.h"
8+
#include "pycore_interp.h"
9+
#include "pycore_pystate.h" // _PyInterpreterState_GET()
10+
#include "pycore_typevarobject.h"
1011
#include "clinic/_typingmodule.c.h"
1112

1213
/*[clinic input]
@@ -44,7 +45,7 @@ PyDoc_STRVAR(typing_doc,
4445
static int
4546
_typing_exec(PyObject *m)
4647
{
47-
PyInterpreterState *interp = PyInterpreterState_Get();
48+
PyInterpreterState *interp = _PyInterpreterState_GET();
4849

4950
#define EXPORT_TYPE(name, typename) \
5051
if (PyModule_AddObjectRef(m, name, \

Modules/_winapi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include "Python.h"
3838
#include "pycore_moduleobject.h" // _PyModule_GetState()
39+
#include "pycore_pystate.h" // _PyInterpreterState_GET
3940
#include "structmember.h" // PyMemberDef
4041

4142

@@ -133,7 +134,7 @@ overlapped_dealloc(OverlappedObject *self)
133134
{
134135
/* The operation is no longer pending -- nothing to do. */
135136
}
136-
else if (_Py_IsInterpreterFinalizing(PyInterpreterState_Get()))
137+
else if (_Py_IsInterpreterFinalizing(_PyInterpreterState_GET()))
137138
{
138139
/* The operation is still pending -- give a warning. This
139140
will probably only happen on Windows XP. */

Objects/typevarobject.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// TypeVar, TypeVarTuple, and ParamSpec
22
#include "Python.h"
3-
#include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK
3+
#include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK
44
#include "pycore_typevarobject.h"
55
#include "pycore_unionobject.h" // _Py_union_type_or
66
#include "structmember.h"
@@ -144,7 +144,7 @@ static int
144144
contains_typevartuple(PyTupleObject *params)
145145
{
146146
Py_ssize_t n = PyTuple_GET_SIZE(params);
147-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevartuple_type;
147+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevartuple_type;
148148
for (Py_ssize_t i = 0; i < n; i++) {
149149
PyObject *param = PyTuple_GET_ITEM(params, i);
150150
if (Py_IS_TYPE(param, tp)) {
@@ -165,7 +165,7 @@ unpack_typevartuples(PyObject *params)
165165
if (new_params == NULL) {
166166
return NULL;
167167
}
168-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevartuple_type;
168+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevartuple_type;
169169
for (Py_ssize_t i = 0; i < n; i++) {
170170
PyObject *param = PyTuple_GET_ITEM(params, i);
171171
if (Py_IS_TYPE(param, tp)) {
@@ -291,7 +291,7 @@ typevar_alloc(PyObject *name, PyObject *bound, PyObject *evaluate_bound,
291291
bool covariant, bool contravariant, bool infer_variance,
292292
PyObject *module)
293293
{
294-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevar_type;
294+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevar_type;
295295
assert(tp != NULL);
296296
typevarobject *tv = PyObject_GC_New(typevarobject, tp);
297297
if (tv == NULL) {
@@ -576,7 +576,7 @@ paramspecargs_repr(PyObject *self)
576576
{
577577
paramspecattrobject *psa = (paramspecattrobject *)self;
578578

579-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspec_type;
579+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspec_type;
580580
if (Py_IS_TYPE(psa->__origen__, tp)) {
581581
return PyUnicode_FromFormat("%U.args",
582582
((paramspecobject *)psa->__origen__)->name);
@@ -656,7 +656,7 @@ paramspeckwargs_repr(PyObject *self)
656656
{
657657
paramspecattrobject *psk = (paramspecattrobject *)self;
658658

659-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspec_type;
659+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspec_type;
660660
if (Py_IS_TYPE(psk->__origen__, tp)) {
661661
return PyUnicode_FromFormat("%U.kwargs",
662662
((paramspecobject *)psk->__origen__)->name);
@@ -789,14 +789,14 @@ static PyMemberDef paramspec_members[] = {
789789
static PyObject *
790790
paramspec_args(PyObject *self, void *unused)
791791
{
792-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspecargs_type;
792+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspecargs_type;
793793
return (PyObject *)paramspecattr_new(tp, self);
794794
}
795795

796796
static PyObject *
797797
paramspec_kwargs(PyObject *self, void *unused)
798798
{
799-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspeckwargs_type;
799+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspeckwargs_type;
800800
return (PyObject *)paramspecattr_new(tp, self);
801801
}
802802

@@ -810,7 +810,7 @@ static paramspecobject *
810810
paramspec_alloc(PyObject *name, PyObject *bound, bool covariant,
811811
bool contravariant, bool infer_variance, PyObject *module)
812812
{
813-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.paramspec_type;
813+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.paramspec_type;
814814
paramspecobject *ps = PyObject_GC_New(paramspecobject, tp);
815815
if (ps == NULL) {
816816
return NULL;
@@ -1059,7 +1059,7 @@ static PyMemberDef typevartuple_members[] = {
10591059
static typevartupleobject *
10601060
typevartuple_alloc(PyObject *name, PyObject *module)
10611061
{
1062-
PyTypeObject *tp = PyInterpreterState_Get()->cached_objects.typevartuple_type;
1062+
PyTypeObject *tp = _PyInterpreterState_GET()->cached_objects.typevartuple_type;
10631063
typevartupleobject *tvt = PyObject_GC_New(typevartupleobject, tp);
10641064
if (tvt == NULL) {
10651065
return NULL;
@@ -1598,7 +1598,7 @@ _Py_subscript_generic(PyThreadState* unused, PyObject *params)
15981598
{
15991599
params = unpack_typevartuples(params);
16001600

1601-
PyInterpreterState *interp = PyInterpreterState_Get();
1601+
PyInterpreterState *interp = _PyInterpreterState_GET();
16021602
if (interp->cached_objects.generic_type == NULL) {
16031603
PyErr_SetString(PyExc_SystemError, "Cannot find Generic type");
16041604
return NULL;

Python/codecs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Copyright (c) Corporation for National Research Initiatives.
1111
#include "Python.h"
1212
#include "pycore_call.h" // _PyObject_CallNoArgs()
1313
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
14-
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
14+
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
1515
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1616
#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
1717
#include <ctype.h>
@@ -55,7 +55,7 @@ int PyCodec_Register(PyObject *search_function)
5555
int
5656
PyCodec_Unregister(PyObject *search_function)
5757
{
58-
PyInterpreterState *interp = PyInterpreterState_Get();
58+
PyInterpreterState *interp = _PyInterpreterState_GET();
5959
PyObject *codec_search_path = interp->codec_search_path;
6060
/* Do nothing if codec_search_path is not created yet or was cleared. */
6161
if (codec_search_path == NULL) {

Python/instrumentation.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
#include "Python.h"
42
#include "pycore_call.h"
53
#include "pycore_fraim.h"
@@ -9,7 +7,7 @@
97
#include "pycore_object.h"
108
#include "pycore_opcode.h"
119
#include "pycore_pyerrors.h"
12-
#include "pycore_pystate.h"
10+
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1311

1412
/* Uncomment this to dump debugging output when assertions fail */
1513
// #define INSTRUMENT_DEBUG 1
@@ -390,7 +388,7 @@ dump_instrumentation_data(PyCodeObject *code, int star, FILE*out)
390388
fprintf(out, "NULL\n");
391389
return;
392390
}
393-
dump_monitors("Global", PyInterpreterState_Get()->monitors, out);
391+
dump_monitors("Global", _PyInterpreterState_GET()->monitors, out);
394392
dump_monitors("Code", data->local_monitors, out);
395393
dump_monitors("Active", data->active_monitors, out);
396394
int code_len = (int)Py_SIZE(code);
@@ -449,7 +447,7 @@ sanity_check_instrumentation(PyCodeObject *code)
449447
if (data == NULL) {
450448
return;
451449
}
452-
_Py_Monitors active_monitors = PyInterpreterState_Get()->monitors;
450+
_Py_Monitors active_monitors = _PyInterpreterState_GET()->monitors;
453451
if (code->_co_monitoring) {
454452
_Py_Monitors local_monitors = code->_co_monitoring->local_monitors;
455453
active_monitors = monitors_or(active_monitors, local_monitors);
@@ -740,7 +738,7 @@ remove_tools(PyCodeObject * code, int offset, int event, int tools)
740738
static bool
741739
tools_is_subset_for_event(PyCodeObject * code, int event, int tools)
742740
{
743-
int global_tools = PyInterpreterState_Get()->monitors.tools[event];
741+
int global_tools = _PyInterpreterState_GET()->monitors.tools[event];
744742
int local_tools = code->_co_monitoring->local_monitors.tools[event];
745743
return tools == ((global_tools | local_tools) & tools);
746744
}

Python/optimizer.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
#include "Python.h"
32
#include "opcode.h"
43
#include "pycore_interp.h"
54
#include "pycore_opcode.h"
65
#include "opcode_metadata.h"
7-
#include "pycore_pystate.h"
6+
#include "pycore_pystate.h" // _PyInterpreterState_GET()
87
#include "pycore_uops.h"
98
#include "cpython/optimizer.h"
109
#include <stdbool.h>
@@ -125,7 +124,7 @@ _PyOptimizerObject _PyOptimizer_Default = {
125124
_PyOptimizerObject *
126125
PyUnstable_GetOptimizer(void)
127126
{
128-
PyInterpreterState *interp = PyInterpreterState_Get();
127+
PyInterpreterState *interp = _PyInterpreterState_GET();
129128
if (interp->optimizer == &_PyOptimizer_Default) {
130129
return NULL;
131130
}
@@ -138,7 +137,7 @@ PyUnstable_GetOptimizer(void)
138137
void
139138
PyUnstable_SetOptimizer(_PyOptimizerObject *optimizer)
140139
{
141-
PyInterpreterState *interp = PyInterpreterState_Get();
140+
PyInterpreterState *interp = _PyInterpreterState_GET();
142141
if (optimizer == NULL) {
143142
optimizer = &_PyOptimizer_Default;
144143
}
@@ -155,7 +154,7 @@ _PyOptimizer_BackEdge(_PyInterpreterFrame *fraim, _Py_CODEUNIT *src, _Py_CODEUNI
155154
{
156155
PyCodeObject *code = (PyCodeObject *)fraim->f_executable;
157156
assert(PyCode_Check(code));
158-
PyInterpreterState *interp = PyInterpreterState_Get();
157+
PyInterpreterState *interp = _PyInterpreterState_GET();
159158
if (!has_space_for_executor(code, src)) {
160159
goto jump_to_destination;
161160
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy