Newer
Older
vengine / external / rpmalloc-sys / src / lib.rs
Maple Nebel Maple Nebel 9 days ago 2 KB things
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

use std::ffi::{c_int, c_void};

use libc::size_t;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
#[cfg(feature = "override")]
#[allow(unsafe_op_in_unsafe_fn)]
mod set_up_statics {
    use super::*;
    /*
    #[unsafe(no_mangle)]
    unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
        rpmalloc(size)
    }
    #[unsafe(no_mangle)]
    unsafe extern "C" fn calloc(num: size_t, size: size_t) -> *mut c_void {
        rpcalloc(num, size)
    }
    #[unsafe(no_mangle)]
    unsafe extern "C" fn posix_memalign(
        ptr: *mut *mut c_void,
        alignment: size_t,
        size: size_t,
    ) -> c_int {
        rpposix_memalign(ptr, alignment, size)
    }
    #[unsafe(no_mangle)]
    unsafe extern "C" fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void {
        rpaligned_alloc(alignment, size)
    }
    #[unsafe(no_mangle)]
    unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void {
        rprealloc(ptr, size)
    }
    #[unsafe(no_mangle)]
    unsafe extern "C" fn free(ptr: *mut c_void) {
        rpfree(ptr)
    }
    #[unsafe(no_mangle)]
    unsafe extern "C" fn malloc_usable_size(ptr: *const c_void) -> size_t {
        rpmalloc_usable_size(ptr as _)
    }*/
    unsafe extern "C" {
        fn malloc(size: size_t) -> *mut c_void;
        fn calloc(num: size_t, size: size_t) -> *mut c_void;
        fn posix_memalign(ptr: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int;
        fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
        fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
        fn free(ptr: *mut c_void);
    }
    #[used]
    static USED_MALLOC: unsafe extern "C" fn(usize) -> *mut c_void = malloc;
    #[used]
    static USED_CALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void = calloc;
    #[used]
    static USED_POSIX_MEMALIGN: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
        posix_memalign;
    #[used]
    static USED_ALIGNED_ALLOC: unsafe extern "C" fn(usize, usize) -> *mut c_void = aligned_alloc;
    #[used]
    static USED_REALLOC: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = realloc;
    #[used]
    static USED_FREE: unsafe extern "C" fn(*mut c_void) = free;
}