brotli/ffi/
alloc_util.rs

1use alloc::{Allocator, SliceWrapper, SliceWrapperMut};
2
3use brotli_decompressor::ffi::alloc_util::SubclassableAllocator;
4use enc::BrotliAlloc;
5
6pub struct BrotliSubclassableAllocator(SubclassableAllocator);
7
8impl BrotliSubclassableAllocator {
9    pub fn new(s: SubclassableAllocator) -> BrotliSubclassableAllocator {
10        BrotliSubclassableAllocator(s)
11    }
12}
13
14#[derive(Default)]
15pub struct SendableMemoryBlock<T: Clone + Default>(
16    <SubclassableAllocator as Allocator<T>>::AllocatedMemory,
17);
18impl<T: Clone + Default> SliceWrapperMut<T> for SendableMemoryBlock<T> {
19    fn slice_mut(&mut self) -> &mut [T] {
20        self.0.slice_mut()
21    }
22}
23impl<T: Clone + Default> SliceWrapper<T> for SendableMemoryBlock<T> {
24    fn slice(&self) -> &[T] {
25        self.0.slice()
26    }
27}
28impl<T: Clone + Default> Allocator<T> for BrotliSubclassableAllocator {
29    type AllocatedMemory = SendableMemoryBlock<T>;
30    fn alloc_cell(&mut self, s: usize) -> Self::AllocatedMemory {
31        SendableMemoryBlock(self.0.alloc_cell(s))
32    }
33    fn free_cell(&mut self, data: Self::AllocatedMemory) {
34        self.0.free_cell(data.0)
35    }
36}
37
38impl BrotliAlloc for BrotliSubclassableAllocator {}
39#[cfg(not(feature = "safe"))]
40unsafe impl Send for BrotliSubclassableAllocator {}
41
42#[cfg(not(feature = "safe"))]
43unsafe impl<T: Clone + Default> Send for SendableMemoryBlock<T> {}
44
45#[cfg(not(feature = "std"))]
46#[cfg(feature = "no-stdlib-ffi-binding")]
47#[panic_handler]
48extern "C" fn panic_impl(_: &::core::panic::PanicInfo) -> ! {
49    loop {}
50}
51
52#[cfg(not(feature = "std"))]
53#[cfg(feature = "no-stdlib-ffi-binding")]
54#[lang = "eh_personality"]
55extern "C" fn eh_personality() {}