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 non-void returning functions with value-type out parameters #1775

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/Generator/Generators/CSharp/CSharpMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
Context.Before.WriteLine("fixed ({0}.{1}* {2} = &{3}.{4})",
Context.Parameter.QualifiedType, Helpers.InternalStruct,
arg, Context.Parameter.Name, Helpers.InstanceIdentifier);
Context.HasCodeBlock = true;
Context.Before.WriteOpenBraceAndIndent();
Context.Return.Write($"new {typePrinter.IntPtrType}({arg})");
Context.Cleanup.UnindentAndWriteCloseBrace();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tests/dotnet/CSharp/CSharp.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ public void TestPointerToClass()
[Test]
public void TestValueTypeOutParameter()
{
CSharp.CSharp.ValueTypeOutParameter(out var unionTestA, out var unionTestB);
Assert.AreEqual(2, CSharp.CSharp.ValueTypeOutParameter(out var unionTestA, out var unionTestB));
Assert.AreEqual(2, unionTestA.A);
Assert.AreEqual(2, unionTestB.B);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/dotnet/CSharp/CSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,8 +1792,9 @@ bool PointerTester::IsValid()

PointerTester* PointerToClass = &internalPointerTesterInstance;

void ValueTypeOutParameter(UnionTester* testerA, UnionTester* testerB)
int ValueTypeOutParameter(UnionTester* testerA, UnionTester* testerB)
{
testerA->a = 2;
testerB->b = 2;
return 2;
}
2 changes: 1 addition & 1 deletion tests/dotnet/CSharp/CSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1609,4 +1609,4 @@ union DLL_API UnionTester {
int b;
};

void DLL_API ValueTypeOutParameter(CS_OUT UnionTester* testerA, CS_OUT UnionTester* testerB);
int DLL_API ValueTypeOutParameter(CS_OUT UnionTester* testerA, CS_OUT UnionTester* testerB);