Skip to content

Commit 28829a7

Browse files
Add pyframe functions to c-api (#8215)
1 parent 5e40256 commit 28829a7

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

.cspell.dict/cpython.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ pycore
191191
pyinner
192192
pydecimal
193193
pyerrors
194+
pyframe
194195
Pyfunc
195196
pylifecycle
196197
pymain

crates/capi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub mod object;
2828
pub mod osmodule;
2929
pub mod pycapsule;
3030
pub mod pyerrors;
31+
pub mod pyframe;
3132
pub mod pylifecycle;
3233
pub mod pymem;
3334
pub mod pystate;

crates/capi/src/pyframe.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::PyObject;
2+
use crate::pystate::with_vm;
3+
use rustpython_vm::frame::Frame;
4+
5+
#[unsafe(no_mangle)]
6+
pub unsafe extern "C" fn PyFrame_GetCode(frame: *mut PyObject) -> *mut PyObject {
7+
with_vm(|vm| {
8+
let frame = unsafe { &*frame }.try_downcast_ref::<Frame>(vm)?;
9+
Ok(frame.f_code())
10+
})
11+
}
12+
13+
#[unsafe(no_mangle)]
14+
pub unsafe extern "C" fn PyFrame_GetLineNumber(frame: *mut PyObject) -> core::ffi::c_int {
15+
with_vm(|vm| {
16+
let frame = unsafe { &*frame }.try_downcast_ref::<Frame>(vm)?;
17+
Ok(frame.f_lineno() as core::ffi::c_int)
18+
})
19+
}

0 commit comments

Comments
 (0)