Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/5966.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add non-limited API counterpart of bytearrayobject.rs
18 changes: 0 additions & 18 deletions pyo3-ffi/src/bytearrayobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@ use crate::object::*;
use crate::pyport::Py_ssize_t;
use std::ffi::{c_char, c_int};

#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
#[repr(C)]
pub struct PyByteArrayObject {
pub ob_base: PyVarObject,
pub ob_alloc: Py_ssize_t,
pub ob_bytes: *mut c_char,
pub ob_start: *mut c_char,
#[cfg(Py_3_9)]
pub ob_exports: Py_ssize_t,
#[cfg(not(Py_3_9))]
pub ob_exports: c_int,
#[cfg(Py_3_15)]
pub ob_bytes_object: *mut PyObject,
}

#[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
opaque_struct!(pub PyByteArrayObject);

extern_libpython! {
#[cfg_attr(PyPy, link_name = "PyPyByteArray_Type")]
pub static mut PyByteArray_Type: PyTypeObject;
Expand Down
47 changes: 47 additions & 0 deletions pyo3-ffi/src/cpython/bytearrayobject.rs
Comment thread
davidhewitt marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::object::*;
use crate::pyport::Py_ssize_t;
#[cfg(not(PyPy))]
use std::ffi::c_char;
#[cfg(not(Py_3_9))]
use std::ffi::c_int;

#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
#[repr(C)]
pub struct PyByteArrayObject {
pub ob_base: PyVarObject,
pub ob_alloc: Py_ssize_t,
pub ob_bytes: *mut c_char,
pub ob_start: *mut c_char,
#[cfg(Py_3_9)]
pub ob_exports: Py_ssize_t,
#[cfg(not(Py_3_9))]
pub ob_exports: c_int,
#[cfg(Py_3_15)]
pub ob_bytes_object: *mut PyObject,
}

#[cfg(any(PyPy, GraalPy))]
opaque_struct!(pub PyByteArrayObject);

#[inline]
#[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn PyByteArray_AS_STRING(op: *mut PyObject) -> *mut c_char {
let byte_array = op as *mut PyByteArrayObject;
(*byte_array).ob_start
}

/*
#[inline]
#[cfg(Py_GIL_DISABLED)]
pub unsafe fn PyByteArray_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
let byte_array = op as *mut PyByteArrayObject;
// _Py_atomic_load_ssize_relaxed and _PyVarObject_CAST not implemented
return _Py_atomic_load_ssize_relaxed(&(_PyVarObject_CAST(byte_array)->ob_size));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be ok with defining these functions with pub(crate) visibility in their respective headers, if we want this.

}
*/

#[inline]
#[cfg(not(Py_GIL_DISABLED))]
pub unsafe fn PyByteArray_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
Py_SIZE(op)
}
3 changes: 2 additions & 1 deletion pyo3-ffi/src/cpython/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub(crate) mod abstract_;
// skipped bytearrayobject.h
pub(crate) mod bytearrayobject;
pub(crate) mod bytesobject;
#[cfg(not(PyPy))]
pub(crate) mod ceval;
Expand Down Expand Up @@ -45,6 +45,7 @@ pub(crate) mod unicodeobject;
pub(crate) mod weakrefobject;

pub use self::abstract_::*;
pub use self::bytearrayobject::*;
pub use self::bytesobject::*;
#[cfg(not(PyPy))]
pub use self::ceval::*;
Expand Down
Loading