From 6602841a3c040272ed6c162c8ee728f83f00224b Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 8 Feb 2019 18:26:32 +0200 Subject: [PATCH] Fixed the generated C# for const void*& in parameters. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 11 +++++++++++ src/Generator/Generators/CodeGenerator.cs | 1 + tests/Common/Common.cpp | 4 ++++ tests/Common/Common.h | 1 + 4 files changed, 17 insertions(+) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 372869fe..46953e2a 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -614,7 +614,18 @@ namespace CppSharp.Generators.CSharp Context.Return.Write($"({typePrinter.PrintNative(pointer)}) "); if (qualifiedPointer.IsConstRefToPrimitive()) + { + if (primitive == PrimitiveType.Void && pointee.IsAddress()) + { + string ptr = $@"{Helpers.PtrIdentifier}{ + Context.ParameterIndex}"; + Context.Before.WriteLine($@"var {ptr} = { + Context.Parameter.Name}.ToPointer();"); + Context.Return.Write($"&{ptr}"); + return true; + } Context.Return.Write("&"); + } Context.Return.Write(Context.Parameter.Name); } diff --git a/src/Generator/Generators/CodeGenerator.cs b/src/Generator/Generators/CodeGenerator.cs index a5952c32..a9706914 100644 --- a/src/Generator/Generators/CodeGenerator.cs +++ b/src/Generator/Generators/CodeGenerator.cs @@ -523,6 +523,7 @@ namespace CppSharp.Generators public static readonly string DummyIdentifier = Generator.GeneratedIdentifier("dummy"); public static readonly string TargetIdentifier = Generator.GeneratedIdentifier("target"); public static readonly string SlotIdentifier = Generator.GeneratedIdentifier("slot"); + public static readonly string PtrIdentifier = Generator.GeneratedIdentifier("ptr"); public static readonly string OwnsNativeInstanceIdentifier = Generator.GeneratedIdentifier("ownsNativeInstance"); diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 903a340d..09523f49 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -1006,3 +1006,7 @@ void integerOverload(long i) void integerOverload(unsigned long i) { } + +void takeReferenceToVoidStar(const void*& p) +{ +} diff --git a/tests/Common/Common.h b/tests/Common/Common.h index a5b3e492..c2739a43 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -1480,3 +1480,4 @@ DLL_API void integerOverload(int i); DLL_API void integerOverload(unsigned int i); DLL_API void integerOverload(long i); DLL_API void integerOverload(unsigned long i); +DLL_API void takeReferenceToVoidStar(const void*& p);