Skip to content

Replace Marshal with Unsafe #336

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions src/Externs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Wasmtime
[StructLayout(LayoutKind.Sequential)]
internal record struct ExternFunc
{
static ExternFunc() => Debug.Assert(Marshal.SizeOf(typeof(ExternFunc)) == 16);
static ExternFunc() => Debug.Assert(Marshal.SizeOf<ExternFunc>() == 16);

public ulong store;
public IntPtr __private;
Expand All @@ -16,11 +16,11 @@ internal record struct ExternFunc
[StructLayout(LayoutKind.Explicit)]
internal record struct ExternTable
{
static ExternTable() => Debug.Assert(Marshal.SizeOf(typeof(ExternTable)) == 24);
static ExternTable() => Debug.Assert(Marshal.SizeOf<ExternTable>() == 24);

// Use explicit offsets because the struct in the C api has extra padding
// due to field alignments. The total struct size is 24 bytes.

[FieldOffset(0)]
public ulong store;
[FieldOffset(8)]
Expand All @@ -29,15 +29,15 @@ internal record struct ExternTable
public uint __private2;
}


[StructLayout(LayoutKind.Explicit)]
internal record struct ExternMemory
{
static ExternMemory() => Debug.Assert(Marshal.SizeOf(typeof(ExternMemory)) == 24);
static ExternMemory() => Debug.Assert(Marshal.SizeOf<ExternMemory>() == 24);

// Use explicit offsets because the struct in the C api has extra padding
// due to field alignments. The total struct size is 24 bytes.

[FieldOffset(0)]
public ulong store;
[FieldOffset(8)]
Expand All @@ -49,7 +49,7 @@ internal record struct ExternMemory
[StructLayout(LayoutKind.Sequential)]
internal record struct ExternInstance
{
static ExternInstance() => Debug.Assert(Marshal.SizeOf(typeof(ExternInstance)) == 16);
static ExternInstance() => Debug.Assert(Marshal.SizeOf<ExternInstance>() == 16);

public ulong store;
public nuint __private;
Expand All @@ -58,7 +58,7 @@ internal record struct ExternInstance
[StructLayout(LayoutKind.Sequential)]
internal record struct ExternGlobal
{
static ExternGlobal() => Debug.Assert(Marshal.SizeOf(typeof(ExternMemory)) == 24);
static ExternGlobal() => Debug.Assert(Marshal.SizeOf<ExternMemory>() == 24);

public ulong store;
public uint __private1;
Expand All @@ -78,7 +78,7 @@ internal enum ExternKind : byte
[StructLayout(LayoutKind.Explicit)]
internal struct ExternUnion
{
static ExternUnion() => Debug.Assert(Marshal.SizeOf(typeof(ExternUnion)) == 24);
static ExternUnion() => Debug.Assert(Marshal.SizeOf<ExternUnion>() == 24);

[FieldOffset(0)]
public ExternFunc func;
Expand All @@ -99,8 +99,8 @@ internal struct ExternUnion
[StructLayout(LayoutKind.Sequential)]
internal struct Extern : IDisposable
{
static Extern() => Debug.Assert(Marshal.SizeOf(typeof(Extern)) == 32);
static Extern() => Debug.Assert(Marshal.SizeOf<Extern>() == 32);

public ExternKind kind;
public ExternUnion of;

Expand Down
2 changes: 1 addition & 1 deletion src/Wasmtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The .NET embedding of Wasmtime enables .NET code to instantiate WebAssembly modu
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<None Update="Function.FromCallback.tt">
<Generator>TextTemplatingFileGenerator</Generator>
Expand Down
Loading