Skip to content

Commit 528dd09

Browse files
committed
[stdlib] convert withUnsafeMutableBytes() to typed throws
1 parent 68088bc commit 528dd09

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,11 +1207,23 @@ extension ${Self} {
12071207
/// of the closure's execution.
12081208
/// - Returns: The return value, if any, of the `body` closure.
12091209
@inlinable
1210-
public func withUnsafeMutableBytes<T, Result>(
1210+
@_alwaysEmitIntoClient
1211+
public func withUnsafeMutableBytes<T, E: Error, Result>(
1212+
of value: inout T,
1213+
_ body: (UnsafeMutableRawBufferPointer) throws(E) -> Result
1214+
) throws(E) -> Result {
1215+
let pointer = UnsafeMutableRawPointer(Builtin.addressof(&value))
1216+
return try body(.init(start: pointer, count: MemoryLayout<T>.size))
1217+
}
1218+
1219+
/// ABI: Historical withUnsafeMutableBytes(of:_:) rethrows,
1220+
/// expressed as "throws", which is ABI-compatible with "rethrows".
1221+
@_silgen_name("$ss22withUnsafeMutableBytes2of_q_xz_q_SwKXEtKr0_lF")
1222+
@usableFromInline
1223+
func __abi_se0413_withUnsafeMutableBytes<T, Result>(
12111224
of value: inout T,
12121225
_ body: (UnsafeMutableRawBufferPointer) throws -> Result
1213-
) rethrows -> Result
1214-
{
1226+
) throws -> Result {
12151227
return try withUnsafeMutablePointer(to: &value) {
12161228
return try body(UnsafeMutableRawBufferPointer(
12171229
start: $0, count: MemoryLayout<T>.size))

0 commit comments

Comments
 (0)