| 1 |
use libc::size_t; |
| 2 |
use std::ffi::c_void; |
| 3 |
|
| 4 |
extern "C" { |
| 5 |
#[cfg_attr(PyPy, link_name = "PyPyMem_RawMalloc")] |
| 6 |
pub fn PyMem_RawMalloc(size: size_t) -> *mut c_void; |
| 7 |
#[cfg_attr(PyPy, link_name = "PyPyMem_RawCalloc")] |
| 8 |
pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) -> *mut c_void; |
| 9 |
#[cfg_attr(PyPy, link_name = "PyPyMem_RawRealloc")] |
| 10 |
pub fn PyMem_RawRealloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; |
| 11 |
#[cfg_attr(PyPy, link_name = "PyPyMem_RawFree")] |
| 12 |
pub fn PyMem_RawFree(ptr: *mut c_void); |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
} |
| 19 |
|
| 20 |
#[repr(C)] |
| 21 |
#[derive(Copy, Clone)] |
| 22 |
pub enum PyMemAllocatorDomain { |
| 23 |
PYMEM_DOMAIN_RAW, |
| 24 |
PYMEM_DOMAIN_MEM, |
| 25 |
PYMEM_DOMAIN_OBJ, |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
#[cfg(not(any(PyPy, GraalPy)))] |
| 30 |
#[repr(C)] |
| 31 |
#[derive(Copy, Clone)] |
| 32 |
pub struct PyMemAllocatorEx { |
| 33 |
pub ctx: *mut c_void, |
| 34 |
pub malloc: Option<extern "C" fn(ctx: *mut c_void, size: size_t) -> *mut c_void>, |
| 35 |
pub calloc: |
| 36 |
Option<extern "C" fn(ctx: *mut c_void, nelem: size_t, elsize: size_t) -> *mut c_void>, |
| 37 |
pub realloc: |
| 38 |
Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void, new_size: size_t) -> *mut c_void>, |
| 39 |
pub free: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void)>, |
| 40 |
} |
| 41 |
|
| 42 |
extern "C" { |
| 43 |
#[cfg(not(any(PyPy, GraalPy)))] |
| 44 |
pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx); |
| 45 |
#[cfg(not(any(PyPy, GraalPy)))] |
| 46 |
pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx); |
| 47 |
#[cfg(not(any(PyPy, GraalPy)))] |
| 48 |
pub fn PyMem_SetupDebugHooks(); |
| 49 |
} |