Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change raw funcref/externref from nuint to IntPtr #247

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}