Skip to content

Commit b933f6e

Browse files
Use new case regenerator
1 parent 898c75d commit b933f6e

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

Python/bytecodes.c

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,10 +3475,55 @@ dummy_func(
34753475
}
34763476
assert(PyTuple_CheckExact(callargs));
34773477

3478-
result = do_call_core(tstate, func, callargs, kwargs, cframe.use_tracing);
3479-
Py_DECREF(func);
3480-
Py_DECREF(callargs);
3481-
Py_XDECREF(kwargs);
3478+
if (Py_IS_TYPE(func, &PyFunction_Type) &&
3479+
tstate->interp->eval_frame == NULL &&
3480+
((PyFunctionObject *)func)->vectorcall == _PyFunction_Vectorcall) {
3481+
assert(PyTuple_CheckExact(callargs));
3482+
Py_ssize_t nargs = PyTuple_GET_SIZE(callargs);
3483+
int code_flags = ((PyCodeObject *)PyFunction_GET_CODE(func))->co_flags;
3484+
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(func));
3485+
3486+
bool has_dict = (kwargs != NULL && PyDict_GET_SIZE(kwargs) > 0);
3487+
PyObject *kwnames = NULL;
3488+
PyObject *const *newargs = has_dict
3489+
? _PyStack_UnpackDict(tstate, _PyTuple_ITEMS(callargs),
3490+
nargs, kwargs, &kwnames)
3491+
: &PyTuple_GET_ITEM(callargs, 0);
3492+
if (newargs == NULL) {
3493+
goto error;
3494+
}
3495+
if (!has_dict) {
3496+
/* We need to incref all our args since the new frame steals the references. */
3497+
for (Py_ssize_t i = 0; i < nargs; ++i) {
3498+
Py_INCREF(PyTuple_GET_ITEM(callargs, i));
3499+
}
3500+
}
3501+
_PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit(
3502+
tstate, (PyFunctionObject *)func, locals,
3503+
newargs, nargs, kwnames
3504+
);
3505+
STACK_SHRINK(2); /* get rid of func and NULL */
3506+
Py_DECREF(callargs);
3507+
Py_XDECREF(kwargs);
3508+
if (has_dict) {
3509+
_PyStack_UnpackDict_FreeNoDecRef(newargs, kwnames);
3510+
}
3511+
if (new_frame == NULL) {
3512+
goto error;
3513+
}
3514+
_PyFrame_SetStackPointer(frame, stack_pointer);
3515+
frame->prev_instr = next_instr - 1;
3516+
new_frame->previous = frame;
3517+
cframe.current_frame = frame = new_frame;
3518+
CALL_STAT_INC(inlined_py_calls);
3519+
goto start_frame;
3520+
}
3521+
else {
3522+
result = do_call_core(tstate, func, callargs, kwargs, cframe.use_tracing);
3523+
Py_DECREF(func);
3524+
Py_DECREF(callargs);
3525+
Py_XDECREF(kwargs);
3526+
}
34823527

34833528
STACK_SHRINK(1);
34843529
assert(TOP() == NULL);

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)