summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authoradphrost <104581013+adphrost@users.noreply.github.com>2022-09-15 15:42:37 (GMT)
committerGitHub <noreply@github.com>2022-09-15 15:42:37 (GMT)
commita41ed975e863ae0ca435783596f14f8492d62f8d (patch)
treeb87ceae5a7c55e1131a7cdf02b0cda2b6ca41eaf /Python
parente37ac5fbb6de593521cf218aa05bc58a45c5a7c9 (diff)
downloadcpython-a41ed975e863ae0ca435783596f14f8492d62f8d.zip
cpython-a41ed975e863ae0ca435783596f14f8492d62f8d.tar.gz
cpython-a41ed975e863ae0ca435783596f14f8492d62f8d.tar.bz2
GH-91049: Introduce set vectorcall field API for PyFunctionObject (GH-92257)
Co-authored-by: Andrew Frost <adfrost@fb.com> Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c10
-rw-r--r--Python/specialize.c5
2 files changed, 13 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index b61cc08..8891d6c 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3126,8 +3126,11 @@ handle_eval_breaker:
PyObject *getattribute = read_obj(cache->descr);
assert(Py_IS_TYPE(getattribute, &PyFunction_Type));
PyFunctionObject *f = (PyFunctionObject *)getattribute;
+ uint32_t func_version = read_u32(cache->keys_version);
+ assert(func_version != 0);
+ DEOPT_IF(f->func_version != func_version, LOAD_ATTR);
PyCodeObject *code = (PyCodeObject *)f->func_code;
- DEOPT_IF(((PyCodeObject *)f->func_code)->co_argcount != 2, LOAD_ATTR);
+ assert(code->co_argcount == 2);
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
STAT_INC(LOAD_ATTR, hit);
@@ -4133,7 +4136,10 @@ handle_eval_breaker:
function = PEEK(total_args + 1);
int positional_args = total_args - KWNAMES_LEN();
// Check if the call can be inlined or not
- if (Py_TYPE(function) == &PyFunction_Type && tstate->interp->eval_frame == NULL) {
+ if (Py_TYPE(function) == &PyFunction_Type &&
+ tstate->interp->eval_frame == NULL &&
+ ((PyFunctionObject *)function)->vectorcall == _PyFunction_Vectorcall)
+ {
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags;
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(function));
STACK_SHRINK(total_args);
diff --git a/Python/specialize.c b/Python/specialize.c
index 93f1d28..b7c321e 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -837,6 +837,11 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name)
if (!function_check_args(descr, 2, LOAD_ATTR)) {
goto fail;
}
+ uint32_t version = function_get_version(descr, LOAD_ATTR);
+ if (version == 0) {
+ goto fail;
+ }
+ write_u32(lm_cache->keys_version, version);
/* borrowed */
write_obj(lm_cache->descr, descr);
write_u32(lm_cache->type_version, type->tp_version_tag);