@@ -146,13 +146,25 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
146
146
147
147
var pointee = pointer . Pointee . Desugar ( ) ;
148
148
var finalPointee = pointer . GetFinalPointee ( ) . Desugar ( ) ;
149
- var type = Context . ReturnType . Type . Desugar (
149
+ var returnType = Context . ReturnType . Type . Desugar (
150
150
resolveTemplateSubstitution : false ) ;
151
- PrimitiveType primitive ;
152
- if ( ( pointee . IsConstCharString ( ) && ( isRefParam || type . IsReference ( ) ) ) ||
153
- ( ! finalPointee . IsPrimitiveType ( out primitive ) &&
151
+ if ( ( pointee . IsConstCharString ( ) && ( isRefParam || returnType . IsReference ( ) ) ) ||
152
+ ( ! finalPointee . IsPrimitiveType ( out PrimitiveType primitive ) &&
154
153
! finalPointee . IsEnumType ( ) ) )
154
+ {
155
+ if ( Context . MarshalKind != MarshalKind . NativeField &&
156
+ pointee . IsPointerTo ( out Type type ) &&
157
+ type . Desugar ( ) . TryGetClass ( out Class c ) )
158
+ {
159
+ string ret = Generator . GeneratedIdentifier ( Context . ReturnVarName ) ;
160
+ Context . Before . WriteLine ( $@ "{ typePrinter . IntPtrType } { ret } = {
161
+ Context . ReturnVarName } == { typePrinter . IntPtrType } .Zero ? {
162
+ typePrinter . IntPtrType } .Zero : new {
163
+ typePrinter . IntPtrType } (*(void**) { Context . ReturnVarName } );" ) ;
164
+ Context . ReturnVarName = ret ;
165
+ }
155
166
return pointer . QualifiedPointee . Visit ( this ) ;
167
+ }
156
168
157
169
if ( isRefParam )
158
170
{
@@ -167,7 +179,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
167
179
if ( Context . Function != null &&
168
180
Context . Function . OperatorKind == CXXOperatorKind . Subscript )
169
181
{
170
- if ( type . IsPrimitiveType ( primitive ) )
182
+ if ( returnType . IsPrimitiveType ( primitive ) )
171
183
{
172
184
Context . Return . Write ( "*" ) ;
173
185
}
@@ -517,7 +529,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
517
529
if ( param . IsOut )
518
530
{
519
531
MarshalString ( pointee ) ;
520
- Context . Return . Write ( "IntPtr .Zero") ;
532
+ Context . Return . Write ( $ " { typePrinter . IntPtrType } .Zero") ;
521
533
Context . ArgumentPrefix . Write ( "&" ) ;
522
534
return true ;
523
535
}
@@ -604,7 +616,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
604
616
arg , Context . Parameter . Name , Helpers . InstanceIdentifier ) ;
605
617
}
606
618
607
- Context . Return . Write ( $ "new global::System.IntPtr (&{ arg } )") ;
619
+ Context . Return . Write ( $ "new { typePrinter . IntPtrType } (&{ arg } )") ;
608
620
return true ;
609
621
}
610
622
@@ -614,7 +626,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
614
626
pointer . QualifiedPointee . Visit ( this ) ;
615
627
Context . Before . WriteLine ( $ "var { arg } = { Context . Return } ;") ;
616
628
Context . Return . StringBuilder . Clear ( ) ;
617
- Context . Return . Write ( $ "new global::System.IntPtr (&{ arg } )") ;
629
+ Context . Return . Write ( $ "new { typePrinter . IntPtrType } (&{ arg } )") ;
618
630
return true ;
619
631
}
620
632
0 commit comments