Skip to content

Commit f2bad0d

Browse files
committed
Modernize CALL_FUNCTION_EX
1 parent c43d20b commit f2bad0d

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
@@ -2949,20 +2949,14 @@ dummy_func(
29492949
CHECK_EVAL_BREAKER();
29502950
}
29512951

2952-
// error: CALL_FUNCTION_EX has irregular stack effect
2953-
inst(CALL_FUNCTION_EX) {
2954-
PyObject *func, *callargs, *kwargs = NULL, *result;
2955-
if (oparg & 0x01) {
2956-
kwargs = POP();
2952+
inst(CALL_FUNCTION_EX, (null, func, callargs, kwargs if (oparg & 1) -- result)) {
2953+
if (oparg & 1) {
29572954
// DICT_MERGE is called before this opcode if there are kwargs.
29582955
// It converts all dict subtypes in kwargs into regular dicts.
29592956
assert(PyDict_CheckExact(kwargs));
29602957
}
2961-
callargs = POP();
2962-
func = TOP();
29632958
if (!PyTuple_CheckExact(callargs)) {
29642959
if (check_args_iterable(tstate, func, callargs) < 0) {
2965-
Py_DECREF(callargs);
29662960
goto error;
29672961
}
29682962
Py_SETREF(callargs, PySequence_Tuple(callargs));
@@ -2977,12 +2971,8 @@ dummy_func(
29772971
Py_DECREF(callargs);
29782972
Py_XDECREF(kwargs);
29792973

2980-
STACK_SHRINK(1);
2981-
assert(TOP() == NULL);
2982-
SET_TOP(result);
2983-
if (result == NULL) {
2984-
goto error;
2985-
}
2974+
assert(null == NULL);
2975+
ERROR_IF(result == NULL, error);
29862976
CHECK_EVAL_BREAKER();
29872977
}
29882978

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)