Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SOT][3.12] Fix that frame in eval custom code was not released in tstate - step 2 #62470

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions paddle/fluid/pybind/cpython_internals.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static void Internal_clear_thread_frame(PyThreadState *tstate,
tstate->datastack_top);
tstate->c_recursion_remaining--;
assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
Internal_PyFrame_Clear(frame); // see _PyFrame_ClearExceptCode
Internal_PyFrame_ClearExceptCode(frame);
Py_DECREF(frame->f_code);
tstate->c_recursion_remaining++;
Internal_PyThreadState_PopFrame(tstate, frame);
Expand All @@ -125,7 +125,7 @@ static void Internal_clear_gen_frame(PyThreadState *tstate,
gen->gi_exc_state.previous_item = NULL;
tstate->c_recursion_remaining--;
assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame);
Internal_PyFrame_Clear(frame); // see _PyFrame_ClearExceptCode
Internal_PyFrame_ClearExceptCode(frame);
tstate->c_recursion_remaining++;
frame->previous = NULL;
}
Expand Down Expand Up @@ -584,7 +584,11 @@ static void Internal_take_ownership(PyFrameObject *f,
}

// Call on 3.11 _PyFrame_Clear is called on 3.12+ _PyFrame_ClearExceptCode
#if PY_VERSION_HEX >= 0x030c0000
void Internal_PyFrame_ClearExceptCode(_PyInterpreterFrame *frame) {
#else
void Internal_PyFrame_Clear(_PyInterpreterFrame *frame) {
#endif
/* It is the responsibility of the owning generator/coroutine
* to have cleared the enclosing generator, if any. */
assert(frame->owner != FRAME_OWNED_BY_GENERATOR ||
Expand Down
1 change: 1 addition & 0 deletions paddle/fluid/pybind/cpython_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void Internal_PyEvalFrameClearAndPop(PyThreadState *tstate,
_PyInterpreterFrame *frame);
_PyInterpreterFrame *Internal_PyThreadState_PushFrame(PyThreadState *tstate,
size_t size);
void Internal_PyFrame_ClearExceptCode(_PyInterpreterFrame *frame);
#endif

#endif
Expand Down
3 changes: 3 additions & 0 deletions paddle/fluid/pybind/eval_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ static PyObject *_custom_eval_frame(PyThreadState *tstate,
PyObject *result = PyObject_CallObject(callback, args);
Py_DECREF(args);
if (result == NULL) {
#if PY_VERSION_HEX >= 0x030C0000
Internal_PyEvalFrameClearAndPop(tstate, frame);
#endif
return NULL;
}
code = PyObject_GetAttrString(result, "code");
Expand Down