@@ -21,16 +21,18 @@ func sockaddr_cast(_ p: UnsafeMutableRawPointer) -> UnsafeMutablePointer<sockadd
2121 return p. assumingMemoryBound ( to: sockaddr. self)
2222}
2323
24- protocol Kinded {
24+ protocol EntryInfo {
2525 var offset : Int32 { get }
2626 var kind : Int32 { get }
2727}
2828
2929open class AndroidInjection {
3030
31+ static var injectionNumber = 0
32+
3133 open class func connectAndRun( forMainThread: @escaping ( @escaping ( ) -> ( ) ) -> ( ) ) {
3234 if androidInjectionHost == " NNN.NNN.NNN.NNN " {
33- NSLog ( " Injection: androidInjectionHost has not been updated, try build again " )
35+ NSLog ( " Injection: AndroidInjectionHost.swift has not been updated, please build again. " )
3436 return
3537 }
3638
@@ -74,6 +76,7 @@ open class AndroidInjection {
7476 else {
7577 return loaderSocket
7678 }
79+
7780 close ( loaderSocket)
7881 return - 1
7982 }
@@ -101,7 +104,7 @@ open class AndroidInjection {
101104 fflush ( serverWrite)
102105
103106 let serverRead = fdopen ( serverSocket, " r " )
104- var compressedLength : Int32 = 0 , uncompressedLength : Int32 = 0 , injectionNumber = 0
107+ var compressedLength : Int32 = 0 , uncompressedLength : Int32 = 0
105108
106109 while fread ( & compressedLength, 1 , valueLength, serverRead) == valueLength &&
107110 fread ( & uncompressedLength, 1 , valueLength, serverRead) == valueLength,
@@ -126,8 +129,8 @@ open class AndroidInjection {
126129 break
127130 }
128131
129- injectionNumber += 1
130- let libraryPath = NSTemporaryDirectory ( ) + " injection \( injectionNumber) .so "
132+ AndroidInjection . injectionNumber += 1
133+ let libraryPath = NSTemporaryDirectory ( ) + " injection \( AndroidInjection . injectionNumber) .so "
131134 let libraryFILE = fopen ( libraryPath, " w " )
132135 if libraryFILE == nil ||
133136 fwrite ( uncompressedBuffer, 1 , Int ( uncompressedLength) , libraryFILE) != uncompressedLength {
@@ -176,7 +179,7 @@ open class AndroidInjection {
176179
177180 var processed = [ UnsafeMutablePointer < UInt8 > : Bool ] ( )
178181
179- struct TypeEntry : Kinded {
182+ struct TypeEntry : EntryInfo {
180183 let offset : Int32
181184 let kind : Int32
182185 }
@@ -185,7 +188,7 @@ open class AndroidInjection {
185188 entrySymbol: " .swift2_type_metadata_start " ,
186189 entryType: TypeEntry . self, processed: & processed)
187190
188- struct Conformance : Kinded {
191+ struct Conformance : EntryInfo {
189192 let skip1 : Int32
190193 let offset : Int32
191194 let skip2 : Int32
@@ -194,14 +197,14 @@ open class AndroidInjection {
194197
195198 process ( libHandle: libHandle, mainHandle: mainHandle,
196199 entrySymbol: " .swift2_protocol_conformances_start " ,
197- entryType: Conformance . self, pointerOffset: pointerSize , processed: & processed)
200+ entryType: Conformance . self, pointerOffset: MemoryLayout < Int32 > . size , processed: & processed)
198201
199202 return nil
200203 }
201204
202- class func process< T: Kinded > ( libHandle: UnsafeMutableRawPointer , mainHandle: UnsafeMutableRawPointer ,
203- entrySymbol: String , entryType: T . Type , pointerOffset: Int = 0 ,
204- processed: inout [ UnsafeMutablePointer < UInt8 > : Bool ] ) {
205+ class func process< T: EntryInfo > ( libHandle: UnsafeMutableRawPointer , mainHandle: UnsafeMutableRawPointer ,
206+ entrySymbol: String , entryType: T . Type , pointerOffset: Int = 0 ,
207+ processed: inout [ UnsafeMutablePointer < UInt8 > : Bool ] ) {
205208 guard let conformance = dlsym ( libHandle, entrySymbol) else {
206209 NSLog ( " Could not locate \( entrySymbol) entries " )
207210 return
0 commit comments