Skip to content

Commit

Permalink
Fix Some C-API calls (#316)
Browse files Browse the repository at this point in the history
* Fixed breakage due to changes introduced in bytecodealliance/wasmtime@e55fa3c

* Update src/WasiConfiguration.cs

Co-authored-by: Konstantin Preißer <[email protected]>

* Update src/WasiConfiguration.cs

Co-authored-by: Konstantin Preißer <[email protected]>

---------

Co-authored-by: Konstantin Preißer <[email protected]>
  • Loading branch information
martindevans and kpreisser authored Jul 1, 2024
1 parent 704b155 commit 5e1b0e8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/WasiConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ private unsafe void SetConfigArgs(Handle config)
{
fixed (byte** arrayOfStringsPtrNamedArgs = args)
{
Native.wasi_config_set_argv(config, _args.Count, arrayOfStringsPtrNamedArgs);
// This shouldn't ever fail - it would only return false if `ToUTF8PtrArray` creates invalid UTF8 bytes!
if (!Native.wasi_config_set_argv(config, (nuint)_args.Count, arrayOfStringsPtrNamedArgs))
throw new WasmtimeException("Failed to encode string to UTF8");
}
}
finally
Expand Down Expand Up @@ -329,7 +331,9 @@ private unsafe void SetEnvironmentVariables(Handle config)

try
{
Native.wasi_config_set_env(config, _vars.Count, names, values);
// This shouldn't ever fail - it would only return false if `ToUTF8PtrArray` creates invalid UTF8 bytes!
if (!Native.wasi_config_set_env(config, (nuint)_vars.Count, names, values))
throw new WasmtimeException("Failed to encode string to UTF8");
}
finally
{
Expand Down Expand Up @@ -450,12 +454,14 @@ private static class Native
public static extern void wasi_config_delete(IntPtr config);

[DllImport(Engine.LibraryName)]
public unsafe static extern void wasi_config_set_argv(Handle config, int argc, byte** argv);
[return: MarshalAs(UnmanagedType.I1)]
public unsafe static extern bool wasi_config_set_argv(Handle config, nuint argc, byte** argv);

[DllImport(Engine.LibraryName)]
public static extern unsafe void wasi_config_set_env(
[return: MarshalAs(UnmanagedType.I1)]
public static extern unsafe bool wasi_config_set_env(
Handle config,
int envc,
nuint envc,
byte*[] names,
byte*[] values
);
Expand Down

0 comments on commit 5e1b0e8

Please sign in to comment.