Skip to content

Commit

Permalink
Fix variadic generics generation
Browse files Browse the repository at this point in the history
Make sure the created `NativeGodotVariant` is stored in a local variable so it doesn't go out of scope while using it.
  • Loading branch information
raulsntos committed May 18, 2024
1 parent afabeae commit 4291d4c
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,18 @@ public override void Populate(BindingsData.CollectionContext context)
return;
}

for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant __arg{i} = global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i});");
}

writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant** args = stackalloc global::Godot.NativeInterop.NativeGodotVariant*[{genericTypeArgumentCount}]");
writer.WriteLine('{');
writer.Indent++;

for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i}).GetUnsafeAddress(),");
writer.WriteLine($"__arg{i}.GetUnsafeAddress(),");
}

writer.Indent--;
Expand Down Expand Up @@ -98,14 +103,18 @@ public override void Populate(BindingsData.CollectionContext context)
}
else
{
for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant __arg{i} = global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i});");
}

writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant** args = stackalloc global::Godot.NativeInterop.NativeGodotVariant*[{genericTypeArgumentCount}]");
writer.WriteLine('{');
writer.Indent++;

for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i}).GetUnsafeAddress(),");
writer.WriteLine($"__arg{i}.GetUnsafeAddress(),");
}

writer.Indent--;
Expand Down Expand Up @@ -153,13 +162,18 @@ public override void Populate(BindingsData.CollectionContext context)
return;
}

for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant __arg{i} = global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i});");
}

writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant** args = stackalloc global::Godot.NativeInterop.NativeGodotVariant*[{genericTypeArgumentCount}]");
writer.WriteLine('{');
writer.Indent++;

for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i}).GetUnsafeAddress(),");
writer.WriteLine($"__arg{i}.GetUnsafeAddress(),");
}

writer.Indent--;
Expand Down Expand Up @@ -198,13 +212,18 @@ public override void Populate(BindingsData.CollectionContext context)
}
else
{
for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant __arg{i} = global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i});");
}

writer.WriteLine($"global::Godot.NativeInterop.NativeGodotVariant** args = stackalloc global::Godot.NativeInterop.NativeGodotVariant*[{genericTypeArgumentCount}]");
writer.WriteLine('{');
writer.Indent++;

for (int i = 0; i < genericTypeArgumentCount; i++)
{
writer.WriteLine($"global::Godot.NativeInterop.Marshalling.ConvertToVariant<T{i}>(in parameter{i}).GetUnsafeAddress(),");
writer.WriteLine($"__arg{i}.GetUnsafeAddress(),");
}

writer.Indent--;
Expand Down

0 comments on commit 4291d4c

Please sign in to comment.