Browse Source

Handle pointer to pointer param (#1343)

Generate valid C++/CLI for passed pointers to pointers

Co-authored-by: Build Agent <admin@sage.com>
pull/1350/head
Ali Alamiri 5 years ago committed by GitHub
parent
commit
e0b8b58836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/Generator/Generators/CLI/CLIMarshal.cs
  2. 11
      tests/Common/Common.Tests.cs
  3. 5
      tests/Common/Common.cpp
  4. 8
      tests/Common/Common.h

6
src/Generator/Generators/CLI/CLIMarshal.cs

@ -550,6 +550,12 @@ namespace CppSharp.Generators.CLI
return true; return true;
} }
// Pass address of argument if the parameter is a pointer to the pointer itself.
if (pointee is PointerType && !Context.Parameter.Type.IsReference())
{
ArgumentPrefix.Write("&");
}
return pointer.QualifiedPointee.Visit(this); return pointer.QualifiedPointee.Visit(this);
} }

11
tests/Common/Common.Tests.cs

@ -1073,4 +1073,15 @@ This is a very long string. This is a very long string. This is a very long stri
Assert.AreEqual(3, nonPrimitiveFixedArray.NonPrimitiveTypeArray[2].Foo); Assert.AreEqual(3, nonPrimitiveFixedArray.NonPrimitiveTypeArray[2].Foo);
} }
} }
[Test]
public void TestPointerToTypedefPointerTestMethod()
{
using (PointerToTypedefPointerTest lp = new PointerToTypedefPointerTest())
{
lp.Val = 50;
Common.PointerToTypedefPointerTestMethod(lp, 100);
Assert.AreEqual(100, lp.Val);
}
}
} }

5
tests/Common/Common.cpp

@ -1192,3 +1192,8 @@ int NonPrimitiveType::GetFoo()
TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays() TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays()
{ {
} }
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet)
{
(*(*lp)).val = valToSet;
}

8
tests/Common/Common.h

@ -1596,3 +1596,11 @@ class TemplateClass : TemplateClassBase<A,B> {
using Func = std::function<B(XType)>; using Func = std::function<B(XType)>;
explicit TemplateClass(Func function) {} explicit TemplateClass(Func function) {}
}; };
struct DLL_API PointerToTypedefPointerTest
{
int val;
};
typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest;
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);
Loading…
Cancel
Save