File tree 1 file changed +18
-0
lines changed 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,27 @@ extern crate proc_macro2;
2
2
3
3
use proc_macro2:: watt;
4
4
use proc_macro2:: watt:: buffer:: InputBuffer ;
5
+ use std:: alloc:: { GlobalAlloc , Layout , System } ;
5
6
use std:: io:: { self , Read , Write } ;
6
7
use std:: sync:: atomic:: Ordering ;
7
8
9
+ struct MonotonicAllocator ;
10
+
11
+ #[ global_allocator]
12
+ static ALLOCATOR : MonotonicAllocator = MonotonicAllocator ;
13
+
14
+ unsafe impl GlobalAlloc for MonotonicAllocator {
15
+ unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
16
+ System . alloc ( layout)
17
+ }
18
+
19
+ unsafe fn dealloc ( & self , _ptr : * mut u8 , _layout : Layout ) {
20
+ // Leak: this cuts 3% of code size from the precompiled macro binary.
21
+ // There is no way that serde_derive would fill up all memory on the
22
+ // host. When the subprocess exits, operating system will clean this up.
23
+ }
24
+ }
25
+
8
26
fn main ( ) {
9
27
let mut buf = Vec :: new ( ) ;
10
28
io:: stdin ( ) . read_to_end ( & mut buf) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments