tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

lib.rs (1055B)


      1 mod hb;
      2 use hb::*;
      3 
      4 #[cfg(feature = "font")]
      5 mod font;
      6 #[cfg(feature = "shape")]
      7 mod shape;
      8 
      9 use std::alloc::{GlobalAlloc, Layout};
     10 use std::os::raw::c_void;
     11 
     12 struct MyAllocator;
     13 
     14 unsafe impl GlobalAlloc for MyAllocator {
     15    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
     16        assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>());
     17        hb_malloc(layout.size()) as *mut u8
     18    }
     19 
     20    unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
     21        assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>());
     22        hb_calloc(layout.size(), 1) as *mut u8
     23    }
     24 
     25    unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
     26        assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>());
     27        hb_realloc(ptr as *mut c_void, new_size) as *mut u8
     28    }
     29 
     30    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
     31        assert!(layout.align() <= 2 * std::mem::size_of::<*mut u8>());
     32        hb_free(ptr as *mut c_void);
     33    }
     34 }
     35 
     36 #[global_allocator]
     37 static GLOBAL: MyAllocator = MyAllocator;