Skip to content

Commit

Permalink
Fix bug pushing frame in _PY_FRAME_KW
Browse files Browse the repository at this point in the history
_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.

The pre-existing arrangement works fine in the default build because
PyStackRef_NULL and NULL are the same value. The error handling code
in the interpreter calls `PyStackRef_XCLOSE()` on the value, which is
a no-op. In the free-threaded build the values are not the same, so
the `PyStackRef_XCLOSE()` in the error handler will attempt to decref
a null pointer.
  • Loading branch information
mpage committed Nov 19, 2024
1 parent 2e28caa commit 98a5b4b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 4 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4289,17 +4289,19 @@ dummy_func(
assert(Py_TYPE(callable_o) == &PyFunction_Type);
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));
new_frame = _PyEvalFramePushAndInit(
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
tstate, callable[0], locals,
args, positional_args, kwnames_o, frame
);
PyStackRef_CLOSE(kwnames);
// The frame has stolen all the arguments from the stack,
// so there is no need to clean them up.
INPUTS_DEAD();
SYNC_SP();
if (new_frame == NULL) {
if (temp == NULL) {
ERROR_NO_POP();
}
new_frame = temp;
}

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)) {
Expand Down
11 changes: 7 additions & 4 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98a5b4b

Please sign in to comment.