@@ -168,11 +168,6 @@ private final class ToolWrapper {
168168 self . tool = tool
169169 }
170170
171- /// The owning list of all created commands.
172- //
173- // FIXME: This is unfortunate, we should be able to destroy these naturally.
174- private var commandWrappers : [ CommandWrapper ] = [ ]
175-
176171 func createCommand( _ name: UnsafePointer < llb_data_t > ) -> OpaquePointer ? {
177172 let command = tool. createCommand ( stringFromData ( name. pointee) ) as ExternalCommand ?
178173 return command. map { command in buildCommand ( name, command) } ?? nil
@@ -198,9 +193,9 @@ private final class ToolWrapper {
198193
199194 private func buildCommand( _ name: UnsafePointer < llb_data_t > , _ command: ExternalCommand ) -> OpaquePointer ? {
200195 let wrapper = CommandWrapper ( command: command)
201- self . commandWrappers. append ( wrapper)
202196 var _delegate = llb_buildsystem_external_command_delegate_t ( )
203- _delegate. context = Unmanaged . passUnretained ( wrapper) . toOpaque ( )
197+ _delegate. context = Unmanaged . passRetained ( wrapper) . toOpaque ( )
198+ _delegate. destroy_context = { Unmanaged < CommandWrapper > . fromOpaque ( UnsafeRawPointer ( $0!) ) . release ( ) }
204199 _delegate. configure = { BuildSystem . toCommandWrapper ( $0!) . configure ( $1!, $2!, $3!, $4!) }
205200 _delegate. get_signature = { return BuildSystem . toCommandWrapper ( $0!) . getSignature ( $1!, $2!) }
206201 _delegate. start = { return BuildSystem . toCommandWrapper ( $0!) . start ( $1!, $2!, $3) }
@@ -1253,10 +1248,6 @@ public final class BuildSystem {
12531248 return fsGetFileInfo ( path, info)
12541249 }
12551250
1256- /// The owning list of all created tools.
1257- //
1258- // FIXME: This is unfortunate, we should be able to destroy these naturally.
1259- private var toolWrappers : [ ToolWrapper ] = [ ]
12601251 private func lookupTool( _ name: UnsafePointer < llb_data_t > ) -> OpaquePointer ? {
12611252 // Look up the named tool.
12621253 guard let tool = delegate. lookupTool ( stringFromData ( name. pointee) ) else {
@@ -1265,9 +1256,9 @@ public final class BuildSystem {
12651256
12661257 // If we got a tool, save it and create an appropriate low-level instance.
12671258 let wrapper = ToolWrapper ( tool: tool)
1268- self . toolWrappers. append ( wrapper)
12691259 var _delegate = llb_buildsystem_tool_delegate_t ( )
1270- _delegate. context = Unmanaged . passUnretained ( wrapper) . toOpaque ( )
1260+ _delegate. context = Unmanaged . passRetained ( wrapper) . toOpaque ( )
1261+ _delegate. destroy_context = { Unmanaged < CommandWrapper > . fromOpaque ( UnsafeRawPointer ( $0!) ) . release ( ) }
12711262 _delegate. create_command = { return BuildSystem . toToolWrapper ( $0!) . createCommand ( $1!) }
12721263 _delegate. create_custom_command = { return BuildSystem . toToolWrapper ( $0!) . createCustomCommand ( $1!) }
12731264
0 commit comments