@@ -56,46 +56,38 @@ pub struct GcStore {
5656
5757 /// An allocation counter that triggers GC when it reaches zero.
5858 ///
59- /// Initialized from the `WASMTIME_GC_ZEAL_ALLOC_COUNTER` environment
60- /// variable. Decremented on every allocation and when it hits zero, a GC is
59+ /// Decremented on every allocation and when it hits zero, a GC is
6160 /// forced and the counter is reset.
62- #[ cfg( all ( gc_zeal, feature = "std" ) ) ]
61+ #[ cfg( gc_zeal) ]
6362 gc_zeal_alloc_counter : Option < NonZeroU32 > ,
6463
6564 /// The initial value to reset the counter to after it triggers.
66- #[ cfg( all ( gc_zeal, feature = "std" ) ) ]
65+ #[ cfg( gc_zeal) ]
6766 gc_zeal_alloc_counter_init : Option < NonZeroU32 > ,
6867}
6968
7069impl GcStore {
7170 /// Create a new `GcStore`.
72- pub fn new ( allocation_index : GcHeapAllocationIndex , gc_heap : Box < dyn GcHeap > ) -> Self {
71+ pub fn new (
72+ allocation_index : GcHeapAllocationIndex ,
73+ gc_heap : Box < dyn GcHeap > ,
74+ gc_zeal_alloc_counter : Option < NonZeroU32 > ,
75+ ) -> Self {
7376 let host_data_table = ExternRefHostDataTable :: default ( ) ;
7477 let func_ref_table = FuncRefTable :: default ( ) ;
7578
76- #[ cfg( all( gc_zeal, feature = "std" ) ) ]
77- let gc_zeal_alloc_counter_init =
78- std:: env:: var ( "WASMTIME_GC_ZEAL_ALLOC_COUNTER" )
79- . ok ( )
80- . map ( |v| {
81- v. parse :: < NonZeroU32 > ( ) . unwrap_or_else ( |_| {
82- panic ! (
83- "`WASMTIME_GC_ZEAL_ALLOC_COUNTER` must be a non-zero \
84- `u32` value, got: {v}"
85- )
86- } )
87- } ) ;
79+ let _ = & gc_zeal_alloc_counter;
8880
8981 Self {
9082 allocation_index,
9183 gc_heap,
9284 host_data_table,
9385 func_ref_table,
9486 last_post_gc_allocated_bytes : None ,
95- #[ cfg( all ( gc_zeal, feature = "std" ) ) ]
96- gc_zeal_alloc_counter : gc_zeal_alloc_counter_init ,
97- #[ cfg( all ( gc_zeal, feature = "std" ) ) ]
98- gc_zeal_alloc_counter_init,
87+ #[ cfg( gc_zeal) ]
88+ gc_zeal_alloc_counter,
89+ #[ cfg( gc_zeal) ]
90+ gc_zeal_alloc_counter_init : gc_zeal_alloc_counter ,
9991 }
10092 }
10193
@@ -279,7 +271,7 @@ impl GcStore {
279271 ) -> Result < Result < VMGcRef , u64 > > {
280272 // When gc_zeal is enabled with an allocation counter, decrement it and
281273 // force a GC cycle when it reaches zero by returning a fake OOM.
282- #[ cfg( all ( gc_zeal, feature = "std" ) ) ]
274+ #[ cfg( gc_zeal) ]
283275 if let Some ( counter) = self . gc_zeal_alloc_counter . take ( ) {
284276 match NonZeroU32 :: new ( counter. get ( ) - 1 ) {
285277 Some ( c) => self . gc_zeal_alloc_counter = Some ( c) ,
0 commit comments