File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
src/Generator/Generators/CSharp Expand file tree Collapse file tree 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)
12851285 } ;
12861286 ctx . PushMarshalKind ( MarshalKind . ReturnVariableArray ) ;
12871287
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+
12881299 var arrayType = var . Type . Desugar ( ) as ArrayType ;
12891300 var isRefTypeArray = arrayType != null && var . Namespace is Class context && context . IsRefType ;
12901301 var elementType = arrayType ? . Type . Desugar ( ) ;
Original file line number Diff line number Diff line change @@ -1988,4 +1988,11 @@ public void TestCallByValueCppToCSharpPointer()
19881988 Assert . That ( RuleOfThreeTester . CopyConstructorCalls , Is . EqualTo ( 0 ) ) ;
19891989 Assert . That ( RuleOfThreeTester . CopyAssignmentCalls , Is . EqualTo ( 0 ) ) ;
19901990 }
1991+
1992+ [ Test ]
1993+ public void TestPointerToClass ( )
1994+ {
1995+ Assert . IsTrue ( CSharp . CSharp . PointerToClass . IsDefaultInstance ) ;
1996+ Assert . IsTrue ( CSharp . CSharp . PointerToClass . IsValid ) ;
1997+ }
19911998}
Original file line number Diff line number Diff line change @@ -1772,3 +1772,22 @@ void CallCallByValueInterfacePointer(CallByValueInterface* interface)
17721772 RuleOfThreeTester value;
17731773 interface->CallByPointer (&value);
17741774}
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 {
15921592void DLL_API CallCallByValueInterfaceValue (CallByValueInterface*);
15931593void DLL_API CallCallByValueInterfaceReference (CallByValueInterface*);
15941594void 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