Skip to content

Commit

Permalink
Fix non-void returning functions with value-type out parameters
Browse files Browse the repository at this point in the history
Also fixes indentation
  • Loading branch information
Saalvage authored and tritao committed Oct 18, 2023
1 parent 0c60384 commit 7f567b6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
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);

0 comments on commit 7f567b6

Please sign in to comment.