File tree 4 files changed +48
-0
lines changed
src/Generator/Generators/CSharp
4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -1285,6 +1285,17 @@ private bool GenerateVariableGetter(Variable var)
1285
1285
} ;
1286
1286
ctx . PushMarshalKind ( MarshalKind . ReturnVariableArray ) ;
1287
1287
1288
+ if ( var . Type . Desugar ( ) . IsPointer ( ) )
1289
+ {
1290
+ var pointerType = var . Type . Desugar ( ) as PointerType ;
1291
+ while ( pointerType != null && ! pointerType . Pointee . Desugar ( ) . IsPrimitiveType ( PrimitiveType . Char ) )
1292
+ {
1293
+ ptr = $ "*{ ptr } ";
1294
+ pointerType = pointerType . Pointee . Desugar ( ) as PointerType ;
1295
+ }
1296
+ ptr = $ "(IntPtr*)({ ptr } )";
1297
+ }
1298
+
1288
1299
var arrayType = var . Type . Desugar ( ) as ArrayType ;
1289
1300
var isRefTypeArray = arrayType != null && var . Namespace is Class context && context . IsRefType ;
1290
1301
var elementType = arrayType ? . Type . Desugar ( ) ;
Original file line number Diff line number Diff line change @@ -1988,4 +1988,11 @@ public void TestCallByValueCppToCSharpPointer()
1988
1988
Assert . That ( RuleOfThreeTester . CopyConstructorCalls , Is . EqualTo ( 0 ) ) ;
1989
1989
Assert . That ( RuleOfThreeTester . CopyAssignmentCalls , Is . EqualTo ( 0 ) ) ;
1990
1990
}
1991
+
1992
+ [ Test ]
1993
+ public void TestPointerToClass ( )
1994
+ {
1995
+ Assert . IsTrue ( CSharp . CSharp . PointerToClass . IsDefaultInstance ) ;
1996
+ Assert . IsTrue ( CSharp . CSharp . PointerToClass . IsValid ) ;
1997
+ }
1991
1998
}
Original file line number Diff line number Diff line change @@ -1772,3 +1772,22 @@ void CallCallByValueInterfacePointer(CallByValueInterface* interface)
1772
1772
RuleOfThreeTester value;
1773
1773
interface->CallByPointer (&value);
1774
1774
}
1775
+
1776
+ static PointerTester internalPointerTesterInstance;
1777
+
1778
+ PointerTester::PointerTester ()
1779
+ {
1780
+ a = 0 ;
1781
+ }
1782
+
1783
+ bool PointerTester::IsDefaultInstance ()
1784
+ {
1785
+ return this == &internalPointerTesterInstance;
1786
+ }
1787
+
1788
+ bool PointerTester::IsValid ()
1789
+ {
1790
+ return a == 0 ;
1791
+ }
1792
+
1793
+ PointerTester* PointerToClass = &internalPointerTesterInstance;
Original file line number Diff line number Diff line change @@ -1592,3 +1592,14 @@ struct DLL_API CallByValueInterface {
1592
1592
void DLL_API CallCallByValueInterfaceValue (CallByValueInterface*);
1593
1593
void DLL_API CallCallByValueInterfaceReference (CallByValueInterface*);
1594
1594
void DLL_API CallCallByValueInterfacePointer (CallByValueInterface*);
1595
+
1596
+ class DLL_API PointerTester
1597
+ {
1598
+ int a;
1599
+ public:
1600
+ PointerTester ();
1601
+ bool IsDefaultInstance ();
1602
+ bool IsValid ();
1603
+ };
1604
+
1605
+ DLL_API extern PointerTester* PointerToClass;
You can’t perform that action at this time.
0 commit comments