Skip to content

Commit 6602841

Browse files
committed
Fixed the generated C# for const void*& in parameters.
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent e2a23b8 commit 6602841

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/Generator/Generators/CSharp/CSharpMarshal.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,18 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
614614
Context.Return.Write($"({typePrinter.PrintNative(pointer)}) ");
615615

616616
if (qualifiedPointer.IsConstRefToPrimitive())
617+
{
618+
if (primitive == PrimitiveType.Void && pointee.IsAddress())
619+
{
620+
string ptr = $@"{Helpers.PtrIdentifier}{
621+
Context.ParameterIndex}";
622+
Context.Before.WriteLine($@"var {ptr} = {
623+
Context.Parameter.Name}.ToPointer();");
624+
Context.Return.Write($"&{ptr}");
625+
return true;
626+
}
617627
Context.Return.Write("&");
628+
}
618629
Context.Return.Write(Context.Parameter.Name);
619630
}
620631

src/Generator/Generators/CodeGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ public static class Helpers
523523
public static readonly string DummyIdentifier = Generator.GeneratedIdentifier("dummy");
524524
public static readonly string TargetIdentifier = Generator.GeneratedIdentifier("target");
525525
public static readonly string SlotIdentifier = Generator.GeneratedIdentifier("slot");
526+
public static readonly string PtrIdentifier = Generator.GeneratedIdentifier("ptr");
526527

527528
public static readonly string OwnsNativeInstanceIdentifier = Generator.GeneratedIdentifier("ownsNativeInstance");
528529

tests/Common/Common.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,3 +1006,7 @@ void integerOverload(long i)
10061006
void integerOverload(unsigned long i)
10071007
{
10081008
}
1009+
1010+
void takeReferenceToVoidStar(const void*& p)
1011+
{
1012+
}

tests/Common/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,3 +1480,4 @@ DLL_API void integerOverload(int i);
14801480
DLL_API void integerOverload(unsigned int i);
14811481
DLL_API void integerOverload(long i);
14821482
DLL_API void integerOverload(unsigned long i);
1483+
DLL_API void takeReferenceToVoidStar(const void*& p);

0 commit comments

Comments
 (0)