Skip to content

Commit 1b538f5

Browse files
committed
swift-inspect: correct some escaping binding for RemoteMirror
Adjust the pointer handling for the callback and adjust the code to ensure that we properly form memory references to the function for the callback.
1 parent e89de6e commit 1b538f5

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

tools/swift-inspect/Sources/swift-inspect/RemoteMirror+Extensions.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,32 +119,35 @@ extension SwiftReflectionContextRef {
119119
return words[2]
120120
}
121121

122-
internal func iterateConformanceCache(_ body: ConformanceIterationCallback) throws {
122+
internal func iterateConformanceCache(_ body: @escaping ConformanceIterationCallback) throws {
123123
var body = body
124-
if let error = swift_reflection_iterateConformanceCache(self, {
125-
let callback = $2!.bindMemory(to: ConformanceIterationCallback.self, capacity: 1)
126-
callback.pointee($0, $1)
127-
}, &body) {
124+
if let error = withUnsafeMutablePointer(to: &body, {
125+
swift_reflection_iterateConformanceCache(self, {
126+
$2!.bindMemory(to: ConformanceIterationCallback.self, capacity: 1).pointee($0, $1)
127+
}, $0)
128+
}) {
128129
throw Error(cString: error)
129130
}
130131
}
131132

132-
internal func iterateMetadataAllocations(_ body: MetadataAllocationIterationCallback) throws {
133+
internal func iterateMetadataAllocations(_ body: @escaping MetadataAllocationIterationCallback) throws {
133134
var body = body
134-
if let error = swift_reflection_iterateMetadataAllocations(self, {
135-
let callback = $1!.bindMemory(to: MetadataAllocationIterationCallback.self, capacity: 1)
136-
callback.pointee($0)
137-
}, &body) {
135+
if let error = withUnsafeMutablePointer(to: &body, {
136+
swift_reflection_iterateMetadataAllocations(self, {
137+
$1!.bindMemory(to: MetadataAllocationIterationCallback.self, capacity: 1).pointee($0)
138+
}, $0)
139+
}) {
138140
throw Error(cString: error)
139141
}
140142
}
141143

142-
internal func iterateMetadataAllocationBacktraces(_ body: MetadataAllocationBacktraceIterationCallback) throws {
144+
internal func iterateMetadataAllocationBacktraces(_ body: @escaping MetadataAllocationBacktraceIterationCallback) throws {
143145
var body = body
144-
if let error = swift_reflection_iterateMetadataAllocationBacktraces(self, {
145-
let callback = $3!.bindMemory(to: MetadataAllocationBacktraceIterationCallback.self, capacity: 1)
146-
callback.pointee($0, $1, $2!)
147-
}, &body) {
146+
if let error = withUnsafeMutablePointer(to: &body, {
147+
swift_reflection_iterateMetadataAllocationBacktraces(self, {
148+
$3!.bindMemory(to: MetadataAllocationBacktraceIterationCallback.self, capacity: 1).pointee($0, $1, $2!)
149+
}, $0)
150+
}) {
148151
throw Error(cString: error)
149152
}
150153
}

0 commit comments

Comments
 (0)