pyforge_ffi/cpython/
objimpl.rs1
2use libc::size_t;
3use std::ffi::c_int;
4
5
6use std::ffi::c_void;
7
8use crate::object::*;
9
10#[repr(C)]
15#[derive(Copy, Clone)]
16pub struct PyObjectArenaAllocator {
17 pub ctx: *mut c_void,
18 pub alloc: Option<extern "C" fn(ctx: *mut c_void, size: size_t) -> *mut c_void>,
19 pub free: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void, size: size_t)>,
20}
21
22
23impl Default for PyObjectArenaAllocator {
24 #[inline]
25 fn default() -> Self {
26 unsafe { std::mem::zeroed() }
27 }
28}
29
30extern_libpython! {
31
32 pub fn PyObject_GetArenaAllocator(allocator: *mut PyObjectArenaAllocator);
33
34 pub fn PyObject_SetArenaAllocator(allocator: *mut PyObjectArenaAllocator);
35
36 pub fn PyObject_IS_GC(o: *mut PyObject) -> c_int;
37}
38
39#[inline]
40pub unsafe fn PyType_SUPPORTS_WEAKREFS(t: *mut PyTypeObject) -> c_int {
41 ((*t).tp_weaklistoffset > 0) as c_int
42}
43
44#[inline]
45pub unsafe fn PyObject_GET_WEAKREFS_LISTPTR(o: *mut PyObject) -> *mut *mut PyObject {
46 let weaklistoffset = (*Py_TYPE(o)).tp_weaklistoffset;
47 o.offset(weaklistoffset) as *mut *mut PyObject
48}
49
50