Skip to content

Commit d11e748

Browse files
authored
Adapt to changes in bytecodealliance/wasmtime#6338, which changes the 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.
1 parent df0cab2 commit d11e748

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/Function.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,10 @@ internal static class Native
724724
public static extern IntPtr wasmtime_func_type(IntPtr context, in ExternFunc func);
725725

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

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

732732
[DllImport(Engine.LibraryName)]
733733
public static extern IntPtr wasm_functype_new(in ValueTypeArray parameters, in ValueTypeArray results);

src/Value.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,10 @@ public static class Native
391391
public static extern void wasmtime_externref_delete(IntPtr externref);
392392

393393
[DllImport(Engine.LibraryName)]
394-
public static extern IntPtr wasmtime_externref_from_raw(IntPtr context, nuint raw);
394+
public static extern IntPtr wasmtime_externref_from_raw(IntPtr context, IntPtr raw);
395395

396396
[DllImport(Engine.LibraryName)]
397-
public static extern nuint wasmtime_externref_to_raw(IntPtr context, IntPtr externref);
397+
public static extern IntPtr wasmtime_externref_to_raw(IntPtr context, IntPtr externref);
398398
}
399399

400400
public static readonly Native.Finalizer Finalizer = (p) => GCHandle.FromIntPtr(p).Free();

src/ValueRaw.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ internal unsafe struct ValueRaw
2222
public V128 v128;
2323

2424
[FieldOffset(0)]
25-
public nuint funcref;
25+
public IntPtr funcref;
2626

2727
[FieldOffset(0)]
28-
public nuint externref;
28+
public IntPtr externref;
2929

3030
public static IValueRawConverter<T> Converter<T>()
3131
{
@@ -196,7 +196,7 @@ public Function Unbox(StoreContext storeContext, Store store, in ValueRaw valueR
196196
{
197197
var funcref = default(ExternFunc);
198198

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

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

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

222-
funcrefInt = Function.Native.wasmtime_func_to_raw(storeContext.handle, value.func);
222+
funcrefPtr = Function.Native.wasmtime_func_to_raw(storeContext.handle, value.func);
223223
}
224224

225-
valueRaw.funcref = funcrefInt;
225+
valueRaw.funcref = funcrefPtr;
226226
}
227227
}
228228

@@ -238,7 +238,7 @@ private GenericValueRawConverter()
238238
{
239239
object? o = null;
240240

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

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

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

289-
valueRaw.externref = externrefInt;
289+
valueRaw.externref = externrefPtr;
290290
}
291291
}
292292
}

0 commit comments

Comments
 (0)