Remove usable_size APIs

This commit is contained in:
Tim Diekmann 2020-03-03 00:08:24 +01:00
parent cd5441faf4
commit d8e3557dba
14 changed files with 129 additions and 264 deletions

View file

@ -37,7 +37,7 @@ fn main() {
unsafe {
let layout = Layout::from_size_align(4, 2).unwrap();
let ptr = Global.alloc(layout.clone()).unwrap();
let (ptr, _) = Global.alloc(layout.clone()).unwrap();
helper::work_with(&ptr);
assert_eq!(HITS.load(Ordering::SeqCst), n + 1);
Global.dealloc(ptr, layout.clone());
@ -49,7 +49,7 @@ fn main() {
drop(s);
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
let ptr = System.alloc(layout.clone()).unwrap();
let (ptr, _) = System.alloc(layout.clone()).unwrap();
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
helper::work_with(&ptr);
System.dealloc(ptr, layout);

View file

@ -20,13 +20,13 @@ fn main() {
let n = GLOBAL.0.load(Ordering::SeqCst);
let layout = Layout::from_size_align(4, 2).unwrap();
let ptr = Global.alloc(layout.clone()).unwrap();
let (ptr, _) = Global.alloc(layout.clone()).unwrap();
helper::work_with(&ptr);
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
Global.dealloc(ptr, layout.clone());
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
let ptr = System.alloc(layout.clone()).unwrap();
let (ptr, _) = System.alloc(layout.clone()).unwrap();
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
helper::work_with(&ptr);
System.dealloc(ptr, layout);

View file

@ -41,13 +41,13 @@ unsafe fn test_triangle() -> bool {
println!("allocate({:?})", layout);
}
let ret = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
let (ptr, _) = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
if PRINT {
println!("allocate({:?}) = {:?}", layout, ret);
println!("allocate({:?}) = {:?}", layout, ptr);
}
ret.cast().as_ptr()
ptr.cast().as_ptr()
}
unsafe fn deallocate(ptr: *mut u8, layout: Layout) {
@ -63,16 +63,16 @@ unsafe fn test_triangle() -> bool {
println!("reallocate({:?}, old={:?}, new={:?})", ptr, old, new);
}
let ret = Global.realloc(NonNull::new_unchecked(ptr), old, new.size())
let (ptr, _) = Global.realloc(NonNull::new_unchecked(ptr), old, new.size())
.unwrap_or_else(|_| handle_alloc_error(
Layout::from_size_align_unchecked(new.size(), old.align())
));
if PRINT {
println!("reallocate({:?}, old={:?}, new={:?}) = {:?}",
ptr, old, new, ret);
ptr, old, new, ptr);
}
ret.cast().as_ptr()
ptr.cast().as_ptr()
}
fn idx_to_size(i: usize) -> usize { (i+1) * 10 }

View file

@ -24,29 +24,29 @@ struct Ccx {
x: isize
}
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
fn alloc(_bcx: &arena) -> &Bcx<'_> {
unsafe {
let layout = Layout::new::<Bcx>();
let ptr = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
let (ptr, _) = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
&*(ptr.as_ptr() as *const _)
}
}
fn h<'a>(bcx : &'a Bcx<'a>) -> &'a Bcx<'a> {
fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> {
return alloc(bcx.fcx.arena);
}
fn g(fcx : &Fcx) {
let bcx = Bcx { fcx: fcx };
fn g(fcx: &Fcx) {
let bcx = Bcx { fcx };
let bcx2 = h(&bcx);
unsafe {
Global.dealloc(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
}
}
fn f(ccx : &Ccx) {
fn f(ccx: &Ccx) {
let a = arena(());
let fcx = Fcx { arena: &a, ccx: ccx };
let fcx = Fcx { arena: &a, ccx };
return g(&fcx);
}