Browse Source

Fix marshalling for bool arrays (#1439)

* Fix marshalling for bool arrays
pull/1440/head
josetr 5 years ago committed by GitHub
parent
commit
41f0e9f72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 2
      tests/CSharp/CSharp.Tests.cs
  3. 1
      tests/CSharp/CSharp.cpp
  4. 2
      tests/CSharp/CSharp.h

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

@ -102,7 +102,7 @@ namespace CppSharp.Generators.CSharp @@ -102,7 +102,7 @@ namespace CppSharp.Generators.CSharp
}
else
{
if (arrayType.IsPrimitiveType(PrimitiveType.Bool))
if (arrayType.IsPrimitiveType(PrimitiveType.Bool) && Context.MarshalKind == MarshalKind.NativeField)
supportBefore.WriteLineIndent($@"{value}[i] = {
Context.ReturnVarName}[i] != 0;");
else if (arrayType.IsPrimitiveType(PrimitiveType.Char) &&

2
tests/CSharp/CSharp.Tests.cs

@ -746,6 +746,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -746,6 +746,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.That(StaticVariables.ChrArray, Is.EqualTo(new[] { 'A', 'B'}));
Assert.That(StaticVariables.IntArray, Is.EqualTo(new[] { 1020304050 , 1526374850 }));
Assert.That(StaticVariables.FloatArray, Is.EqualTo(new[] { 0.5020f, 0.6020f }));
Assert.That(StaticVariables.BoolArray, Is.EqualTo(new[] { false, true }));
}
[Test]
@ -776,6 +777,7 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -776,6 +777,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.That(VariablesWithInitializer.IntArray, Is.EqualTo(new[] { 1020304050, 1526374850 }));
Assert.That(VariablesWithInitializer.IntArray3, Is.EqualTo(new[] { 1020304050, 1526374850, default }));
Assert.That(VariablesWithInitializer.FloatArray, Is.EqualTo(new[] { 0.5020f, 0.6020f }));
Assert.That(VariablesWithInitializer.BoolArray, Is.EqualTo(new[] { false, true }));
}
[Test]

1
tests/CSharp/CSharp.cpp

@ -1413,6 +1413,7 @@ const std::string StaticVariables::String = "Str"; @@ -1413,6 +1413,7 @@ const std::string StaticVariables::String = "Str";
const char StaticVariables::ChrArray[2] { 'A', 'B' };
const int StaticVariables::IntArray[2] { 1020304050, 1526374850 };
const float StaticVariables::FloatArray[2] { 0.5020f, 0.6020f };
const bool StaticVariables::BoolArray[2] { false, true };
TestString::TestString() : unicodeConst(L"ქართული ენა"), unicode(0)
{

2
tests/CSharp/CSharp.h

@ -1116,6 +1116,7 @@ public: @@ -1116,6 +1116,7 @@ public:
static const char ChrArray[2];
static const int IntArray[2];
static const float FloatArray[2];
static const bool BoolArray[2];
};
static constexpr double ConstexprCreateDoubleValue(double value) {
@ -1150,6 +1151,7 @@ public: @@ -1150,6 +1151,7 @@ public:
static constexpr unsigned char ByteArray[2] { 'A', 10 };
static constexpr int IntArray[2] = { 1020304050, 1526374850 };
static constexpr int IntArray3[3] = { 1020304050, 1526374850 };
static constexpr bool BoolArray[2] { false, true };
static constexpr float FloatArray[2] { 0.5020f, 0.6020f };
};

Loading…
Cancel
Save