Skip to content

Commit 10dcbec

Browse files
committed
Modernize CALL_FUNCTION_EX
1 parent 91026d5 commit 10dcbec

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,20 +2935,14 @@ dummy_func(
29352935
CHECK_EVAL_BREAKER();
29362936
}
29372937

2938-
// error: CALL_FUNCTION_EX has irregular stack effect
2939-
inst(CALL_FUNCTION_EX) {
2940-
PyObject *func, *callargs, *kwargs = NULL, *result;
2941-
if (oparg & 0x01) {
2942-
kwargs = POP();
2938+
inst(CALL_FUNCTION_EX, (null, func, callargs, kwargs if (oparg & 1) -- result)) {
2939+
if (oparg & 1) {
29432940
// DICT_MERGE is called before this opcode if there are kwargs.
29442941
// It converts all dict subtypes in kwargs into regular dicts.
29452942
assert(PyDict_CheckExact(kwargs));
29462943
}
2947-
callargs = POP();
2948-
func = TOP();
29492944
if (!PyTuple_CheckExact(callargs)) {
29502945
if (check_args_iterable(tstate, func, callargs) < 0) {
2951-
Py_DECREF(callargs);
29522946
goto error;
29532947
}
29542948
Py_SETREF(callargs, PySequence_Tuple(callargs));
@@ -2963,12 +2957,8 @@ dummy_func(
29632957
Py_DECREF(callargs);
29642958
Py_XDECREF(kwargs);
29652959

2966-
STACK_SHRINK(1);
2967-
assert(TOP() == NULL);
2968-
SET_TOP(result);
2969-
if (result == NULL) {
2970-
goto error;
2971-
}
2960+
assert(null == NULL);
2961+
ERROR_IF(result == NULL, error);
29722962
CHECK_EVAL_BREAKER();
29732963
}
29742964

Python/generated_cases.c.h

Lines changed: 11 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
323323
case CALL_NO_KW_METHOD_DESCRIPTOR_FAST:
324324
return -1;
325325
case CALL_FUNCTION_EX:
326-
return -1;
326+
return ((oparg & 1) ? 1 : 0) + 3;
327327
case MAKE_FUNCTION:
328328
return ((oparg & 0x01) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x08) ? 1 : 0) + 1;
329329
case RETURN_GENERATOR:
@@ -669,7 +669,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
669669
case CALL_NO_KW_METHOD_DESCRIPTOR_FAST:
670670
return -1;
671671
case CALL_FUNCTION_EX:
672-
return -1;
672+
return 1;
673673
case MAKE_FUNCTION:
674674
return 1;
675675
case RETURN_GENERATOR:

0 commit comments

Comments
 (0)