Add a wasmtime-specific wasmtime_wat2wasm C API (#1206)
* Add a wasmtime-specific `wasmtime_wat2wasm` C API This commit implements a wasmtime-specific C API for converting the text format to the binary format. An upstream spec issue exists for adding this to the C API, but in the meantime we can experiment with our own version of this API and use it in the C# extension, for example! Closes #1000 * Reorder arguments * Use wasm_byte_vec_t for input `*.wat` * Mark wat input as const * Return an error message and use `fixed` * Actually include the error message * Use `fixed` in `Module.cs` as well
This commit is contained in:
@@ -15,15 +15,13 @@ namespace Wasmtime
|
||||
throw new ArgumentNullException(nameof(store));
|
||||
}
|
||||
|
||||
var bytesHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
|
||||
try
|
||||
unsafe
|
||||
{
|
||||
unsafe
|
||||
fixed (byte *ptr = bytes)
|
||||
{
|
||||
Interop.wasm_byte_vec_t vec;
|
||||
vec.size = (UIntPtr)bytes.Length;
|
||||
vec.data = (byte*)bytesHandle.AddrOfPinnedObject();
|
||||
vec.data = ptr;
|
||||
|
||||
Handle = Interop.wasm_module_new(store.Handle, ref vec);
|
||||
}
|
||||
@@ -33,10 +31,6 @@ namespace Wasmtime
|
||||
throw new WasmtimeException($"WebAssembly module '{name}' is not valid.");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
bytesHandle.Free();
|
||||
}
|
||||
|
||||
Store = store;
|
||||
Name = name;
|
||||
|
||||
Reference in New Issue
Block a user