Skip to content
Merged
Changes from all commits
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
Don't calls at the C level when calling bound-methods from Python code.
  • Loading branch information
markshannon committed Oct 27, 2021
commit a65c7695243753f4bf56e4b8439e20d1ececfe4b
15 changes: 14 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4635,8 +4635,21 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
kwnames = NULL;
postcall_shrink = 1;
call_function:
// Check if the call can be inlined or not
function = PEEK(oparg + 1);
if (Py_TYPE(function) == &PyMethod_Type) {
PyObject *meth = ((PyMethodObject *)function)->im_func;
PyObject *self = ((PyMethodObject *)function)->im_self;
Py_INCREF(meth);
Py_INCREF(self);
PEEK(oparg + 1) = self;
Py_DECREF(function);
function = meth;
oparg++;
nargs++;
assert(postcall_shrink >= 1);
postcall_shrink--;
}
// Check if the call can be inlined or not
if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
int is_generator = code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR);
Expand Down