From 519399156616ec37eb67939774ab25919575e52f Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Thu, 16 Apr 2026 14:40:10 -0400 Subject: [PATCH 1/8] Implement PyCellObject and associated functions Add PyCellObject structure and related functions. --- pyo3-ffi/src/cpython/cellobject.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pyo3-ffi/src/cpython/cellobject.rs diff --git a/pyo3-ffi/src/cpython/cellobject.rs b/pyo3-ffi/src/cpython/cellobject.rs new file mode 100644 index 00000000000..ffc537a5f32 --- /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, Py_LIMITED_API)))] +#[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) +} + +// akippws PyCell_SET +// skipped PyCell_GET From a503e0532e13d0e784c97b46a23d22bbecc20971 Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Thu, 16 Apr 2026 14:41:57 -0400 Subject: [PATCH 2/8] Add cellobject module to lib.rs --- pyo3-ffi/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyo3-ffi/src/lib.rs b/pyo3-ffi/src/lib.rs index df72ac7b23e..f1f3f6420b8 100644 --- a/pyo3-ffi/src/lib.rs +++ b/pyo3-ffi/src/lib.rs @@ -433,6 +433,7 @@ pub use self::bltinmodule::*; pub use self::boolobject::*; pub use self::bytearrayobject::*; pub use self::bytesobject::*; +pub use self::cellobject::*; pub use self::ceval::*; pub use self::codecs::*; pub use self::compile::*; @@ -496,7 +497,7 @@ mod bltinmodule; mod boolobject; mod bytearrayobject; mod bytesobject; -// skipped cellobject.h +mod cellobject; mod ceval; // skipped classobject.h mod codecs; From 8838b94a8c5b37bd53156c4b0d5aeaf76f25cf9c Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Thu, 16 Apr 2026 14:43:26 -0400 Subject: [PATCH 3/8] news --- newsfragments/5978.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/5978.added.md 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. From dc10cffc0f8447a3bae30d22e2c953495e08845d Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Thu, 16 Apr 2026 14:47:10 -0400 Subject: [PATCH 4/8] Update lib.rs --- pyo3-ffi/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyo3-ffi/src/lib.rs b/pyo3-ffi/src/lib.rs index f1f3f6420b8..2a852112029 100644 --- a/pyo3-ffi/src/lib.rs +++ b/pyo3-ffi/src/lib.rs @@ -497,7 +497,7 @@ mod bltinmodule; mod boolobject; mod bytearrayobject; mod bytesobject; -mod cellobject; +// skipped cellobject.h mod ceval; // skipped classobject.h mod codecs; From e3c4dff74e453992736c768798f82880b4b3aa6a Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Fri, 17 Apr 2026 09:53:39 -0400 Subject: [PATCH 5/8] spelling Co-authored-by: Thomas Tanon --- pyo3-ffi/src/cpython/cellobject.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyo3-ffi/src/cpython/cellobject.rs b/pyo3-ffi/src/cpython/cellobject.rs index ffc537a5f32..31d4458fa34 100644 --- a/pyo3-ffi/src/cpython/cellobject.rs +++ b/pyo3-ffi/src/cpython/cellobject.rs @@ -20,5 +20,5 @@ pub unsafe fn PyCell_Check(op: *mut PyObject) -> c_int { Py_IS_TYPE(op, &raw mut PyCell_Type) } -// akippws PyCell_SET +// skipped PyCell_SET // skipped PyCell_GET From f262603153746921fe8ff855e25631cc918dbac4 Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Fri, 17 Apr 2026 09:53:58 -0400 Subject: [PATCH 6/8] Drop macro Co-authored-by: Thomas Tanon --- pyo3-ffi/src/cpython/cellobject.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyo3-ffi/src/cpython/cellobject.rs b/pyo3-ffi/src/cpython/cellobject.rs index 31d4458fa34..01223574e59 100644 --- a/pyo3-ffi/src/cpython/cellobject.rs +++ b/pyo3-ffi/src/cpython/cellobject.rs @@ -1,7 +1,7 @@ use crate::object::*; use std::ffi::c_int; -#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))] +#[cfg(not(any(PyPy, GraalPy)))] #[repr(C)] pub struct PyCellObject { pub ob_base: PyObject, From 78d27bd778593c8e33d3530a8e7d2ba7bcc08130 Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Fri, 17 Apr 2026 14:19:29 +0000 Subject: [PATCH 7/8] fmt --- pyo3-ffi/src/cpython/cellobject.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyo3-ffi/src/cpython/cellobject.rs b/pyo3-ffi/src/cpython/cellobject.rs index 01223574e59..474d253aa38 100644 --- a/pyo3-ffi/src/cpython/cellobject.rs +++ b/pyo3-ffi/src/cpython/cellobject.rs @@ -9,15 +9,15 @@ pub struct PyCellObject { } 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; + 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) + Py_IS_TYPE(op, &raw mut PyCell_Type) } // skipped PyCell_SET From d36aa9e3604581297102cbcb4467b5d6e4ad1c17 Mon Sep 17 00:00:00 2001 From: Charlie Lin Date: Fri, 17 Apr 2026 14:42:50 +0000 Subject: [PATCH 8/8] Define in `src/cpython/mod.rs`, not `src/lib.rs` --- pyo3-ffi/src/cpython/mod.rs | 2 ++ pyo3-ffi/src/lib.rs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) 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::*; diff --git a/pyo3-ffi/src/lib.rs b/pyo3-ffi/src/lib.rs index 2a852112029..df72ac7b23e 100644 --- a/pyo3-ffi/src/lib.rs +++ b/pyo3-ffi/src/lib.rs @@ -433,7 +433,6 @@ pub use self::bltinmodule::*; pub use self::boolobject::*; pub use self::bytearrayobject::*; pub use self::bytesobject::*; -pub use self::cellobject::*; pub use self::ceval::*; pub use self::codecs::*; pub use self::compile::*;