Skip to content

Commit 6d2de26

Browse files
committed
Adopt typed throws in one withUnsafePointer() API
1 parent 92a0867 commit 6d2de26

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

stdlib/public/core/LifetimeManager.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public func _withUnprotectedUnsafeMutablePointer<T, Result>(
9999
#endif
100100
}
101101

102-
#if !$Embedded
103102
/// Invokes the given closure with a pointer to the given argument.
104103
///
105104
/// The `withUnsafePointer(to:_:)` function is useful for calling Objective-C
@@ -120,25 +119,27 @@ public func _withUnprotectedUnsafeMutablePointer<T, Result>(
120119
/// type. If you need to mutate the argument through the pointer, use
121120
/// `withUnsafeMutablePointer(to:_:)` instead.
122121
/// - Returns: The return value, if any, of the `body` closure.
122+
@_alwaysEmitIntoClient
123123
@inlinable
124-
public func withUnsafePointer<T, Result>(
124+
public func withUnsafePointer<T, E, Result>(
125125
to value: T,
126-
_ body: (UnsafePointer<T>) throws -> Result
127-
) rethrows -> Result
126+
_ body: (UnsafePointer<T>) throws(E) -> Result
127+
) throws(E) -> Result
128128
{
129129
return try body(UnsafePointer<T>(Builtin.addressOfBorrow(value)))
130130
}
131-
#else
132-
// TODO: This should be unified with non-embedded Swift.
133-
@inlinable
134-
public func withUnsafePointer<T, E, Result>(
131+
132+
/// ABI: Historical withUnsafePointer(to:_:) rethrows, expressed as "throws",
133+
/// which is ABI-compatible with "rethrows".
134+
@_silgen_name("$ss17withUnsafePointer2to_q_x_q_SPyxGKXEtKr0_lF")
135+
@usableFromInline
136+
func __abi_withUnsafePointer<T, Result>(
135137
to value: T,
136-
_ body: (UnsafePointer<T>) throws(E) -> Result
137-
) throws(E) -> Result
138+
_ body: (UnsafePointer<T>) throws -> Result
139+
) throws -> Result
138140
{
139141
return try body(UnsafePointer<T>(Builtin.addressOfBorrow(value)))
140142
}
141-
#endif
142143

143144
/// Invokes the given closure with a pointer to the given argument.
144145
///

0 commit comments

Comments
 (0)