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 compile error in Python 3.12 #58112

Merged
merged 5 commits into from
Oct 16, 2023
Merged
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
17 changes: 17 additions & 0 deletions paddle/fluid/pybind/eval_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,13 @@ int Internal_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) {
if (lasti < 0 && _Py_OPCODE(_PyCode_CODE(co)[0]) == COPY_FREE_VARS) {
/* Free vars have not been initialized -- Do that */
PyCodeObject *co = frame->f_code;
#if PY_VERSION_HEX >= 0x030c0000
PyObject *closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure;
int offset = co->co_nlocals + co->co_ncellvars;
#else
PyObject *closure = frame->f_func->func_closure;
int offset = co->co_nlocals + co->co_nplaincellvars;
#endif
for (int i = 0; i < co->co_nfreevars; ++i) {
PyObject *o = PyTuple_GET_ITEM(closure, i);
Py_INCREF(o);
Expand Down Expand Up @@ -269,6 +274,8 @@ PyFrameObject *Internal_PyFrame_New_NoTrack(PyCodeObject *code) {
return f;
}

#if PY_VERSION_HEX < 0x030c0000

PyFrameObject *Internal_PyFrame_MakeAndSetFrameObject(
_PyInterpreterFrame *frame) {
assert(frame->frame_obj == NULL);
Expand Down Expand Up @@ -387,6 +394,8 @@ void Internal_PyFrame_Clear(_PyInterpreterFrame *frame) {
Py_DECREF(frame->f_code);
}

#endif

#else
typedef PyFrameObject FrameObject;
#endif
Expand Down Expand Up @@ -449,9 +458,11 @@ inline static PyObject *eval_custom_code_py311_plus(PyThreadState *tstate,
// Create a new function object from code object. Refer to MAKE_FUNCTION.
PyFunctionObject *func =
(PyFunctionObject *)PyFunction_New((PyObject *)code, frame->f_globals);
#if PY_VERSION_HEX < 0x030c0000
Py_XINCREF(frame->f_func->func_closure);
func->func_closure = frame->f_func->func_closure;
_PyFrame_InitializeSpecials(shadow, func, NULL, code->co_nlocalsplus);
#endif

PyObject **fastlocals_old = frame->localsplus;
PyObject **fastlocals_new = shadow->localsplus;
Expand Down Expand Up @@ -483,7 +494,9 @@ inline static PyObject *eval_custom_code_py311_plus(PyThreadState *tstate,
}

PyObject *result = eval_frame_default(tstate, shadow, throw_flag);
#if PY_VERSION_HEX < 0x030c0000
Internal_PyFrame_Clear(shadow);
#endif
free(shadow);
Py_DECREF(func);
Py_DECREF(namemap);
Expand Down Expand Up @@ -558,7 +571,11 @@ static PyObject *_custom_eval_frame(PyThreadState *tstate,
// original frame. So we pass a PyInterpreterFrame to
// _PyFrame_FastToLocalsWithError directly. But this is an internal API, so we
// copy many code from CPython project into our project.
#if PY_VERSION_HEX >= 0x030c0000
if (true) {
#else
if (Internal_PyFrame_FastToLocalsWithError(frame) < 0) {
#endif
#else
if (PyFrame_FastToLocalsWithError(frame) < 0) {
#endif
Expand Down