Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4776b07

Browse filesBrowse files
authored
Don't make a call at the C level when calling bound-methods from Python code. (GH-29238)
1 parent bcee6aa commit 4776b07
Copy full SHA for 4776b07

File tree

Expand file treeCollapse file tree

1 file changed

+14
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-1
lines changed

‎Python/ceval.c

Copy file name to clipboardExpand all lines: Python/ceval.c
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4607,8 +4607,21 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
46074607
kwnames = NULL;
46084608
postcall_shrink = 1;
46094609
call_function:
4610-
// Check if the call can be inlined or not
46114610
function = PEEK(oparg + 1);
4611+
if (Py_TYPE(function) == &PyMethod_Type) {
4612+
PyObject *meth = ((PyMethodObject *)function)->im_func;
4613+
PyObject *self = ((PyMethodObject *)function)->im_self;
4614+
Py_INCREF(meth);
4615+
Py_INCREF(self);
4616+
PEEK(oparg + 1) = self;
4617+
Py_DECREF(function);
4618+
function = meth;
4619+
oparg++;
4620+
nargs++;
4621+
assert(postcall_shrink >= 1);
4622+
postcall_shrink--;
4623+
}
4624+
// Check if the call can be inlined or not
46124625
if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
46134626
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
46144627
int is_generator = code_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.