Skip to content

Commit b22403e

Browse files
committed
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.
1 parent e56da80 commit b22403e

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

Python/bytecodes.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,17 +4311,18 @@ dummy_func(
43114311
assert(Py_TYPE(callable_o) == &PyFunction_Type);
43124312
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(callable_o))->co_flags;
43134313
PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : Py_NewRef(PyFunction_GET_GLOBALS(callable_o));
4314-
new_frame = _PyEvalFramePushAndInit(
4314+
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
43154315
tstate, callable[0], locals,
43164316
args, positional_args, kwnames_o, frame
43174317
);
43184318
PyStackRef_CLOSE(kwnames);
43194319
// The frame has stolen all the arguments from the stack,
43204320
// so there is no need to clean them up.
43214321
SYNC_SP();
4322-
if (new_frame == NULL) {
4322+
if (temp == NULL) {
43234323
ERROR_NO_POP();
43244324
}
4325+
new_frame = temp;
43254326
}
43264327

43274328
op(_CHECK_FUNCTION_VERSION_KW, (func_version/2, callable[1], self_or_null[1], unused[oparg], kwnames -- callable[1], self_or_null[1], unused[oparg], kwnames)) {

Python/executor_cases.c.h

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 8 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)