mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-05 09:23:31 +00:00
yk what we can do btree later raaaaagh pain and suffering *unleaks your box* whats thiSegmentation fault (core dumped) straight up testing it. and by it, well, let's just say. "my allocator" linked and listed the unnecesary bits? gone. reduced to atoms
30 lines
661 B
Rust
30 lines
661 B
Rust
#![feature(allocator_api)]
|
|
|
|
use std::alloc::{AllocError, Allocator, Layout, System};
|
|
use std::ptr::NonNull;
|
|
|
|
use std::boxed::Box;
|
|
|
|
struct Alloc {}
|
|
|
|
unsafe impl Allocator for Alloc {
|
|
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
|
System.allocate(layout)
|
|
}
|
|
|
|
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
|
|
System.deallocate(ptr, layout)
|
|
}
|
|
}
|
|
|
|
fn use_value(_: u32) {}
|
|
|
|
fn main() {
|
|
let alloc = Alloc {};
|
|
let boxed = Box::new_in(10, &alloc);
|
|
let theref = Box::leak(boxed);
|
|
drop(alloc);
|
|
//~^ ERROR cannot move out of `alloc` because it is borrowed
|
|
use_value(*theref)
|
|
}
|