2024-02-16 20:02:50 +00:00
|
|
|
//@ no-prefer-dynamic
|
2017-06-03 21:54:08 +00:00
|
|
|
|
2018-07-23 02:14:42 +00:00
|
|
|
#![feature(allocator_api)]
|
2017-06-03 21:54:08 +00:00
|
|
|
#![crate_type = "rlib"]
|
|
|
|
|
2018-05-31 06:57:43 +00:00
|
|
|
use std::alloc::{GlobalAlloc, System, Layout};
|
2017-06-03 21:54:08 +00:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
|
|
|
pub struct A(pub AtomicUsize);
|
|
|
|
|
2018-04-03 15:12:57 +00:00
|
|
|
unsafe impl GlobalAlloc for A {
|
2018-05-31 06:57:43 +00:00
|
|
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
2017-06-03 21:54:08 +00:00
|
|
|
self.0.fetch_add(1, Ordering::SeqCst);
|
|
|
|
System.alloc(layout)
|
|
|
|
}
|
|
|
|
|
2018-05-31 06:57:43 +00:00
|
|
|
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
2017-06-03 21:54:08 +00:00
|
|
|
self.0.fetch_add(1, Ordering::SeqCst);
|
|
|
|
System.dealloc(ptr, layout)
|
|
|
|
}
|
|
|
|
}
|