]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Don't make a call at the C level when calling bound-methods from Python code. (GH...
authorMark Shannon <mark@hotpy.org>
Wed, 27 Oct 2021 14:26:22 +0000 (15:26 +0100)
committerGitHub <noreply@github.com>
Wed, 27 Oct 2021 14:26:22 +0000 (15:26 +0100)
Python/ceval.c

index a0f4c801e8f8c2a94af7e6af2601070df38d338b..bd01e8159c8e4ca8564923e5b837e09f78b3e51e 100644 (file)
@@ -4607,8 +4607,21 @@ check_eval_breaker:
             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);