diff --git a/pyo3-ffi/src/cpython/unicodeobject.rs b/pyo3-ffi/src/cpython/unicodeobject.rs index 1edbb0dc8a9..a4ee92827fc 100644 --- a/pyo3-ffi/src/cpython/unicodeobject.rs +++ b/pyo3-ffi/src/cpython/unicodeobject.rs @@ -1,10 +1,10 @@ #[cfg(not(PyPy))] use crate::Py_hash_t; use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_ssize_t}; -use libc::wchar_t; -use std::os::raw::{c_char, c_int, c_uint, c_void}; +use libc::{c_ushort, wchar_t}; #[cfg(Py_3_14)] use std::os::raw::c_ushort; +use std::os::raw::{c_char, c_int, c_uint, c_void}; // skipped Py_UNICODE_ISSPACE() // skipped Py_UNICODE_ISLOWER() @@ -587,6 +587,44 @@ impl PyASCIIObject { state.set_ready(val); self.state = u32::from(state); } + + /// Get the `statically_allocated` field of the [`PyASCIIObject`] state bitfield. + /// + /// Returns either `0` or `1`. + #[inline] + pub unsafe fn statically_allocated(&self) -> c_uint { + PyASCIIObjectState::from(self.state).statically_allocated() + } + + /// Set the `statically_allocated` flag of the [`PyASCIIObject`] state bitfield. + /// + /// Calling this function with an argument that is neither `0` nor `1` is invalid. + #[inline] + pub unsafe fn set_statically_allocated(&mut self, val: c_uint) { + let mut state = PyASCIIObjectState::from(self.state); + state.set_statically_allocated(val); + self.state = u32::from(state); + } + + /// Get the `statically_allocated` field of the [`PyASCIIObject`] state bitfield. + /// + /// Returns either `0` or `1`. + #[inline] + #[cfg(Py_3_14)] + pub unsafe fn statically_allocated(&self) -> c_ushort { + PyASCIIObjectState::from(self.state).statically_allocated() + } + + /// Set the `statically_allocated` flag of the [`PyASCIIObject`] state bitfield. + /// + /// Calling this function with an argument that is neither `0` nor `1` is invalid. + #[inline] + #[cfg(Py_3_14)] + pub unsafe fn set_statically_allocated(&mut self, val: c_ushort) { + let mut state = PyASCIIObjectState::from(self.state); + state.set_statically_allocated(val); + self.state = u32::from(state); + } } #[repr(C)] diff --git a/src/ffi/tests.rs b/src/ffi/tests.rs index 3396e409368..92922930554 100644 --- a/src/ffi/tests.rs +++ b/src/ffi/tests.rs @@ -158,6 +158,9 @@ fn ascii_object_bitfield() { o.set_ready(1); #[cfg(not(Py_3_12))] assert_eq!(o.ready(), 1); + + o.set_statically_allocated(1); + assert_eq!(o.statically_allocated(), 1); } }