Browse Source

Fixed the marshalling of arrays.

Fixes https://github.com/mono/CppSharp/issues/680.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/696/head
Dimitar Dobrev 9 years ago
parent
commit
bcd6b226fa
  1. 4
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 9
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  3. 7
      tests/CSharp/CSharp.Tests.cs
  4. 2
      tests/CSharp/CSharp.cpp
  5. 2
      tests/CSharp/CSharp.h

4
src/Generator/Generators/CSharp/CSharpSources.cs

@ -1169,7 +1169,9 @@ namespace CppSharp.Generators.CSharp @@ -1169,7 +1169,9 @@ namespace CppSharp.Generators.CSharp
var ctx = new CSharpMarshalContext(Context)
{
ArgName = decl.Name,
ReturnVarName = (isRefTypeArray ? string.Empty : "*") + Generator.GeneratedIdentifier("ptr"),
ReturnVarName = (isRefTypeArray ||
(arrayType != null && arrayType.Type.Desugar().IsPrimitiveType()) ? string.Empty : "*")
+ Generator.GeneratedIdentifier("ptr"),
ReturnType = new QualifiedType(var.Type)
};

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

@ -139,14 +139,15 @@ namespace CppSharp.Generators.CSharp @@ -139,14 +139,15 @@ namespace CppSharp.Generators.CSharp
Type arrayType = array.Type.Desugar();
PrimitiveType primitiveType;
if (arrayType.IsPointerToPrimitiveType(out primitiveType) &&
!(arrayType is FunctionType))
if ((arrayType.IsPointerToPrimitiveType(out primitiveType) &&
!(arrayType is FunctionType)) ||
(arrayType.IsPrimitiveType() && MarshalKind != CSharpMarshalKind.NativeField))
{
if (primitiveType == PrimitiveType.Void)
{
return "void**";
return "void*";
}
return string.Format("{0}*", array.Type.Visit(this, quals));
return string.Format("{0}", array.Type.Visit(this, quals));
}
if (TypePrinterContext.Parameter != null)

7
tests/CSharp/CSharp.Tests.cs

@ -555,6 +555,13 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -555,6 +555,13 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
}
[Test]
public void TestConstantArray()
{
Assert.That(CSharp.CSharp.VariableWithFixedPrimitiveArray[0], Is.EqualTo(5));
Assert.That(CSharp.CSharp.VariableWithFixedPrimitiveArray[1], Is.EqualTo(10));
}
[Test]
public void TestOverrideVirtualWithString()
{

2
tests/CSharp/CSharp.cpp

@ -1064,3 +1064,5 @@ bool HasVirtualTakesReturnsProblematicTypes::callsVirtualToReturnBool(bool b) @@ -1064,3 +1064,5 @@ bool HasVirtualTakesReturnsProblematicTypes::callsVirtualToReturnBool(bool b)
{
return virtualTakesAndReturnsBool(b);
}
extern const unsigned char variableWithFixedPrimitiveArray[2] = { 5, 10 };

2
tests/CSharp/CSharp.h

@ -980,3 +980,5 @@ public: @@ -980,3 +980,5 @@ public:
virtual bool virtualTakesAndReturnsBool(bool b);
bool callsVirtualToReturnBool(bool b);
};
extern const unsigned char DLL_API variableWithFixedPrimitiveArray[2];

Loading…
Cancel
Save