Add Wasmtime C API function to control linker shadowing.

This commit is contained in:
Peter Huene
2020-03-26 11:26:04 -07:00
parent 2d43d5a8fa
commit 382f68c620
5 changed files with 25 additions and 11 deletions

View File

@@ -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,

View File

@@ -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]

View File

@@ -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;

View File

@@ -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);