gh-98831: Modernize CALL_FUNCTION_EX (#101627)

New generator feature: Move CHECK_EVAL_BREAKER() call to just before DISPATCH().
This commit is contained in:
Guido van Rossum 2023-02-07 20:03:22 -08:00 committed by GitHub
parent 790ff6bc6a
commit a9f01448a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 37 deletions

View file

@ -2951,26 +2951,21 @@ 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, (unused, 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));
if (callargs == NULL) {
PyObject *tuple = PySequence_Tuple(callargs);
if (tuple == NULL) {
goto error;
}
Py_SETREF(callargs, tuple);
}
assert(PyTuple_CheckExact(callargs));
@ -2979,12 +2974,8 @@ dummy_func(
Py_DECREF(callargs);
Py_XDECREF(kwargs);
STACK_SHRINK(1);
assert(TOP() == NULL);
SET_TOP(result);
if (result == NULL) {
goto error;
}
assert(PEEK(3 + (oparg & 1)) == NULL);
ERROR_IF(result == NULL, error);
CHECK_EVAL_BREAKER();
}