Skip to content

Commit

Permalink
Adapt to changes in bytecodealliance/wasmtime#6338, which changes the…
Browse files Browse the repository at this point in the history
… type of raw funcrefs/externrefs from usize to void*. (#247)

Therefore we change `nuint` to `IntPtr` for these types, which although technically equivalent, better matches the native API.
  • Loading branch information
kpreisser authored May 11, 2023
1 parent df0cab2 commit d11e748
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,10 @@ internal static class Native
public static extern IntPtr wasmtime_func_type(IntPtr context, in ExternFunc func);

[DllImport(Engine.LibraryName)]
public static unsafe extern void wasmtime_func_from_raw(IntPtr context, nuint raw, out ExternFunc func);
public static unsafe extern void wasmtime_func_from_raw(IntPtr context, IntPtr raw, out ExternFunc func);

[DllImport(Engine.LibraryName)]
public static unsafe extern nuint wasmtime_func_to_raw(IntPtr context, in ExternFunc func);
public static unsafe extern IntPtr wasmtime_func_to_raw(IntPtr context, in ExternFunc func);

[DllImport(Engine.LibraryName)]
public static extern IntPtr wasm_functype_new(in ValueTypeArray parameters, in ValueTypeArray results);
Expand Down
4 changes: 2 additions & 2 deletions src/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ public static class Native
public static extern void wasmtime_externref_delete(IntPtr externref);

[DllImport(Engine.LibraryName)]
public static extern IntPtr wasmtime_externref_from_raw(IntPtr context, nuint raw);
public static extern IntPtr wasmtime_externref_from_raw(IntPtr context, IntPtr raw);

[DllImport(Engine.LibraryName)]
public static extern nuint wasmtime_externref_to_raw(IntPtr context, IntPtr externref);
public static extern IntPtr wasmtime_externref_to_raw(IntPtr context, IntPtr externref);
}

public static readonly Native.Finalizer Finalizer = (p) => GCHandle.FromIntPtr(p).Free();
Expand Down
20 changes: 10 additions & 10 deletions src/ValueRaw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ internal unsafe struct ValueRaw
public V128 v128;

[FieldOffset(0)]
public nuint funcref;
public IntPtr funcref;

[FieldOffset(0)]
public nuint externref;
public IntPtr externref;

public static IValueRawConverter<T> Converter<T>()
{
Expand Down Expand Up @@ -196,7 +196,7 @@ public Function Unbox(StoreContext storeContext, Store store, in ValueRaw valueR
{
var funcref = default(ExternFunc);

if (valueRaw.funcref != 0)
if (valueRaw.funcref != IntPtr.Zero)
{
Function.Native.wasmtime_func_from_raw(storeContext.handle, valueRaw.funcref, out funcref);
}
Expand All @@ -206,7 +206,7 @@ public Function Unbox(StoreContext storeContext, Store store, in ValueRaw valueR

public void Box(StoreContext storeContext, Store store, ref ValueRaw valueRaw, Function? value)
{
nuint funcrefInt = 0;
IntPtr funcrefPtr = IntPtr.Zero;

if (value?.IsNull is false)
{
Expand All @@ -219,10 +219,10 @@ public void Box(StoreContext storeContext, Store store, ref ValueRaw valueRaw, F
throw new InvalidOperationException("Returning a Function is only allowed when it belongs to the current store.");
}

funcrefInt = Function.Native.wasmtime_func_to_raw(storeContext.handle, value.func);
funcrefPtr = Function.Native.wasmtime_func_to_raw(storeContext.handle, value.func);
}

valueRaw.funcref = funcrefInt;
valueRaw.funcref = funcrefPtr;
}
}

Expand All @@ -238,7 +238,7 @@ private GenericValueRawConverter()
{
object? o = null;

if (valueRaw.externref != 0)
if (valueRaw.externref != IntPtr.Zero)
{
// The externref is an owned value, so we must delete it afterwards.
var externref = Value.Native.wasmtime_externref_from_raw(storeContext.handle, valueRaw.externref);
Expand All @@ -262,7 +262,7 @@ private GenericValueRawConverter()

public void Box(StoreContext storeContext, Store store, ref ValueRaw valueRaw, T value)
{
nuint externrefInt = 0;
IntPtr externrefPtr = IntPtr.Zero;

if (value is not null)
{
Expand All @@ -276,7 +276,7 @@ public void Box(StoreContext storeContext, Store store, ref ValueRaw valueRaw, T
// Note: The externref data isn't tracked by wasmtime's GC until
// it enters WebAssembly, so Store.GC() mustn't be called between
// converting the value and passing it to WebAssembly.
externrefInt = Value.Native.wasmtime_externref_to_raw(storeContext.handle, externref);
externrefPtr = Value.Native.wasmtime_externref_to_raw(storeContext.handle, externref);
}
finally
{
Expand All @@ -286,7 +286,7 @@ public void Box(StoreContext storeContext, Store store, ref ValueRaw valueRaw, T
}
}

valueRaw.externref = externrefInt;
valueRaw.externref = externrefPtr;
}
}
}

0 comments on commit d11e748

Please sign in to comment.