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

Fix Some C-API calls #316

Merged
Merged
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
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);
martindevans marked this conversation as resolved.
Show resolved Hide resolved

[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(
martindevans marked this conversation as resolved.
Show resolved Hide resolved
Handle config,
int envc,
nuint envc,
byte*[] names,
byte*[] values
);
Expand Down