2019-07-16 21:06:17 +03:00
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
|
pub enum AllocatorKind {
|
|
|
|
|
Global,
|
|
|
|
|
DefaultLib,
|
|
|
|
|
DefaultExe,
|
|
|
|
|
}
|
2017-06-03 14:54:08 -07:00
|
|
|
|
2019-07-16 21:06:17 +03:00
|
|
|
impl AllocatorKind {
|
|
|
|
|
pub fn fn_name(&self, base: &str) -> String {
|
|
|
|
|
match *self {
|
|
|
|
|
AllocatorKind::Global => format!("__rg_{}", base),
|
|
|
|
|
AllocatorKind::DefaultLib => format!("__rdl_{}", base),
|
|
|
|
|
AllocatorKind::DefaultExe => format!("__rde_{}", base),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-03 14:54:08 -07:00
|
|
|
|
2019-07-16 21:06:17 +03:00
|
|
|
pub enum AllocatorTy {
|
|
|
|
|
Layout,
|
|
|
|
|
Ptr,
|
|
|
|
|
ResultPtr,
|
|
|
|
|
Unit,
|
|
|
|
|
Usize,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct AllocatorMethod {
|
|
|
|
|
pub name: &'static str,
|
|
|
|
|
pub inputs: &'static [AllocatorTy],
|
|
|
|
|
pub output: AllocatorTy,
|
|
|
|
|
}
|
2017-06-03 14:54:08 -07:00
|
|
|
|
|
|
|
|
pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
|
|
|
|
|
AllocatorMethod {
|
|
|
|
|
name: "alloc",
|
|
|
|
|
inputs: &[AllocatorTy::Layout],
|
|
|
|
|
output: AllocatorTy::ResultPtr,
|
|
|
|
|
},
|
|
|
|
|
AllocatorMethod {
|
|
|
|
|
name: "dealloc",
|
|
|
|
|
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
|
|
|
|
|
output: AllocatorTy::Unit,
|
|
|
|
|
},
|
|
|
|
|
AllocatorMethod {
|
|
|
|
|
name: "realloc",
|
2018-04-03 17:12:57 +02:00
|
|
|
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Usize],
|
2017-06-03 14:54:08 -07:00
|
|
|
output: AllocatorTy::ResultPtr,
|
|
|
|
|
},
|
|
|
|
|
AllocatorMethod {
|
|
|
|
|
name: "alloc_zeroed",
|
|
|
|
|
inputs: &[AllocatorTy::Layout],
|
|
|
|
|
output: AllocatorTy::ResultPtr,
|
|
|
|
|
},
|
|
|
|
|
];
|