33#[ cfg( feature = "visualizer" ) ]
44pub ( crate ) mod visualizer;
55
6+ #[ cfg( feature = "std" ) ]
67use std:: {
78 backtrace:: Backtrace ,
89 collections:: { HashMap , HashSet } ,
@@ -32,6 +33,7 @@ pub(crate) struct MemoryChunk {
3233 pub ( crate ) allocation_type : AllocationType ,
3334 pub ( crate ) name : Option < String > ,
3435 /// Only used if [`crate::AllocatorDebugSettings::store_stack_traces`] is [`true`]
36+ #[ cfg( feature = "std" ) ]
3537 pub ( crate ) backtrace : Arc < Backtrace > ,
3638 next : Option < std:: num:: NonZeroU64 > ,
3739 prev : Option < std:: num:: NonZeroU64 > ,
@@ -79,6 +81,7 @@ impl FreeListAllocator {
7981 offset : 0 ,
8082 allocation_type : AllocationType :: Free ,
8183 name : None ,
84+ #[ cfg( feature = "std" ) ]
8285 backtrace : Arc :: new ( Backtrace :: disabled ( ) ) ,
8386 prev : None ,
8487 next : None ,
@@ -162,8 +165,8 @@ impl SubAllocator for FreeListAllocator {
162165 allocation_type : AllocationType ,
163166 granularity : u64 ,
164167 name : & str ,
165- backtrace : Arc < Backtrace > ,
166- ) -> Result < ( u64 , std :: num:: NonZeroU64 ) > {
168+ # [ cfg ( feature = "std" ) ] backtrace : Arc < Backtrace > ,
169+ ) -> Result < ( u64 , core :: num:: NonZeroU64 ) > {
167170 let free_size = self . size - self . allocated ;
168171 if size > free_size {
169172 return Err ( AllocationError :: OutOfMemory ) ;
@@ -249,6 +252,7 @@ impl SubAllocator for FreeListAllocator {
249252 offset : free_chunk. offset ,
250253 allocation_type,
251254 name : Some ( name. to_string ( ) ) ,
255+ #[ cfg( feature = "std" ) ]
252256 backtrace,
253257 prev : free_chunk. prev ,
254258 next : Some ( first_fit_id) ,
@@ -278,7 +282,10 @@ impl SubAllocator for FreeListAllocator {
278282
279283 chunk. allocation_type = allocation_type;
280284 chunk. name = Some ( name. to_string ( ) ) ;
281- chunk. backtrace = backtrace;
285+ #[ cfg( feature = "std" ) ]
286+ {
287+ chunk. backtrace = backtrace;
288+ }
282289
283290 self . remove_id_from_free_list ( first_fit_id) ;
284291
@@ -302,7 +309,10 @@ impl SubAllocator for FreeListAllocator {
302309 } ) ?;
303310 chunk. allocation_type = AllocationType :: Free ;
304311 chunk. name = None ;
305- chunk. backtrace = Arc :: new ( Backtrace :: disabled ( ) ) ;
312+ #[ cfg( feature = "std" ) ]
313+ {
314+ chunk. backtrace = Arc :: new ( Backtrace :: disabled ( ) ) ;
315+ }
306316
307317 self . allocated -= chunk. size ;
308318
@@ -363,6 +373,7 @@ impl SubAllocator for FreeListAllocator {
363373 let empty = "" . to_string ( ) ;
364374 let name = chunk. name . as_ref ( ) . unwrap_or ( & empty) ;
365375
376+ #[ cfg( feature = "std" ) ]
366377 log ! (
367378 log_level,
368379 r#"leak detected: {{
@@ -386,6 +397,28 @@ impl SubAllocator for FreeListAllocator {
386397 name,
387398 chunk. backtrace
388399 ) ;
400+ #[ cfg( not( feature = "std" ) ) ]
401+ log ! (
402+ log_level,
403+ r#"leak detected: {{
404+ memory type: {}
405+ memory block: {}
406+ chunk: {{
407+ chunk_id: {},
408+ size: 0x{:x},
409+ offset: 0x{:x},
410+ allocation_type: {:?},
411+ name: {},
412+ }}
413+ }}"# ,
414+ memory_type_index,
415+ memory_block_index,
416+ chunk_id,
417+ chunk. size,
418+ chunk. offset,
419+ chunk. allocation_type,
420+ name,
421+ ) ;
389422 }
390423 }
391424
0 commit comments