From e0b8b588369d612ead3e8919aedbe6a34f15535e Mon Sep 17 00:00:00 2001 From: Ali Alamiri Date: Wed, 15 Apr 2020 14:50:45 +0100 Subject: [PATCH] Handle pointer to pointer param (#1343) Generate valid C++/CLI for passed pointers to pointers Co-authored-by: Build Agent --- src/Generator/Generators/CLI/CLIMarshal.cs | 6 ++++++ tests/Common/Common.Tests.cs | 11 +++++++++++ tests/Common/Common.cpp | 5 +++++ tests/Common/Common.h | 8 ++++++++ 4 files changed, 30 insertions(+) diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index 29979085..2bfe6580 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -550,6 +550,12 @@ namespace CppSharp.Generators.CLI 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); } diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index 9b43e029..2c79a587 100644 --- a/tests/Common/Common.Tests.cs +++ b/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); } } + + [Test] + public void TestPointerToTypedefPointerTestMethod() + { + using (PointerToTypedefPointerTest lp = new PointerToTypedefPointerTest()) + { + lp.Val = 50; + Common.PointerToTypedefPointerTestMethod(lp, 100); + Assert.AreEqual(100, lp.Val); + } + } } diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index 008bce56..e84aded2 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -1192,3 +1192,8 @@ int NonPrimitiveType::GetFoo() TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays() { } + +void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet) +{ + (*(*lp)).val = valToSet; +} \ No newline at end of file diff --git a/tests/Common/Common.h b/tests/Common/Common.h index 0241b08c..c0fe4568 100644 --- a/tests/Common/Common.h +++ b/tests/Common/Common.h @@ -1596,3 +1596,11 @@ class TemplateClass : TemplateClassBase { using Func = std::function; explicit TemplateClass(Func function) {} }; + +struct DLL_API PointerToTypedefPointerTest +{ + int val; +}; +typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest; + +void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet); \ No newline at end of file