diff --git a/newsfragments/5978.added.md b/newsfragments/5978.added.md new file mode 100644 index 00000000000..1335d769655 --- /dev/null +++ b/newsfragments/5978.added.md @@ -0,0 +1 @@ +Add non-limited API version of `PyCellObject` and associated functions. diff --git a/pyo3-ffi/src/cpython/cellobject.rs b/pyo3-ffi/src/cpython/cellobject.rs new file mode 100644 index 00000000000..474d253aa38 --- /dev/null +++ b/pyo3-ffi/src/cpython/cellobject.rs @@ -0,0 +1,24 @@ +use crate::object::*; +use std::ffi::c_int; + +#[cfg(not(any(PyPy, GraalPy)))] +#[repr(C)] +pub struct PyCellObject { + pub ob_base: PyObject, + pub ob_ref: *mut PyObject, +} + +extern_libpython! { + pub fn PyCell_New(o: *mut PyObject) -> *mut PyObject; + pub fn PyCell_Get(o: *mut PyObject) -> *mut PyObject; + pub fn PyCell_Set(o: *mut PyObject, val: *mut PyObject) -> *mut PyObject; + pub static mut PyCell_Type: PyTypeObject; +} + +#[inline] +pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int { + Py_IS_TYPE(op, &raw mut PyCell_Type) +} + +// skipped PyCell_SET +// skipped PyCell_GET diff --git a/pyo3-ffi/src/cpython/mod.rs b/pyo3-ffi/src/cpython/mod.rs index 1f538a76937..5d79668a5d1 100644 --- a/pyo3-ffi/src/cpython/mod.rs +++ b/pyo3-ffi/src/cpython/mod.rs @@ -1,6 +1,7 @@ pub(crate) mod abstract_; pub(crate) mod bytearrayobject; pub(crate) mod bytesobject; +pub(crate) mod cellobject; #[cfg(not(PyPy))] pub(crate) mod ceval; pub(crate) mod code; @@ -47,6 +48,7 @@ pub(crate) mod weakrefobject; pub use self::abstract_::*; pub use self::bytearrayobject::*; pub use self::bytesobject::*; +pub use self::cellobject::*; #[cfg(not(PyPy))] pub use self::ceval::*; pub use self::code::*;