8000 GH-106701: Move _PyUopExecute to Python/executor.c (GH-106924) · python/cpython@8f4de57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f4de57

Browse files
authored
GH-106701: Move _PyUopExecute to Python/executor.c (GH-106924)
1 parent 9c81fc2 commit 8f4de57

File tree

13 files changed

+276
-247
lines changed

13 files changed

+276
-247
lines changed

Include/internal/pycore_ceval.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ extern int _Py_HandlePending(PyThreadState *tstate);
158158

159159
extern PyObject * _PyEval_GetFrameLocals(void);
160160

161+
extern const binaryfunc _PyEval_BinaryOps[];
162+
int _PyEval_CheckExceptStarTypeValid(PyThreadState *tstate, PyObject* right);
163+
int _PyEval_CheckExceptTypeValid(PyThreadState *tstate, PyObject* right);
164+
int _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, PyObject **match, PyObject **rest);
165+
void _PyEval_FormatAwaitableError(PyThreadState *tstate, PyTypeObject *type, int oparg);
166+
void _PyEval_FormatExcCheckArg(PyThreadState *tstate, PyObject *exc, const char *format_str, PyObject *obj);
167+
void _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
168+
void _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwargs);
169+
PyObject *_PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs);
170+
PyObject *_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys);
171+
int _PyEval_UnpackIterable(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, PyObject **sp);
172+
161173

162174
#ifdef __cplusplus
163175
}

Makefile.pre.in

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ PYTHON_OBJS= \
381381
Python/context.o \
382382
Python/dynamic_annotations.o \
383383
Python/errors.o \
384+
Python/executor.o \
384385
Python/flowgraph.o \
385386
Python/frame.o \
386387
Python/frozenmain.o \
@@ -1562,10 +1563,13 @@ Python/ceval.o: \
15621563
$(srcdir)/Python/ceval_macros.h \
15631564
$(srcdir)/Python/condvar.h \
15641565
$(srcdir)/Python/generated_cases.c.h \
1565-
$(srcdir)/Python/executor_cases.c.h \
1566-
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
15671566
$(srcdir)/Python/opcode_targets.h
15681567

1568+
Python/executor.o: \
1569+
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
1570+
$(srcdir)/Python/ceval_macros.h \
1571+
$(srcdir)/Python/executor_cases.c.h
1572+
15691573
Python/flowgraph.o: \
15701574
$(srcdir)/Include/internal/pycore_opcode_metadata.h
15711575

PCbuild/_freeze_module.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
<ClCompile Include="..\Python\dynamic_annotations.c" />
193193
<ClCompile Include="..\Python\dynload_win.c" />
194194
<ClCompile Include="..\Python\errors.c" />
195+
<ClCompile Include="..\Python\executor.c" />
195196
<ClCompile Include="..\Python\fileutils.c" />
196197
<ClCompile Include="..\Python\flowgraph.c" />
197198
<ClCompile Include="..\Python\formatter_unicode.c" />

PCbuild/_freeze_module.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
<ClCompile Include="..\Python\errors.c">
125125
<Filter>Source Files</Filter>
126126
</ClCompile>
127+
<ClCompile Include="..\Python\executor.c">
128+
<Filter>Source Files</Filter>
129+
</ClCompile>
127130
<ClCompile Include="..\Objects\exceptions.c">
128131
<Filter>Source Files</Filter>
129132
</ClCompile>

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@
520520
<ClCompile Include="..\Python\dynamic_annotations.c" />
521521
<ClCompile Include="..\Python\dynload_win.c" />
522522
<ClCompile Include="..\Python\errors.c" />
523+
<ClCompile Include="..\Python\executor.c" />
523524
<ClCompile Include="..\Python\fileutils.c" />
524525
<ClCompile Include="..\Python\flowgraph.c" />
525526
<ClCompile Include="..\Python\formatter_unicode.c" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,9 @@
11451145
<ClCompile Include="..\Python\errors.c">
11461146
<Filter>Python</Filter>
11471147
</ClCompile>
1148+
<ClCompile Include="..\Python\executor.c">
1149+
<Filter>Python</Filter>
1150+
</ClCompile>
11481151
<ClCompile Include="..\Python\fileutils.c">
11491152
<Filter>Python</Filter>
11501153
</ClCompile>

Python/bytecodes.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ dummy_func(
7777
PyObject **stack_pointer,
7878
PyObject *kwnames,
7979
int throwflag,
80-
binaryfunc binary_ops[],
8180
PyObject *args[]
8281
)
8382
{
@@ -893,7 +892,7 @@ dummy_func(
893892
iter = _PyCoro_GetAwaitableIter(iterable);
894893

895894
if (iter == NULL) {
896-
format_awaitable_error(tstate, Py_TYPE(iterable), oparg);
895+
_PyEval_FormatAwaitableError(tstate, Py_TYPE(iterable), oparg);
897896
}
898897

899898
DECREF_INPUTS();
@@ -1120,9 +1119,9 @@ dummy_func(
11201119
err = PyObject_DelItem(ns, name);
11211120
// Can't use ERROR_IF here.
11221121
if (err != 0) {
1123-
format_exc_check_arg(tstate, PyExc_NameError,
1124-
NAME_ERROR_MSG,
1125-
name);
1122+
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1123+
NAME_ERROR_MSG,
1124+
name);
11261125
goto error;
11271126
}
11281127
}
@@ -1145,7 +1144,7 @@ dummy_func(
11451144
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
11461145
#endif /* ENABLE_SPECIALIZATION */
11471146
PyObject **top = stack_pointer + oparg - 1;
1148-
int res = unpack_iterable(tstate, seq, oparg, -1, top);
1147+
int res = _PyEval_UnpackIterable(tstate, seq, oparg, -1, top);
11491148
DECREF_INPUTS();
11501149
ERROR_IF(res == 0, error);
11511150
}
@@ -1185,7 +1184,7 @@ dummy_func(
11851184
inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8])) {
11861185
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
11871186
PyObject **top = stack_pointer + totalargs - 1;
1188-
int res = unpack_iterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
1187+
int res = _PyEval_UnpackIterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
11891188
DECREF_INPUTS();
11901189
ERROR_IF(res == 0, error);
11911190
}
@@ -1235,8 +1234,8 @@ dummy_func(
12351234
// Can't use ERROR_IF here.
12361235
if (err != 0) {
12371236
if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
1238-
format_exc_check_arg(tstate, PyExc_NameError,
1239-
NAME_ERROR_MSG, name);
1237+
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1238+
NAME_ERROR_MSG, name);
12401239
}
12411240
goto error;
12421241
}
@@ -1274,7 +1273,7 @@ dummy_func(
12741273
goto error;
12751274
}
12761275
if (v == NULL) {
1277-
format_exc_check_arg(
1276+
_PyEval_FormatExcCheckArg(
12781277
tstate, PyExc_NameError,
12791278
NAME_ERROR_MSG, name);
12801279
goto error;
@@ -1315,8 +1314,8 @@ dummy_func(
13151314
if (!_PyErr_Occurred(tstate)) {
13161315
/* _PyDict_LoadGlobal() returns NULL without raising
13171316
* an exception if the key doesn't exist */
1318-
format_exc_check_arg(tstate, PyExc_NameError,
1319-
NAME_ERROR_MSG, name);
1317+
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
1318+
NAME_ERROR_MSG, name);
13201319
}
13211320
ERROR_IF(true, error);
13221321
}
@@ -1331,7 +1330,7 @@ dummy_func(
13311330
/* namespace 2: builtins */
13321331
ERROR_IF(PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0, error);
13331332
if (v == NULL) {
1334-
format_exc_check_arg(
1333+
_PyEval_FormatExcCheckArg(
13351334
tstate, PyExc_NameError,
13361335
NAME_ERROR_MSG, name);
13371336
ERROR_IF(true, error);
@@ -1413,7 +1412,7 @@ dummy_func(
14131412
// Can't use ERROR_IF here.
14141413
// Fortunately we don't need its superpower.
14151414
if (oldobj == NULL) {
1416-
format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg);
1415+
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
14171416
goto error;
14181417
}
14191418
PyCell_SET(cell, NULL);
@@ -1434,7 +1433,7 @@ dummy_func(
14341433
PyObject *cell = GETLOCAL(oparg);
14351434
value = PyCell_GET(cell);
14361435
if (value == NULL) {
1437-
format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg);
1436+
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
14381437
goto error;
14391438
}
14401439
Py_INCREF(value);
@@ -1445,7 +1444,7 @@ dummy_func(
14451444
PyObject *cell = GETLOCAL(oparg);
14461445
value = PyCell_GET(cell);
14471446
if (value == NULL) {
1448-
format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg);
1447+
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
14491448
ERROR_IF(true, error);
14501449
}
14511450
Py_INCREF(value);
@@ -1612,7 +1611,7 @@ dummy_func(
16121611
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
16131612

16141613
if (_PyDict_MergeEx(dict, update, 2) < 0) {
1615-
format_kwargs_error(tstate, PEEK(3 + oparg), update);
1614+
_PyEval_FormatKwargsError(tstate, PEEK(3 + oparg), update);
16161615
DECREF_INPUTS();
16171616
ERROR_IF(true, error);
16181617
}
@@ -2126,15 +2125,15 @@ dummy_func(
21262125
}
21272126

21282127
inst(CHECK_EG_MATCH, (exc_value, match_type -- rest, match)) {
2129-
if (check_except_star_type_valid(tstate, match_type) < 0) {
2128+
if (_PyEval_CheckExceptStarTypeValid(tstate, match_type) < 0) {
21302129
DECREF_INPUTS();
21312130
ERROR_IF(true, error);
21322131
}
21332132

21342133
match = NULL;
21352134
rest = NULL;
2136-
int res = exception_group_match(exc_value, match_type,
2137-
&match, &rest);
2135+
int res = _PyEval_ExceptionGroupMatch(exc_value, match_type,
2136+
&match, &rest);
21382137
DECREF_INPUTS();
21392138
ERROR_IF(res < 0, error);
21402139

@@ -2148,7 +2147,7 @@ dummy_func(
21482147

21492148
inst(CHECK_EXC_MATCH, (left, right -- left, b)) {
21502149
assert(PyExceptionInstance_Check(left));
2151-
if (check_except_type_valid(tstate, right) < 0) {
2150+
if (_PyEval_CheckExceptTypeValid(tstate, right) < 0) {
21522151
DECREF_INPUTS();
21532152
ERROR_IF(true, error);
21542153
}
@@ -2275,7 +2274,7 @@ dummy_func(
22752274
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
22762275
// None on failure.
22772276
assert(PyTuple_CheckExact(names));
2278-
attrs = match_class(tstate, subject, type, oparg, names);
2277+
attrs = _PyEval_MatchClass(tstate, subject, type, oparg, names);
22792278
DECREF_INPUTS();
22802279
if (attrs) {
22812280
assert(PyTuple_CheckExact(attrs)); // Success!
@@ -2298,7 +2297,7 @@ dummy_func(
22982297

22992298
inst(MATCH_KEYS, (subject, keys -- subject, keys, values_or_none)) {
23002299
// On successful match, PUSH(values). Otherwise, PUSH(None).
2301-
values_or_none = match_keys(tstate, subject, keys);
2300+
values_or_none = _PyEval_MatchKeys(tstate, subject, keys);
23022301
ERROR_IF(values_or_none == NULL, error);
23032302
}
23042303

@@ -3617,10 +3616,10 @@ dummy_func(
36173616
STAT_INC(BINARY_OP, deferred);
36183617
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
36193618
#endif /* ENABLE_SPECIALIZATION */
3620-
assert(0 <= oparg);
3621-
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
3622-
assert(binary_ops[oparg]);
3623-
res = binary_ops[oparg](lhs, rhs);
3619+
assert(NB_ADD <= oparg);
3620+
assert(oparg <= NB_INPLACE_XOR);
3621+
assert(_PyEval_BinaryOps[oparg]);
3622+
res = _PyEval_BinaryOps[oparg](lhs, rhs);
36243623
DECREF_INPUTS();
36253624
ERROR_IF(res == NULL, error);
36263625
}

0 commit comments

Comments
 (0)
0