Skip to content

Commit

Permalink
graalpy: frame, code, method, and function objects access from C API …
Browse files Browse the repository at this point in the history
…is mostly missing
  • Loading branch information
timfel committed Mar 25, 2024
1 parent 4321aad commit 7e9987e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
15 changes: 9 additions & 6 deletions pyo3-ffi/src/cpython/frameobject.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#[cfg(not(GraalPy))]
use crate::cpython::code::PyCodeObject;
use crate::object::*;
#[cfg(not(GraalPy))]
use crate::pystate::PyThreadState;
#[cfg(not(any(PyPy, Py_3_11)))]
#[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
use std::os::raw::c_char;
use std::os::raw::c_int;
use std::ptr::addr_of_mut;

#[cfg(not(any(PyPy, Py_3_11)))]
#[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub type PyFrameState = c_char;

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(any(PyPy, Py_3_11)))]
#[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub struct PyTryBlock {
pub b_type: c_int,
pub b_handler: c_int,
Expand All @@ -20,7 +22,7 @@ pub struct PyTryBlock {

#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(any(PyPy, Py_3_11)))]
#[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub struct PyFrameObject {
pub ob_base: PyVarObject,
pub f_back: *mut PyFrameObject,
Expand Down Expand Up @@ -51,7 +53,7 @@ pub struct PyFrameObject {
pub f_localsplus: [*mut PyObject; 1],
}

#[cfg(any(PyPy, Py_3_11))]
#[cfg(any(PyPy, GraalPy, Py_3_11))]
opaque_struct!(PyFrameObject);

// skipped _PyFrame_IsRunnable
Expand All @@ -69,6 +71,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
}

extern "C" {
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "PyPyFrame_New")]
pub fn PyFrame_New(
tstate: *mut PyThreadState,
Expand All @@ -79,7 +82,7 @@ extern "C" {
// skipped _PyFrame_New_NoTrack

pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int);
#[cfg(not(any(PyPy, Py_3_11)))]
#[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;

pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int);
Expand Down
6 changes: 6 additions & 0 deletions pyo3-ffi/src/cpython/methodobject.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::object::*;
#[cfg(not(GraalPy))]
use crate::{PyCFunctionObject, PyMethodDefPointer, METH_METHOD, METH_STATIC};
use std::os::raw::c_int;
use std::ptr::addr_of_mut;

#[cfg(not(GraalPy))]
pub struct PyCMethodObject {
pub func: PyCFunctionObject,
pub mm_class: *mut PyTypeObject,
Expand All @@ -23,6 +25,7 @@ pub unsafe fn PyCMethod_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, addr_of_mut!(PyCMethod_Type))
}

#[cfg(not(GraalPy))]
#[inline]
pub unsafe fn PyCFunction_GET_FUNCTION(func: *mut PyObject) -> PyMethodDefPointer {
debug_assert_eq!(PyCMethod_Check(func), 1);
Expand All @@ -31,6 +34,7 @@ pub unsafe fn PyCFunction_GET_FUNCTION(func: *mut PyObject) -> PyMethodDefPointe
(*(*func).m_ml).ml_meth
}

#[cfg(not(GraalPy))]
#[inline]
pub unsafe fn PyCFunction_GET_SELF(func: *mut PyObject) -> *mut PyObject {
debug_assert_eq!(PyCMethod_Check(func), 1);
Expand All @@ -43,6 +47,7 @@ pub unsafe fn PyCFunction_GET_SELF(func: *mut PyObject) -> *mut PyObject {
}
}

#[cfg(not(GraalPy))]
#[inline]
pub unsafe fn PyCFunction_GET_FLAGS(func: *mut PyObject) -> c_int {
debug_assert_eq!(PyCMethod_Check(func), 1);
Expand All @@ -51,6 +56,7 @@ pub unsafe fn PyCFunction_GET_FLAGS(func: *mut PyObject) -> c_int {
(*(*func).m_ml).ml_flags
}

#[cfg(not(GraalPy))]
#[inline]
pub unsafe fn PyCFunction_GET_CLASS(func: *mut PyObject) -> *mut PyTypeObject {
debug_assert_eq!(PyCMethod_Check(func), 1);
Expand Down
2 changes: 1 addition & 1 deletion pyo3-ffi/src/methodobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::PyObject_TypeCheck;
use std::os::raw::{c_char, c_int, c_void};
use std::{mem, ptr};

#[cfg(all(Py_3_9, not(Py_LIMITED_API)))]
#[cfg(all(Py_3_9, not(Py_LIMITED_API), not(GraalPy)))]
pub struct PyCFunctionObject {
pub ob_base: PyObject,
pub m_ml: *mut PyMethodDef,
Expand Down
2 changes: 2 additions & 0 deletions pyo3-ffi/src/pyframe.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(GraalPy))]
#[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))]
use crate::PyCodeObject;
#[cfg(not(Py_LIMITED_API))]
Expand All @@ -9,6 +10,7 @@ opaque_struct!(PyFrameObject);

extern "C" {
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
#[cfg(not(GraalPy))]
#[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))]
pub fn PyFrame_GetCode(f: *mut PyFrameObject) -> *mut PyCodeObject;
}

0 comments on commit 7e9987e

Please sign in to comment.