From e2a2e8df4bd37506c4eddf7b11dce04fc6dd8b9c Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 14 Mar 2017 15:42:28 +0200 Subject: [PATCH] Fixed the generated C# for an array of const char*. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 3 +++ src/Generator/Generators/CSharp/CSharpTypePrinter.cs | 8 +++++--- tests/CSharp/CSharp.cpp | 4 ++++ tests/CSharp/CSharp.h | 2 ++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 5d1cb0de..df680da4 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -464,6 +464,9 @@ namespace CppSharp.Generators.CSharp supportBefore.WriteCloseBraceIndent(); } break; + case ArrayType.ArraySize.Incomplete: + Context.Return.Write(Context.Parameter.Name); + break; default: Context.Return.Write("null"); break; diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 90e3bf5e..0d464762 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -90,11 +90,10 @@ namespace CppSharp.Generators.CSharp public override TypePrinterResult VisitArrayType(ArrayType array, TypeQualifiers quals) { + Type arrayType = array.Type.Desugar(); if (ContextKind == TypePrinterContextKind.Native && array.SizeType == ArrayType.ArraySize.Constant) { - Type arrayType = array.Type.Desugar(); - PrimitiveType primitiveType; if ((arrayType.IsPointerToPrimitiveType(out primitiveType) && !(arrayType is FunctionType)) || @@ -148,10 +147,13 @@ namespace CppSharp.Generators.CSharp // const char* and const char[] are the same so we can use a string if (array.SizeType == ArrayType.ArraySize.Incomplete && - array.Type.Desugar().IsPrimitiveType(PrimitiveType.Char) && + arrayType.IsPrimitiveType(PrimitiveType.Char) && array.QualifiedType.Qualifiers.IsConst) return "string"; + if (arrayType.IsPointerToPrimitiveType(PrimitiveType.Char)) + return "char**"; + return string.Format("{0}{1}", array.Type.Visit(this), array.SizeType == ArrayType.ArraySize.Constant ? "[]" : (ContextKind == TypePrinterContextKind.Managed ? "*" : string.Empty)); diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 71bc5ff3..b10b8a29 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -1306,3 +1306,7 @@ void HasGetterAndOverriddenSetter::setBaseSetter(int value) { field = value; } + +void hasArrayOfConstChar(const char* const arrayOfConstChar[]) +{ +} diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index aec6d0fb..fecf854a 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -1149,3 +1149,5 @@ public: protected: int field; }; + +void DLL_API hasArrayOfConstChar(const char* const arrayOfConstChar[]);