Skip to content

Commit 78a55e6

Browse files
clin1234Tpt
andauthored
Add non-limited PyCellObject interface (#5978)
* Implement PyCellObject and associated functions Add PyCellObject structure and related functions. * Add cellobject module to lib.rs * news * Update lib.rs * spelling Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr> * Drop macro Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr> * fmt * Define in `src/cpython/mod.rs`, not `src/lib.rs` --------- Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>
1 parent ab430d4 commit 78a55e6

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

newsfragments/5978.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add non-limited API version of `PyCellObject` and associated functions.

pyo3-ffi/src/cpython/cellobject.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::object::*;
2+
use std::ffi::c_int;
3+
4+
#[cfg(not(any(PyPy, GraalPy)))]
5+
#[repr(C)]
6+
pub struct PyCellObject {
7+
pub ob_base: PyObject,
8+
pub ob_ref: *mut PyObject,
9+
}
10+
11+
extern_libpython! {
12+
pub fn PyCell_New(o: *mut PyObject) -> *mut PyObject;
13+
pub fn PyCell_Get(o: *mut PyObject) -> *mut PyObject;
14+
pub fn PyCell_Set(o: *mut PyObject, val: *mut PyObject) -> *mut PyObject;
15+
pub static mut PyCell_Type: PyTypeObject;
16+
}
17+
18+
#[inline]
19+
pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int {
20+
Py_IS_TYPE(op, &raw mut PyCell_Type)
21+
}
22+
23+
// skipped PyCell_SET
24+
// skipped PyCell_GET

pyo3-ffi/src/cpython/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub(crate) mod abstract_;
22
pub(crate) mod bytearrayobject;
33
pub(crate) mod bytesobject;
4+
pub(crate) mod cellobject;
45
#[cfg(not(PyPy))]
56
pub(crate) mod ceval;
67
pub(crate) mod code;
@@ -48,6 +49,7 @@ pub(crate) mod weakrefobject;
4849
pub use self::abstract_::*;
4950
pub use self::bytearrayobject::*;
5051
pub use self::bytesobject::*;
52+
pub use self::cellobject::*;
5153
#[cfg(not(PyPy))]
5254
pub use self::ceval::*;
5355
pub use self::code::*;

0 commit comments

Comments
 (0)