pyo3_ffi/cpython/
bytesobject.rs1use crate::object::*;
2use crate::Py_ssize_t;
3#[cfg(not(Py_LIMITED_API))]
4use std::ffi::c_char;
5use std::ffi::c_int;
6
7#[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
8#[repr(C)]
9pub struct PyBytesObject {
10 pub ob_base: PyVarObject,
11 #[cfg_attr(
12 Py_3_11,
13 deprecated(note = "Deprecated in Python 3.11 and will be removed in a future version.")
14 )]
15 pub ob_shash: crate::Py_hash_t,
16 pub ob_sval: [c_char; 1],
17}
18
19#[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
20opaque_struct!(pub PyBytesObject);
21
22extern "C" {
23 #[cfg_attr(PyPy, link_name = "_PyPyBytes_Resize")]
24 pub fn _PyBytes_Resize(bytes: *mut *mut PyObject, newsize: Py_ssize_t) -> c_int;
25}
26
27#[cfg(not(Py_LIMITED_API))]
28#[inline]
29pub unsafe fn PyBytes_AS_STRING(op: *mut PyObject) -> *const c_char {
30 #[cfg(not(any(PyPy, GraalPy)))]
31 return &(*op.cast::<PyBytesObject>()).ob_sval as *const c_char;
32 #[cfg(any(PyPy, GraalPy))]
33 return crate::PyBytes_AsString(op);
34}