Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
44 changes: 44 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,44 @@
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))]
Comment thread
clin1234 marked this conversation as resolved.
Outdated
opaque_struct!(pub PyByteArrayObject);

#[inline]
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 {
let byte_array = op as *mut PyByteArrayObject;
Py_SIZE(byte_array)
}
Loading