Skip to content

Commit 5b82a3e

Browse files
authored
Merge pull request #88 from adam-fowler/asan-fixes
ASan fixes with withMemoryRebound
2 parents 102ea0d + 4e0d499 commit 5b82a3e

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

Sources/Runtime/Pointers/Pointers.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,31 @@ func withClassValuePointer<Value, Result>(
4242
of value: inout Value,
4343
_ body: (UnsafeMutableRawPointer) throws -> Result) throws -> Result {
4444
return try withUnsafePointer(to: &value) {
45-
let pointer = $0.withMemoryRebound(to: UnsafeMutableRawPointer.self, capacity: 1) {$0.pointee}
46-
return try body(pointer)
45+
return try $0.withMemoryRebound(to: UnsafeMutableRawPointer.self, capacity: 1) {
46+
try body($0.pointee)
47+
}
4748
}
4849
}
4950

5051
func withExistentialValuePointer<Value, Result>(
5152
of value: inout Value,
5253
_ body: (UnsafeMutableRawPointer) throws -> Result) throws -> Result {
53-
return try withUnsafePointer(to: &value) {
54-
let container = $0.withMemoryRebound(to: ExistentialContainer.self, capacity: 1) {$0.pointee}
55-
let info = try metadata(of: container.type)
56-
if info.kind == .class || info.size > ExistentialContainerBuffer.size() {
57-
let base = $0.withMemoryRebound(to: UnsafeMutableRawPointer.self, capacity: 1) {$0.pointee}
58-
if info.kind == .struct {
59-
return try body(base.advanced(by: existentialHeaderSize))
54+
return try withUnsafePointer(to: &value) { ptr in
55+
try ptr.withMemoryRebound(to: ExistentialContainer.self, capacity: 1) {
56+
let container = $0.pointee
57+
let info = try metadata(of: container.type)
58+
if info.kind == .class || info.size > ExistentialContainerBuffer.size() {
59+
return try ptr.withMemoryRebound(to: UnsafeMutableRawPointer.self, capacity: 1) {
60+
let base = $0.pointee
61+
if info.kind == .struct {
62+
return try body(base.advanced(by: existentialHeaderSize))
63+
} else {
64+
return try body(base)
65+
}
66+
}
6067
} else {
61-
return try body(base)
68+
return try body($0.mutable.raw)
6269
}
63-
} else {
64-
return try body($0.mutable.raw)
6570
}
6671
}
6772
}

Tests/RuntimeTests/LinuxMain.swift

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)