Skip to content

Commit e0b8b58

Browse files
IIFEBuild Agent
andauthored
Handle pointer to pointer param (#1343)
Generate valid C++/CLI for passed pointers to pointers Co-authored-by: Build Agent <[email protected]>
1 parent 190cbfa commit e0b8b58

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

src/Generator/Generators/CLI/CLIMarshal.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
550550
return true;
551551
}
552552

553+
// Pass address of argument if the parameter is a pointer to the pointer itself.
554+
if (pointee is PointerType && !Context.Parameter.Type.IsReference())
555+
{
556+
ArgumentPrefix.Write("&");
557+
}
558+
553559
return pointer.QualifiedPointee.Visit(this);
554560
}
555561

tests/Common/Common.Tests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,4 +1073,15 @@ public void TestNonPrimitiveFixedArrays()
10731073
Assert.AreEqual(3, nonPrimitiveFixedArray.NonPrimitiveTypeArray[2].Foo);
10741074
}
10751075
}
1076+
1077+
[Test]
1078+
public void TestPointerToTypedefPointerTestMethod()
1079+
{
1080+
using (PointerToTypedefPointerTest lp = new PointerToTypedefPointerTest())
1081+
{
1082+
lp.Val = 50;
1083+
Common.PointerToTypedefPointerTestMethod(lp, 100);
1084+
Assert.AreEqual(100, lp.Val);
1085+
}
1086+
}
10761087
}

tests/Common/Common.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,3 +1192,8 @@ int NonPrimitiveType::GetFoo()
11921192
TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays()
11931193
{
11941194
}
1195+
1196+
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet)
1197+
{
1198+
(*(*lp)).val = valToSet;
1199+
}

tests/Common/Common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,3 +1596,11 @@ class TemplateClass : TemplateClassBase<A,B> {
15961596
using Func = std::function<B(XType)>;
15971597
explicit TemplateClass(Func function) {}
15981598
};
1599+
1600+
struct DLL_API PointerToTypedefPointerTest
1601+
{
1602+
int val;
1603+
};
1604+
typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest;
1605+
1606+
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);

0 commit comments

Comments
 (0)