Make fields in MemoryBlock public

This commit is contained in:
Tim Diekmann 2020-03-28 20:21:26 +01:00
parent db15fe6b38
commit bf6a46db31
13 changed files with 79 additions and 100 deletions

View file

@ -38,9 +38,9 @@ fn main() {
let layout = Layout::from_size_align(4, 2).unwrap();
let memory = Global.alloc(layout.clone(), AllocInit::Uninitialized).unwrap();
helper::work_with(&memory.ptr());
helper::work_with(&memory.ptr);
assert_eq!(HITS.load(Ordering::SeqCst), n + 1);
Global.dealloc(memory.ptr(), layout);
Global.dealloc(memory.ptr, layout);
assert_eq!(HITS.load(Ordering::SeqCst), n + 2);
let s = String::with_capacity(10);
@ -51,8 +51,8 @@ fn main() {
let memory = System.alloc(layout.clone(), AllocInit::Uninitialized).unwrap();
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
helper::work_with(&memory.ptr());
System.dealloc(memory.ptr(), layout);
helper::work_with(&memory.ptr);
System.dealloc(memory.ptr, layout);
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
}
}

View file

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

View file

@ -46,10 +46,10 @@ unsafe fn test_triangle() -> bool {
.unwrap_or_else(|_| handle_alloc_error(layout));
if PRINT {
println!("allocate({:?}) = {:?}", layout, memory.ptr());
println!("allocate({:?}) = {:?}", layout, memory.ptr);
}
memory.ptr().cast().as_ptr()
memory.ptr.cast().as_ptr()
}
unsafe fn deallocate(ptr: *mut u8, layout: Layout) {
@ -82,9 +82,9 @@ unsafe fn test_triangle() -> bool {
});
if PRINT {
println!("reallocate({:?}, old={:?}, new={:?}) = {:?}", ptr, old, new, memory.ptr());
println!("reallocate({:?}, old={:?}, new={:?}) = {:?}", ptr, old, new, memory.ptr);
}
memory.ptr().cast().as_ptr()
memory.ptr.cast().as_ptr()
}
fn idx_to_size(i: usize) -> usize {

View file

@ -28,7 +28,7 @@ fn alloc(_bcx: &arena) -> &Bcx<'_> {
let memory = Global
.alloc(layout, AllocInit::Uninitialized)
.unwrap_or_else(|_| handle_alloc_error(layout));
&*(memory.ptr().as_ptr() as *const _)
&*(memory.ptr.as_ptr() as *const _)
}
}