diff --git a/crates/c-api/include/wasmtime.h b/crates/c-api/include/wasmtime.h index 7f78a44c5e..a7ed8fcd55 100644 --- a/crates/c-api/include/wasmtime.h +++ b/crates/c-api/include/wasmtime.h @@ -72,7 +72,9 @@ WASM_API_EXTERN bool wasmtime_wat2wasm( WASMTIME_DECLARE_OWN(linker) -WASM_API_EXTERN own wasmtime_linker_t* wasmtime_linker_new(wasm_store_t* store, bool allow_shadowing); +WASM_API_EXTERN own wasmtime_linker_t* wasmtime_linker_new(wasm_store_t* store); + +WASM_API_EXTERN void wasmtime_linker_allow_shadowing(wasmtime_linker_t* linker, bool allow_shadowing); WASM_API_EXTERN bool wasmtime_linker_define( wasmtime_linker_t *linker, diff --git a/crates/c-api/src/ext.rs b/crates/c-api/src/ext.rs index 5bc4231501..159b6a1635 100644 --- a/crates/c-api/src/ext.rs +++ b/crates/c-api/src/ext.rs @@ -142,13 +142,18 @@ pub struct wasmtime_linker_t { } #[no_mangle] -pub unsafe extern "C" fn wasmtime_linker_new( - store: *mut wasm_store_t, +pub unsafe extern "C" fn wasmtime_linker_new(store: *mut wasm_store_t) -> *mut wasmtime_linker_t { + Box::into_raw(Box::new(wasmtime_linker_t { + linker: Linker::new(&(*store).store.borrow()), + })) +} + +#[no_mangle] +pub unsafe extern "C" fn wasmtime_linker_allow_shadowing( + linker: *mut wasmtime_linker_t, allow_shadowing: bool, -) -> *mut wasmtime_linker_t { - let mut linker = Linker::new(&(*store).store.borrow()); - linker.allow_shadowing(allow_shadowing); - Box::into_raw(Box::new(wasmtime_linker_t { linker })) +) { + (*linker).linker.allow_shadowing(allow_shadowing); } #[no_mangle] diff --git a/crates/misc/dotnet/src/Host.cs b/crates/misc/dotnet/src/Host.cs index 92b8c05a29..95d6e98042 100644 --- a/crates/misc/dotnet/src/Host.cs +++ b/crates/misc/dotnet/src/Host.cs @@ -668,12 +668,14 @@ namespace Wasmtime { CheckDisposed(); - var linker = Interop.wasmtime_linker_new(Store, allowShadowing: true); + var linker = Interop.wasmtime_linker_new(Store); if (linker.IsInvalid) { throw new WasmtimeException("Failed to create Wasmtime linker."); } + Interop.wasmtime_linker_allow_shadowing(linker, allowShadowing: true); + Linker.Dispose(); Linker = linker; } @@ -722,12 +724,14 @@ namespace Wasmtime throw new WasmtimeException("Failed to create Wasmtime store."); } - var linker = Interop.wasmtime_linker_new(store, allowShadowing: true); + var linker = Interop.wasmtime_linker_new(store); if (linker.IsInvalid) { throw new WasmtimeException("Failed to create Wasmtime linker."); } + Interop.wasmtime_linker_allow_shadowing(linker, allowShadowing: true); + Engine = engine; Store = store; Linker = linker; diff --git a/crates/misc/dotnet/src/Interop.cs b/crates/misc/dotnet/src/Interop.cs index 7432c3cb55..32f92585ed 100644 --- a/crates/misc/dotnet/src/Interop.cs +++ b/crates/misc/dotnet/src/Interop.cs @@ -1020,7 +1020,10 @@ namespace Wasmtime // Linking functions [DllImport(LibraryName)] - public static extern LinkerHandle wasmtime_linker_new(StoreHandle store, [MarshalAs(UnmanagedType.I1)] bool allowShadowing); + public static extern LinkerHandle wasmtime_linker_new(StoreHandle store); + + [DllImport(LibraryName)] + public static extern void wasmtime_linker_allow_shadowing(LinkerHandle linker, [MarshalAs(UnmanagedType.I1)] bool allowShadowing); [DllImport(LibraryName)] public static extern void wasmtime_linker_delete(IntPtr linker); diff --git a/examples/linking.c b/examples/linking.c index 2b31d1a368..f3dc199429 100644 --- a/examples/linking.c +++ b/examples/linking.c @@ -66,7 +66,7 @@ int main() { // Create our linker which will be linking our modules together, and then add // our WASI instance to it. - wasmtime_linker_t *linker = wasmtime_linker_new(store, false); + wasmtime_linker_t *linker = wasmtime_linker_new(store); bool ok = wasmtime_linker_define_wasi(linker, wasi); assert(ok);