diff options
author | mpage <mpage@meta.com> | 2024-12-11 23:18:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 23:18:22 (GMT) |
commit | c84928ed6de105696be24859e03f3ab27e11daf6 (patch) | |
tree | c533074edffdb8ae55dfa197ce8d63417f28949a /Python/executor_cases.c.h | |
parent | e8f4e272cc828f2b79fa17fc6b9786bdddab7ce4 (diff) | |
download | cpython-c84928ed6de105696be24859e03f3ab27e11daf6.zip cpython-c84928ed6de105696be24859e03f3ab27e11daf6.tar.gz cpython-c84928ed6de105696be24859e03f3ab27e11daf6.tar.bz2 |
gh-115999: Specialize `CALL_KW` in free-threaded builds (#127713)
* Enable specialization of CALL_KW
* Fix bug pushing frame in _PY_FRAME_KW
`_PY_FRAME_KW` pushes a pointer to the new frame onto the stack for
consumption by the next uop. When pushing the frame fails, we do not
want to push the result, `NULL`, to the stack because it is not
a valid stackref. This works in the default build because `PyStackRef_NULL`
and `NULL` are the same value, so the `PyStackRef_XCLOSE()` in the error
handler ignores it. In the free-threaded build the values are not the same;
`PyStackRef_XCLOSE()` will attempt to decref a null pointer.
Diffstat (limited to 'Python/executor_cases.c.h')
-rw-r--r-- | Python/executor_cases.c.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 987ff2e..18f1977 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -5235,7 +5235,7 @@ int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(callable_o))->co_flags; PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o)); _PyFrame_SetStackPointer(frame, stack_pointer); - new_frame = _PyEvalFramePushAndInit( + _PyInterpreterFrame *temp = _PyEvalFramePushAndInit( tstate, callable[0], locals, args, positional_args, kwnames_o, frame ); @@ -5243,12 +5243,15 @@ PyStackRef_CLOSE(kwnames); // The frame has stolen all the arguments from the stack, // so there is no need to clean them up. - stack_pointer[-3 - oparg].bits = (uintptr_t)new_frame; - stack_pointer += -2 - oparg; + stack_pointer += -3 - oparg; assert(WITHIN_STACK_BOUNDS()); - if (new_frame == NULL) { + if (temp == NULL) { JUMP_TO_ERROR(); } + new_frame = temp; + stack_pointer[0].bits = (uintptr_t)new_frame; + stack_pointer += 1; + assert(WITHIN_STACK_BOUNDS()); break; } |