Skip to content

Commit

Permalink
pythonGH-106701: Move _PyUopExecute to Python/executor.c (pythonGH-10…
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher authored Jul 20, 2023
1 parent 9c81fc2 commit 8f4de57
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 247 deletions.
12 changes: 12 additions & 0 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ extern int _Py_HandlePending(PyThreadState *tstate);

extern PyObject * _PyEval_GetFrameLocals(void);

extern const binaryfunc _PyEval_BinaryOps[];
int _PyEval_CheckExceptStarTypeValid(PyThreadState *tstate, PyObject* right);
int _PyEval_CheckExceptTypeValid(PyThreadState *tstate, PyObject* right);
int _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type, PyObject **match, PyObject **rest);
void _PyEval_FormatAwaitableError(PyThreadState *tstate, PyTypeObject *type, int oparg);
void _PyEval_FormatExcCheckArg(PyThreadState *tstate, PyObject *exc, const char *format_str, PyObject *obj);
void _PyEval_FormatExcUnbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
void _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwargs);
PyObject *_PyEval_MatchClass(PyThreadState *tstate, PyObject *subject, PyObject *type, Py_ssize_t nargs, PyObject *kwargs);
PyObject *_PyEval_MatchKeys(PyThreadState *tstate, PyObject *map, PyObject *keys);
int _PyEval_UnpackIterable(PyThreadState *tstate, PyObject *v, int argcnt, int argcntafter, PyObject **sp);


#ifdef __cplusplus
}
Expand Down
8 changes: 6 additions & 2 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ PYTHON_OBJS= \
Python/context.o \
Python/dynamic_annotations.o \
Python/errors.o \
Python/executor.o \
Python/flowgraph.o \
Python/frame.o \
Python/frozenmain.o \
Expand Down Expand Up @@ -1562,10 +1563,13 @@ Python/ceval.o: \
$(srcdir)/Python/ceval_macros.h \
$(srcdir)/Python/condvar.h \
$(srcdir)/Python/generated_cases.c.h \
$(srcdir)/Python/executor_cases.c.h \
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
$(srcdir)/Python/opcode_targets.h

Python/executor.o: \
$(srcdir)/Include/internal/pycore_opcode_metadata.h \
$(srcdir)/Python/ceval_macros.h \
$(srcdir)/Python/executor_cases.c.h

Python/flowgraph.o: \
$(srcdir)/Include/internal/pycore_opcode_metadata.h

Expand Down
1 change: 1 addition & 0 deletions PCbuild/_freeze_module.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<ClCompile Include="..\Python\dynamic_annotations.c" />
<ClCompile Include="..\Python\dynload_win.c" />
<ClCompile Include="..\Python\errors.c" />
<ClCompile Include="..\Python\executor.c" />
<ClCompile Include="..\Python\fileutils.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\formatter_unicode.c" />
Expand Down
3 changes: 3 additions & 0 deletions PCbuild/_freeze_module.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<ClCompile Include="..\Python\errors.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\executor.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Objects\exceptions.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@
<ClCompile Include="..\Python\dynamic_annotations.c" />
<ClCompile Include="..\Python\dynload_win.c" />
<ClCompile Include="..\Python\errors.c" />
<ClCompile Include="..\Python\executor.c" />
<ClCompile Include="..\Python\fileutils.c" />
<ClCompile Include="..\Python\flowgraph.c" />
<ClCompile Include="..\Python\formatter_unicode.c" />
Expand Down
3 changes: 3 additions & 0 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,9 @@
<ClCompile Include="..\Python\errors.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\executor.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\fileutils.c">
<Filter>Python</Filter>
</ClCompile>
Expand Down
53 changes: 26 additions & 27 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ dummy_func(
PyObject **stack_pointer,
PyObject *kwnames,
int throwflag,
binaryfunc binary_ops[],
PyObject *args[]
)
{
Expand Down Expand Up @@ -893,7 +892,7 @@ dummy_func(
iter = _PyCoro_GetAwaitableIter(iterable);

if (iter == NULL) {
format_awaitable_error(tstate, Py_TYPE(iterable), oparg);
_PyEval_FormatAwaitableError(tstate, Py_TYPE(iterable), oparg);
}

DECREF_INPUTS();
Expand Down Expand Up @@ -1120,9 +1119,9 @@ dummy_func(
err = PyObject_DelItem(ns, name);
// Can't use ERROR_IF here.
if (err != 0) {
format_exc_check_arg(tstate, PyExc_NameError,
NAME_ERROR_MSG,
name);
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
NAME_ERROR_MSG,
name);
goto error;
}
}
Expand All @@ -1145,7 +1144,7 @@ dummy_func(
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
#endif /* ENABLE_SPECIALIZATION */
PyObject **top = stack_pointer + oparg - 1;
int res = unpack_iterable(tstate, seq, oparg, -1, top);
int res = _PyEval_UnpackIterable(tstate, seq, oparg, -1, top);
DECREF_INPUTS();
ERROR_IF(res == 0, error);
}
Expand Down Expand Up @@ -1185,7 +1184,7 @@ dummy_func(
inst(UNPACK_EX, (seq -- unused[oparg & 0xFF], unused, unused[oparg >> 8])) {
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
PyObject **top = stack_pointer + totalargs - 1;
int res = unpack_iterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
int res = _PyEval_UnpackIterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
DECREF_INPUTS();
ERROR_IF(res == 0, error);
}
Expand Down Expand Up @@ -1235,8 +1234,8 @@ dummy_func(
// Can't use ERROR_IF here.
if (err != 0) {
if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
format_exc_check_arg(tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
}
goto error;
}
Expand Down Expand Up @@ -1274,7 +1273,7 @@ dummy_func(
goto error;
}
if (v == NULL) {
format_exc_check_arg(
_PyEval_FormatExcCheckArg(
tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
goto error;
Expand Down Expand Up @@ -1315,8 +1314,8 @@ dummy_func(
if (!_PyErr_Occurred(tstate)) {
/* _PyDict_LoadGlobal() returns NULL without raising
* an exception if the key doesn't exist */
format_exc_check_arg(tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
_PyEval_FormatExcCheckArg(tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
}
ERROR_IF(true, error);
}
Expand All @@ -1331,7 +1330,7 @@ dummy_func(
/* namespace 2: builtins */
ERROR_IF(PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0, error);
if (v == NULL) {
format_exc_check_arg(
_PyEval_FormatExcCheckArg(
tstate, PyExc_NameError,
NAME_ERROR_MSG, name);
ERROR_IF(true, error);
Expand Down Expand Up @@ -1413,7 +1412,7 @@ dummy_func(
// Can't use ERROR_IF here.
// Fortunately we don't need its superpower.
if (oldobj == NULL) {
format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg);
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
goto error;
}
PyCell_SET(cell, NULL);
Expand All @@ -1434,7 +1433,7 @@ dummy_func(
PyObject *cell = GETLOCAL(oparg);
value = PyCell_GET(cell);
if (value == NULL) {
format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg);
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
goto error;
}
Py_INCREF(value);
Expand All @@ -1445,7 +1444,7 @@ dummy_func(
PyObject *cell = GETLOCAL(oparg);
value = PyCell_GET(cell);
if (value == NULL) {
format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg);
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
ERROR_IF(true, error);
}
Py_INCREF(value);
Expand Down Expand Up @@ -1612,7 +1611,7 @@ dummy_func(
PyObject *dict = PEEK(oparg + 1); // update is still on the stack

if (_PyDict_MergeEx(dict, update, 2) < 0) {
format_kwargs_error(tstate, PEEK(3 + oparg), update);
_PyEval_FormatKwargsError(tstate, PEEK(3 + oparg), update);
DECREF_INPUTS();
ERROR_IF(true, error);
}
Expand Down Expand Up @@ -2126,15 +2125,15 @@ dummy_func(
}

inst(CHECK_EG_MATCH, (exc_value, match_type -- rest, match)) {
if (check_except_star_type_valid(tstate, match_type) < 0) {
if (_PyEval_CheckExceptStarTypeValid(tstate, match_type) < 0) {
DECREF_INPUTS();
ERROR_IF(true, error);
}

match = NULL;
rest = NULL;
int res = exception_group_match(exc_value, match_type,
&match, &rest);
int res = _PyEval_ExceptionGroupMatch(exc_value, match_type,
&match, &rest);
DECREF_INPUTS();
ERROR_IF(res < 0, error);

Expand All @@ -2148,7 +2147,7 @@ dummy_func(

inst(CHECK_EXC_MATCH, (left, right -- left, b)) {
assert(PyExceptionInstance_Check(left));
if (check_except_type_valid(tstate, right) < 0) {
if (_PyEval_CheckExceptTypeValid(tstate, right) < 0) {
DECREF_INPUTS();
ERROR_IF(true, error);
}
Expand Down Expand Up @@ -2275,7 +2274,7 @@ dummy_func(
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
// None on failure.
assert(PyTuple_CheckExact(names));
attrs = match_class(tstate, subject, type, oparg, names);
attrs = _PyEval_MatchClass(tstate, subject, type, oparg, names);
DECREF_INPUTS();
if (attrs) {
assert(PyTuple_CheckExact(attrs)); // Success!
Expand All @@ -2298,7 +2297,7 @@ dummy_func(

inst(MATCH_KEYS, (subject, keys -- subject, keys, values_or_none)) {
// On successful match, PUSH(values). Otherwise, PUSH(None).
values_or_none = match_keys(tstate, subject, keys);
values_or_none = _PyEval_MatchKeys(tstate, subject, keys);
ERROR_IF(values_or_none == NULL, error);
}

Expand Down Expand Up @@ -3617,10 +3616,10 @@ dummy_func(
STAT_INC(BINARY_OP, deferred);
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
#endif /* ENABLE_SPECIALIZATION */
assert(0 <= oparg);
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
assert(binary_ops[oparg]);
res = binary_ops[oparg](lhs, rhs);
assert(NB_ADD <= oparg);
assert(oparg <= NB_INPLACE_XOR);
assert(_PyEval_BinaryOps[oparg]);
res = _PyEval_BinaryOps[oparg](lhs, rhs);
DECREF_INPUTS();
ERROR_IF(res == NULL, error);
}
Expand Down
Loading

0 comments on commit 8f4de57

Please sign in to comment.