Browse Source

Handle returned pointers to std::vector in C++/CLI

Co-authored-by: Build Agent <admin@sage.com>
pull/1350/head
Ali Alamiri 6 years ago committed by GitHub
parent
commit
190cbfa2d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Generator/Types/Std/Stdlib.cs
  2. 13
      tests/CLI/CLI.Tests.cs
  3. 21
      tests/CLI/CLI.cpp
  4. 13
      tests/CLI/CLI.h

4
src/Generator/Types/Std/Stdlib.cs

@ -564,8 +564,10 @@ namespace CppSharp.Types.Std @@ -564,8 +564,10 @@ namespace CppSharp.Types.Std
ctx.Before.WriteLine(
"auto {0} = gcnew System::Collections::Generic::List<{1}>();",
tmpVarName, managedType);
string retVarName = ctx.ReturnType.Type.Desugar().IsPointer() ? $"*{ctx.ReturnVarName}" : ctx.ReturnVarName;
ctx.Before.WriteLine("for(auto _element : {0})",
ctx.ReturnVarName);
retVarName);
ctx.Before.WriteOpenBraceAndIndent();
{
var elementCtx = new MarshalContext(ctx.Context, ctx.Indentation)

13
tests/CLI/CLI.Tests.cs

@ -53,4 +53,17 @@ public class CLITests : GeneratorTestFixture @@ -53,4 +53,17 @@ public class CLITests : GeneratorTestFixture
Assert.AreEqual("ChangePassedMappedTypeNonConstRefParam", val);
}
}
[Test]
public void TestVectorPointerGetter()
{
using (VectorPointerGetter v = new VectorPointerGetter())
{
var list = v.VecPtr;
Assert.AreEqual(1, list.Count);
Assert.AreEqual("VectorPointerGetter", list[0]);
}
}
}

21
tests/CLI/CLI.cpp

@ -43,3 +43,24 @@ void TestMappedTypeNonConstRefParamConsumer::ChangePassedMappedTypeNonConstRefPa @@ -43,3 +43,24 @@ void TestMappedTypeNonConstRefParamConsumer::ChangePassedMappedTypeNonConstRefPa
{
v = "ChangePassedMappedTypeNonConstRefParam";
}
VectorPointerGetter::VectorPointerGetter()
{
vecPtr = new std::vector<std::string>();
vecPtr->push_back("VectorPointerGetter");
}
VectorPointerGetter::~VectorPointerGetter()
{
if (vecPtr)
{
auto tempVec = vecPtr;
delete vecPtr;
tempVec = nullptr;
}
}
std::vector<std::string>* VectorPointerGetter::GetVecPtr()
{
return vecPtr;
}

13
tests/CLI/CLI.h

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
#include "NestedEnumInClassTest/NestedEnumConsumer.h"
#include <ostream>
#include <vector>
// Tests for C++ types
struct DLL_API Types
@ -77,3 +78,15 @@ class DLL_API TestMappedTypeNonConstRefParamConsumer @@ -77,3 +78,15 @@ class DLL_API TestMappedTypeNonConstRefParamConsumer
public:
void ChangePassedMappedTypeNonConstRefParam(TestMappedTypeNonConstRefParam&);
};
class DLL_API VectorPointerGetter
{
public:
VectorPointerGetter();
~VectorPointerGetter();
std::vector<std::string>* GetVecPtr();
private:
std::vector<std::string>* vecPtr;
};
Loading…
Cancel
Save