@@ -3,7 +3,9 @@ use crate::{
33 wasm_store_t, wasm_val_t, wasmtime_error_t, wasmtime_val_t,
44} ;
55use std:: mem:: MaybeUninit ;
6- use wasmtime:: { Extern , Global , RootScope } ;
6+ #[ cfg( feature = "gc" ) ]
7+ use wasmtime:: RootScope ;
8+ use wasmtime:: { Extern , Global } ;
79
810#[ derive( Clone ) ]
911#[ repr( transparent) ]
@@ -84,12 +86,24 @@ pub unsafe extern "C" fn wasmtime_global_new(
8486 val : & wasmtime_val_t ,
8587 ret : & mut Global ,
8688) -> Option < Box < wasmtime_error_t > > {
87- let mut scope = RootScope :: new ( & mut store) ;
88- let val = val. to_val ( & mut scope) ;
89- let global = Global :: new ( scope, gt. ty ( ) . ty . clone ( ) , val) ;
90- handle_result ( global, |global| {
91- * ret = global;
92- } )
89+ #[ cfg( feature = "gc" ) ]
90+ {
91+ let mut scope = RootScope :: new ( & mut store) ;
92+ let val = val. to_val ( & mut scope) ;
93+ let global = Global :: new ( scope, gt. ty ( ) . ty . clone ( ) , val) ;
94+ handle_result ( global, |global| {
95+ * ret = global;
96+ } )
97+ }
98+
99+ #[ cfg( not( feature = "gc" ) ) ]
100+ {
101+ let val = val. to_val_unscoped ( & mut store) ;
102+ let global = Global :: new ( & mut store, gt. ty ( ) . ty . clone ( ) , val) ;
103+ handle_result ( global, |global| {
104+ * ret = global;
105+ } )
106+ }
93107}
94108
95109#[ unsafe( no_mangle) ]
@@ -106,9 +120,20 @@ pub extern "C" fn wasmtime_global_get(
106120 global : & Global ,
107121 val : & mut MaybeUninit < wasmtime_val_t > ,
108122) {
109- let mut scope = RootScope :: new ( store) ;
110- let gval = global. get ( & mut scope) ;
111- crate :: initialize ( val, wasmtime_val_t:: from_val ( & mut scope, gval) )
123+ let mut store = store;
124+
125+ #[ cfg( feature = "gc" ) ]
126+ {
127+ let mut scope = RootScope :: new ( & mut store) ;
128+ let gval = global. get ( & mut scope) ;
129+ crate :: initialize ( val, wasmtime_val_t:: from_val ( & mut scope, gval) )
130+ }
131+
132+ #[ cfg( not( feature = "gc" ) ) ]
133+ {
134+ let gval = global. get ( & mut store) ;
135+ crate :: initialize ( val, wasmtime_val_t:: from_val_unscoped ( & mut store, gval) )
136+ }
112137}
113138
114139#[ unsafe( no_mangle) ]
@@ -117,7 +142,16 @@ pub unsafe extern "C" fn wasmtime_global_set(
117142 global : & Global ,
118143 val : & wasmtime_val_t ,
119144) -> Option < Box < wasmtime_error_t > > {
120- let mut scope = RootScope :: new ( & mut store) ;
121- let val = val. to_val ( & mut scope) ;
122- handle_result ( global. set ( scope, val) , |( ) | { } )
145+ #[ cfg( feature = "gc" ) ]
146+ {
147+ let mut scope = RootScope :: new ( & mut store) ;
148+ let val = val. to_val ( & mut scope) ;
149+ handle_result ( global. set ( scope, val) , |( ) | { } )
150+ }
151+
152+ #[ cfg( not( feature = "gc" ) ) ]
153+ {
154+ let val = val. to_val_unscoped ( & mut store) ;
155+ handle_result ( global. set ( & mut store, val) , |( ) | { } )
156+ }
123157}
0 commit comments