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