From 78c3db80aa2ddb05a26cf2105bc84db5d91c5850 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 4 Aug 2015 18:36:52 +0300 Subject: [PATCH] Fixed incompilable code when a virtual function has ref params. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 11 ++++++----- tests/CSharpTemp/CSharpTemp.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index f9853a67..13887bf0 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -284,10 +284,10 @@ namespace CppSharp.Generators.CSharp if (parameter.Usage == ParameterUsage.Unknown || parameter.IsIn) return base.VisitParameterDecl(parameter); - var ctx = new CSharpMarshalContext(base.Context.Driver) + var ctx = new CSharpMarshalContext(Context.Driver) { - ReturnType = base.Context.ReturnType, - ReturnVarName = base.Context.ReturnVarName + ReturnType = Context.ReturnType, + ReturnVarName = Context.ReturnVarName }; var marshal = new CSharpMarshalNativeToManagedPrinter(ctx); @@ -296,13 +296,14 @@ namespace CppSharp.Generators.CSharp if (!string.IsNullOrWhiteSpace(ctx.SupportBefore)) Context.SupportBefore.WriteLine(ctx.SupportBefore); - if (!string.IsNullOrWhiteSpace(ctx.Return)) + if (!string.IsNullOrWhiteSpace(ctx.Return) && !parameter.IsPrimitiveParameterConvertibleToRef()) { Context.SupportBefore.WriteLine("var _{0} = {1};", parameter.Name, ctx.Return); } - Context.Return.Write("_{0}", parameter.Name); + Context.Return.Write("{0}{1}", + parameter.IsPrimitiveParameterConvertibleToRef() ? "ref *" : "_", parameter.Name); return true; } diff --git a/tests/CSharpTemp/CSharpTemp.h b/tests/CSharpTemp/CSharpTemp.h index bc6f1a0b..eb0d0889 100644 --- a/tests/CSharpTemp/CSharpTemp.h +++ b/tests/CSharpTemp/CSharpTemp.h @@ -624,7 +624,7 @@ class DLL_API MultiOverloadPtrToRef public: void funcPrimitivePtrToRef(int *pOne, char* pTwo, float* pThree, bool* pFour = 0); void funcPrimitivePtrToRefWithDefVal(int* pOne, char* pTwo, Foo* pThree, int* pFour = 0); - void funcPrimitivePtrToRefWithMultiOverload(int* pOne, char* pTwo, Foo* pThree, int* pFour = 0, long* pFive = 0); + virtual void funcPrimitivePtrToRefWithMultiOverload(int* pOne, char* pTwo, Foo* pThree, int* pFour = 0, long* pFive = 0); MultiOverloadPtrToRef(); int* ReturnPrimTypePtr();