Browse Source

Fixed the generated C# for an array of const char*.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/791/head
Dimitar Dobrev 9 years ago
parent
commit
e2a2e8df4b
  1. 3
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 8
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  3. 4
      tests/CSharp/CSharp.cpp
  4. 2
      tests/CSharp/CSharp.h

3
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -464,6 +464,9 @@ namespace CppSharp.Generators.CSharp @@ -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;

8
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -90,11 +90,10 @@ namespace CppSharp.Generators.CSharp @@ -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 @@ -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));

4
tests/CSharp/CSharp.cpp

@ -1306,3 +1306,7 @@ void HasGetterAndOverriddenSetter::setBaseSetter(int value) @@ -1306,3 +1306,7 @@ void HasGetterAndOverriddenSetter::setBaseSetter(int value)
{
field = value;
}
void hasArrayOfConstChar(const char* const arrayOfConstChar[])
{
}

2
tests/CSharp/CSharp.h

@ -1149,3 +1149,5 @@ public: @@ -1149,3 +1149,5 @@ public:
protected:
int field;
};
void DLL_API hasArrayOfConstChar(const char* const arrayOfConstChar[]);

Loading…
Cancel
Save