From 0e0e6623f37b64f09e0abd957e19e3490bffbef8 Mon Sep 17 00:00:00 2001 From: Erle Carrara Date: Sat, 7 Oct 2023 17:04:03 -0300 Subject: [PATCH] fix _PyFrameEvalFunction. Since python 3.11 it receives a `_PyInterpreterFrame` --- newsfragments/3500.fixed.md | 2 ++ pyo3-ffi/src/cpython/ceval.rs | 9 +++++++++ pyo3-ffi/src/cpython/mod.rs | 4 ++++ pyo3-ffi/src/cpython/pyframe.rs | 2 ++ pyo3-ffi/src/cpython/pystate.rs | 9 ++++++++- 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 newsfragments/3500.fixed.md create mode 100644 pyo3-ffi/src/cpython/pyframe.rs diff --git a/newsfragments/3500.fixed.md b/newsfragments/3500.fixed.md new file mode 100644 index 00000000000..82202564826 --- /dev/null +++ b/newsfragments/3500.fixed.md @@ -0,0 +1,2 @@ +In Python 3.11 the `_PyFrameEvalFunction` receives a `_PyInterpreterFrame` opaque struct. + diff --git a/pyo3-ffi/src/cpython/ceval.rs b/pyo3-ffi/src/cpython/ceval.rs index eb326081c9c..6df10627d2e 100644 --- a/pyo3-ffi/src/cpython/ceval.rs +++ b/pyo3-ffi/src/cpython/ceval.rs @@ -5,7 +5,16 @@ use std::os::raw::c_int; extern "C" { // skipped non-limited _PyEval_CallTracing + #[cfg(not(Py_3_11))] pub fn _PyEval_EvalFrameDefault(arg1: *mut crate::PyFrameObject, exc: c_int) -> *mut PyObject; + + #[cfg(Py_3_11)] + pub fn _PyEval_EvalFrameDefault( + tstate: *mut crate::PyThreadState, + frame: *mut crate::_PyInterpreterFrame, + exc: c_int, + ) -> *mut crate::PyObject; + pub fn _PyEval_RequestCodeExtraIndex(func: freefunc) -> c_int; pub fn PyEval_SetProfile(trace_func: Option, arg1: *mut PyObject); pub fn PyEval_SetTrace(trace_func: Option, arg1: *mut PyObject); diff --git a/pyo3-ffi/src/cpython/mod.rs b/pyo3-ffi/src/cpython/mod.rs index 57d5a3798b5..efb93eff0b2 100644 --- a/pyo3-ffi/src/cpython/mod.rs +++ b/pyo3-ffi/src/cpython/mod.rs @@ -31,6 +31,8 @@ pub(crate) mod pystate; pub(crate) mod pythonrun; // skipped sysmodule.h pub(crate) mod floatobject; +#[cfg(not(PyPy))] +pub(crate) mod pyframe; pub(crate) mod tupleobject; pub(crate) mod unicodeobject; pub(crate) mod weakrefobject; @@ -58,6 +60,8 @@ pub use self::object::*; pub use self::objimpl::*; pub use self::pydebug::*; pub use self::pyerrors::*; +#[cfg(not(PyPy))] +pub use self::pyframe::*; #[cfg(all(Py_3_8, not(PyPy)))] pub use self::pylifecycle::*; pub use self::pymem::*; diff --git a/pyo3-ffi/src/cpython/pyframe.rs b/pyo3-ffi/src/cpython/pyframe.rs new file mode 100644 index 00000000000..d0cfa0a2c6d --- /dev/null +++ b/pyo3-ffi/src/cpython/pyframe.rs @@ -0,0 +1,2 @@ +#[cfg(Py_3_11)] +opaque_struct!(_PyInterpreterFrame); diff --git a/pyo3-ffi/src/cpython/pystate.rs b/pyo3-ffi/src/cpython/pystate.rs index a70af8e8542..5481265b55d 100644 --- a/pyo3-ffi/src/cpython/pystate.rs +++ b/pyo3-ffi/src/cpython/pystate.rs @@ -69,13 +69,20 @@ extern "C" { pub fn PyThreadState_DeleteCurrent(); } -#[cfg(Py_3_9)] +#[cfg(all(Py_3_9, not(Py_3_11)))] pub type _PyFrameEvalFunction = extern "C" fn( *mut crate::PyThreadState, *mut crate::PyFrameObject, c_int, ) -> *mut crate::object::PyObject; +#[cfg(Py_3_11)] +pub type _PyFrameEvalFunction = extern "C" fn( + *mut crate::PyThreadState, + *mut crate::_PyInterpreterFrame, + c_int, +) -> *mut crate::object::PyObject; + #[cfg(Py_3_9)] extern "C" { /// Get the frame evaluation function.