pyo3_ffi/
memoryobject.rs

1use crate::object::*;
2use crate::pyport::Py_ssize_t;
3use std::os::raw::{c_char, c_int};
4use std::ptr::addr_of_mut;
5
6#[cfg_attr(windows, link(name = "pythonXY"))]
7extern "C" {
8    #[cfg(not(Py_LIMITED_API))]
9    pub static mut _PyManagedBuffer_Type: PyTypeObject;
10
11    #[cfg_attr(PyPy, link_name = "PyPyMemoryView_Type")]
12    pub static mut PyMemoryView_Type: PyTypeObject;
13}
14
15#[inline]
16pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int {
17    (Py_TYPE(op) == addr_of_mut!(PyMemoryView_Type)) as c_int
18}
19
20// skipped non-limited PyMemoryView_GET_BUFFER
21// skipped non-limited PyMemeryView_GET_BASE
22
23extern "C" {
24    #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromObject")]
25    pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject;
26    #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromMemory")]
27    pub fn PyMemoryView_FromMemory(
28        mem: *mut c_char,
29        size: Py_ssize_t,
30        flags: c_int,
31    ) -> *mut PyObject;
32    #[cfg(any(Py_3_11, not(Py_LIMITED_API)))]
33    #[cfg_attr(PyPy, link_name = "PyPyMemoryView_FromBuffer")]
34    pub fn PyMemoryView_FromBuffer(view: *const crate::Py_buffer) -> *mut PyObject;
35    #[cfg_attr(PyPy, link_name = "PyPyMemoryView_GetContiguous")]
36    pub fn PyMemoryView_GetContiguous(
37        base: *mut PyObject,
38        buffertype: c_int,
39        order: c_char,
40    ) -> *mut PyObject;
41}
42
43// skipped remainder of file with comment:
44/* The structs are declared here so that macros can work, but they shouldn't
45be considered public. Don't access their fields directly, use the macros
46and functions instead! */