Skip to content
Open
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
1 change: 1 addition & 0 deletions newsfragments/6195.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added FFI bindings for CPython eval-frame get/set API
1 change: 1 addition & 0 deletions newsfragments/6195.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the PyUnstable_Eval_RequestCodeExtraIndex FFI binding to link to the private CPython symbol on Python versions before 3.12.
4 changes: 2 additions & 2 deletions pyo3-ffi/src/cpython/ceval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extern_libpython! {

// skipped private _PyEval_EvalFrameDefault

// was moved to the unstable API tier on Py_3_12, use link_name for older versions
#[cfg_attr(Py_3_12, link_name = "_PyEval_RequestCodeExtraIndex")]
// Was moved to the unstable API tier on Py_3_12; older versions export the private name.
#[cfg_attr(not(Py_3_12), link_name = "_PyEval_RequestCodeExtraIndex")]
pub fn PyUnstable_Eval_RequestCodeExtraIndex(func: freefunc) -> Py_ssize_t;
}

Expand Down
34 changes: 30 additions & 4 deletions pyo3-ffi/src/cpython/pystate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(all(Py_3_11, not(PyPy)))]
use crate::cpython::pyframe::_PyInterpreterFrame;
use crate::PyThreadState;
use crate::{PyFrameObject, PyInterpreterState, PyObject};
use core::ffi::c_int;
Expand All @@ -12,6 +14,20 @@ pub type Py_tracefunc = unsafe extern "C" fn(
arg: *mut PyObject,
) -> c_int;

#[cfg(all(not(Py_3_11), not(PyPy)))]
pub type _PyFrameEvalFunction = unsafe extern "C" fn(
tstate: *mut PyThreadState,
frame: *mut PyFrameObject,
throwflag: c_int,
) -> *mut PyObject;

#[cfg(all(Py_3_11, not(PyPy)))]
pub type _PyFrameEvalFunction = unsafe extern "C" fn(
tstate: *mut PyThreadState,
frame: *mut _PyInterpreterFrame,
throwflag: c_int,
) -> *mut PyObject;

pub const PyTrace_CALL: c_int = 0;
pub const PyTrace_EXCEPTION: c_int = 1;
pub const PyTrace_LINE: c_int = 2;
Expand Down Expand Up @@ -78,8 +94,18 @@ extern_libpython! {

#[cfg_attr(PyPy, link_name = "PyPyThreadState_DeleteCurrent")]
pub fn PyThreadState_DeleteCurrent();
}

// skipped private _PyFrameEvalFunction
// skipped private _PyInterpreterState_GetEvalFrameFunc
// skipped private _PyInterpreterState_SetEvalFrameFunc
#[cfg(all(not(Py_3_11), not(PyPy)))]
pub fn _PyInterpreterState_GetEvalFrameFunc(
interp: *mut PyInterpreterState,
) -> Option<_PyFrameEvalFunction>;
#[cfg(all(Py_3_11, not(PyPy)))]
pub fn _PyInterpreterState_GetEvalFrameFunc(
interp: *mut PyInterpreterState,
) -> _PyFrameEvalFunction;
#[cfg(not(PyPy))]
pub fn _PyInterpreterState_SetEvalFrameFunc(
interp: *mut PyInterpreterState,
eval_frame: Option<_PyFrameEvalFunction>,
);
}
12 changes: 12 additions & 0 deletions pyo3-ffi/src/impl_/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ macro_rules! extern_libpython_maybe_private_fn {
) => {
extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? }
};
(
[_PyInterpreterState_GetEvalFrameFunc]
$(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)?
) => {
extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? }
};
(
[_PyInterpreterState_SetEvalFrameFunc]
$(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)?
) => {
extern_libpython_cpython_private_fn! { $(#[$attrs])* $vis $name($($args)*) $(-> $ret)? }
};
(
[_PyObject_GC_New]
$(#[$attrs:meta])* $vis:vis fn $name:ident($($args:tt)*) $(-> $ret:ty)?
Expand Down
Loading