From 125d652dd9a5d960aeb04f87b130a1a7b1aa72ae Mon Sep 17 00:00:00 2001 From: Salvage <29021710+Saalvage@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:26:03 +0200 Subject: [PATCH] Fix non-void returning functions with value-type out parameters Also fixes indentation --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 2 +- tests/dotnet/CSharp/CSharp.Tests.cs | 2 +- tests/dotnet/CSharp/CSharp.cpp | 3 ++- tests/dotnet/CSharp/CSharp.h | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index df793b567..771064533 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -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 { diff --git a/tests/dotnet/CSharp/CSharp.Tests.cs b/tests/dotnet/CSharp/CSharp.Tests.cs index b44b59525..ecf73afe9 100644 --- a/tests/dotnet/CSharp/CSharp.Tests.cs +++ b/tests/dotnet/CSharp/CSharp.Tests.cs @@ -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); } diff --git a/tests/dotnet/CSharp/CSharp.cpp b/tests/dotnet/CSharp/CSharp.cpp index fc909ee5d..9a8beb618 100644 --- a/tests/dotnet/CSharp/CSharp.cpp +++ b/tests/dotnet/CSharp/CSharp.cpp @@ -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; } diff --git a/tests/dotnet/CSharp/CSharp.h b/tests/dotnet/CSharp/CSharp.h index 9d4e669b3..fcc638f50 100644 --- a/tests/dotnet/CSharp/CSharp.h +++ b/tests/dotnet/CSharp/CSharp.h @@ -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);