8000 gh-98831: Modernize CALL_FUNCTION_EX by gvanrossum · Pull Request #101627 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-98831: Modernize CALL_FUNCTION_EX #101627

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

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Modernize CALL_FUNCTION_EX
  • Loading branch information
gvanrossum committed Feb 7, 2023
commit f2bad0debbbdaf74e79410a1d6d12aea1337c867
18 changes: 4 additions & 14 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2949,20 +2949,14 @@ dummy_func(
CHECK_EVAL_BREAKER();
}

// error: CALL_FUNCTION_EX has irregular stack effect
inst(CALL_FUNCTION_EX) {
PyObject *func, *callargs, *kwargs = NULL, *result;
if (oparg & 0x01) {
kwargs = POP();
inst(CALL_FUNCTION_EX, (null, func, callargs, kwargs if (oparg & 1) -- result)) {
if (oparg & 1) {
// DICT_MERGE is called before this opcode if there are kwargs.
// It converts all dict subtypes in kwargs into regular dicts.
assert(PyDict_CheckExact(kwargs));
}
callargs = POP();
func = TOP();
if (!PyTuple_CheckExact(callargs)) {
if (check_args_iterable(tstate, func, callargs) < 0) {
Py_DECREF(callargs);
goto error;
}
Py_SETREF(callargs, PySequence_Tuple(callargs));
Expand All @@ -2977,12 +2971,8 @@ dummy_func(
Py_DECREF(callargs);
Py_XDECREF(kwargs);

STACK_SHRINK(1);
assert(TOP() == NULL);
SET_TOP(result);
if (result == NULL) {
goto error;
}
assert(null == NULL);
ERROR_IF(result == NULL, error);
CHECK_EVAL_BREAKER();
}

Expand Down
23 changes: 11 additions & 12 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
case CALL_NO_KW_METHOD_DESCRIPTOR_FAST:
return -1;
case CALL_FUNCTION_EX:
return -1;
return ((oparg & 1) ? 1 : 0) + 3;
case MAKE_FUNCTION:
return ((oparg & 0x01) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x08) ? 1 : 0) + 1;
case RETURN_GENERATOR:
Expand Down Expand Up @@ -669,7 +669,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
case CALL_NO_KW_METHOD_DESCRIPTOR_FAST:
return -1;
case CALL_FUNCTION_EX:
return -1;
return 1;
case MAKE_FUNCTION:
return 1;
case RETURN_GENERATOR:
Expand Down
0