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 Instance.GetMemories() ignored memories after the 1st non-memory export #326

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 20 additions & 8 deletions src/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,15 @@ public Instance(Store store, Module module, params object[] imports)
{
for (var i = 0; i < int.MaxValue; i++)
{
if (TryGetExtern(i, ExternKind.Func) is not var (name, @extern))
if (TryGetExtern(i) is not var (name, @extern))
{
break;
}

yield return (name, _store.GetCachedExtern(@extern.of.func));
if (@extern.kind == ExternKind.Func)
{
yield return (name, _store.GetCachedExtern(@extern.of.func));
}
}

GC.KeepAlive(_store);
Expand All @@ -607,12 +610,15 @@ public Instance(Store store, Module module, params object[] imports)
{
for (var i = 0; i < int.MaxValue; i++)
{
if (TryGetExtern(i, ExternKind.Table) is not var (name, @extern))
if (TryGetExtern(i) is not var (name, @extern))
{
break;
}

yield return (name, new Table(_store, @extern.of.table));
if (@extern.kind == ExternKind.Table)
{
yield return (name, new Table(_store, @extern.of.table));
}
}

GC.KeepAlive(_store);
Expand All @@ -626,12 +632,15 @@ public Instance(Store store, Module module, params object[] imports)
{
for (var i = 0; i < int.MaxValue; i++)
{
if (TryGetExtern(i, ExternKind.Memory) is not var (name, @extern))
if (TryGetExtern(i) is not var (name, @extern))
{
break;
}

yield return (name, _store.GetCachedExtern(@extern.of.memory));
if (@extern.kind == ExternKind.Memory)
{
yield return (name, _store.GetCachedExtern(@extern.of.memory));
}
}

GC.KeepAlive(_store);
Expand All @@ -645,12 +654,15 @@ public Instance(Store store, Module module, params object[] imports)
{
for (var i = 0; i < int.MaxValue; i++)
{
if (TryGetExtern(i, ExternKind.Global) is not var (name, @extern))
if (TryGetExtern(i) is not var (name, @extern))
{
break;
}

yield return (name, _store.GetCachedExtern(@extern.of.global));
if (@extern.kind == ExternKind.Global)
{
yield return (name, _store.GetCachedExtern(@extern.of.global));
}
}

GC.KeepAlive(_store);
Expand Down