Skip to content

Commit ce7d813

Browse files
committed
[stdlib] remove preconditions from compatibility entry point
- The old implementation of `UnsafePointer.withMemoryRebound` had no preconditions. - When implementing SE-0333, we forwarded the old entry point to the new implementation, which has preconditions. - This change removes the precondition from the compatibility entry point, reverting it to its previous behaviour. - This resolves rdar://90462471
1 parent 687beac commit ce7d813

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/public/core/UnsafePointer.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ public struct UnsafePointer<Pointee>: _Pointer {
336336
capacity count: Int,
337337
_ body: (UnsafePointer<T>) throws -> Result
338338
) rethrows -> Result {
339-
return try withMemoryRebound(to: T.self, capacity: count, body)
339+
let binding = Builtin.bindMemory(_rawValue, count._builtinWordValue, T.self)
340+
defer { Builtin.rebindMemory(_rawValue, binding) }
341+
return try body(.init(_rawValue))
340342
}
341343

342344
/// Accesses the pointee at the specified offset from this pointer.
@@ -1040,7 +1042,9 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
10401042
capacity count: Int,
10411043
_ body: (UnsafeMutablePointer<T>) throws -> Result
10421044
) rethrows -> Result {
1043-
return try withMemoryRebound(to: T.self, capacity: count, body)
1045+
let binding = Builtin.bindMemory(_rawValue, count._builtinWordValue, T.self)
1046+
defer { Builtin.rebindMemory(_rawValue, binding) }
1047+
return try body(.init(_rawValue))
10441048
}
10451049

10461050
/// Accesses the pointee at the specified offset from this pointer.

0 commit comments

Comments
 (0)