1use libc::size_t;
2use std::os::raw::c_void;
3
4extern "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 // skipped _PyMem_GetCurrentAllocatorName
15 // skipped _PyMem_RawStrdup
16 // skipped _PyMem_Strdup
17 // skipped _PyMem_RawWcsdup
18}
19
20#[repr(C)]
21#[derive(Copy, Clone)]
22pub enum PyMemAllocatorDomain {
23 PYMEM_DOMAIN_RAW,
24 PYMEM_DOMAIN_MEM,
25 PYMEM_DOMAIN_OBJ,
26}
27
28// skipped PyMemAllocatorName
29#[cfg(not(PyPy))]
30#[repr(C)]
31#[derive(Copy, Clone)]
32pub 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
42extern "C" {
43 #[cfg(not(PyPy))]
44 pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx);
45 #[cfg(not(PyPy))]
46 pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx);
47 #[cfg(not(PyPy))]
48 pub fn PyMem_SetupDebugHooks();
49}
50