@@ -2053,11 +2053,22 @@ bool ImplementProtocolDeclarationsVTableAndCSProxy (ModuleInventory modInventory
2053
2053
virtFunctions , virtFunctions [ i ] , vtableEntryIndex , vtableName , vtable , vtableAssignments , use , swiftLibraryPath ) ;
2054
2054
}
2055
2055
}
2056
+ AddVTHandleIfNeeded ( use , vtable , vtableAssignments , vtableName ) ;
2056
2057
ImplementVTableInitializer ( proxyClass , picl , usedPinvokeNames , protocolDecl , vtableAssignments , wrapper , vtableType , vtableName , swiftLibraryPath ) ;
2057
2058
2058
2059
return vtable . Fields . Count > 0 ;
2059
2060
}
2060
2061
2062
+ void AddVTHandleIfNeeded ( CSUsingPackages use , CSStruct vtable , List < CSLine > vtableAssignments , string vtName )
2063
+ {
2064
+ if ( vtable . Fields . Count > 0 ) {
2065
+ use . AddIfNotPresent ( typeof ( GCHandle ) ) ;
2066
+ var gcType = new CSSimpleType ( typeof ( GCHandle ) ) ;
2067
+ var decl = new CSFieldDeclaration ( gcType , OverrideBuilder . kVtableHandleName , value : null , CSVisibility . Public ) ;
2068
+ vtable . Fields . Insert ( 0 , new CSLine ( decl ) ) ;
2069
+ }
2070
+ }
2071
+
2061
2072
void CollectAllProtocolMethods ( List < FunctionDeclaration > functions , ProtocolDeclaration decl )
2062
2073
{
2063
2074
foreach ( TypeSpec spec in decl . Inheritance . Where ( inh => inh . InheritanceKind == InheritanceKind . Protocol ) . Select ( inh => inh . InheritedTypeSpec ) ) {
@@ -2114,6 +2125,7 @@ int ImplementVtableMethodsSuperMethodsAndVtable (ModuleInventory modInventory, W
2114
2125
if ( vtable . Fields . Count > 0 ) {
2115
2126
cl . InnerClasses . Add ( vtable ) ;
2116
2127
}
2128
+ AddVTHandleIfNeeded ( use , vtable , vtableAssignments , vtableName ) ;
2117
2129
ImplementVTableInitializer ( cl , picl , usedPinvokeNames , classDecl , vtableAssignments , wrapper , vtableType , vtableName , swiftLibraryPath ) ;
2118
2130
return virtFuncs . Count ;
2119
2131
}
0 commit comments