python27_sys/
memoryobject.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use libc::{c_char, c_int};

use crate::object::*;
use crate::pyport::Py_ssize_t;

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    pub static mut PyMemoryView_Type: PyTypeObject;
}

#[inline(always)]
pub unsafe fn PyMemoryView_Check(op: *mut PyObject) -> c_int {
    let u: *mut PyTypeObject = &mut PyMemoryView_Type;
    (Py_TYPE(op) == u) as c_int
}

#[inline(always)]
pub unsafe fn PyMemoryView_GET_BUFFER(op: *mut PyObject) -> *mut Py_buffer {
    &mut (*(op as *mut PyMemoryViewObject)).view
}

#[inline(always)]
pub unsafe fn PyMemoryView_GET_BASE(op: *mut PyObject) -> *mut PyObject {
    (*(op as *mut PyMemoryViewObject)).view.obj
}

#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
    pub fn PyMemoryView_GetContiguous(
        base: *mut PyObject,
        buffertype: c_int,
        fort: c_char,
    ) -> *mut PyObject;
    pub fn PyMemoryView_FromObject(base: *mut PyObject) -> *mut PyObject;
    pub fn PyMemoryView_FromBuffer(info: *mut Py_buffer) -> *mut PyObject;
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct PyMemoryViewObject {
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_next: *mut PyObject,
    #[cfg(py_sys_config = "Py_TRACE_REFS")]
    pub _ob_prev: *mut PyObject,
    pub ob_refcnt: Py_ssize_t,
    pub ob_type: *mut PyTypeObject,
    pub base: *mut PyObject,
    pub view: Py_buffer,
}