Skip to content

Commit 7cbe2cf

Browse files
authored
Merge pull request #72036 from glessard/rawpointer-withmemoryrebound-typed-throws
[stdlib] convert `U[M]R[B]P.withMemoryRebound()` to typed throws
2 parents 7f9725f + 6befe66 commit 7cbe2cf

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

stdlib/public/core/UnsafeBufferPointerSlice.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -279,9 +279,9 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
279279
/// - Returns: The return value, if any, of the `body` closure parameter.
280280
@inlinable
281281
@_alwaysEmitIntoClient
282-
public func withMemoryRebound<T, Result>(
283-
to type: T.Type, _ body: (UnsafeMutableBufferPointer<T>) throws -> Result
284-
) rethrows -> Result {
282+
public func withMemoryRebound<T, Result, E: Error>(
283+
to type: T.Type, _ body: (UnsafeMutableBufferPointer<T>) throws(E) -> Result
284+
) throws(E) -> Result {
285285
let buffer = Base(rebasing: self)
286286
return try buffer.withMemoryRebound(to: T.self, body)
287287
}
@@ -518,9 +518,9 @@ extension Slice where Base == UnsafeRawBufferPointer {
518518
/// - Returns: The return value, if any, of the `body` closure parameter.
519519
@inlinable
520520
@_alwaysEmitIntoClient
521-
public func withMemoryRebound<T, Result>(
522-
to type: T.Type, _ body: (UnsafeBufferPointer<T>) throws -> Result
523-
) rethrows -> Result {
521+
public func withMemoryRebound<T, Result, E: Error>(
522+
to type: T.Type, _ body: (UnsafeBufferPointer<T>) throws(E) -> Result
523+
) throws(E) -> Result {
524524
let buffer = Base(rebasing: self)
525525
return try buffer.withMemoryRebound(to: T.self, body)
526526
}

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -1074,10 +1074,10 @@ extension Unsafe${Mutable}RawBufferPointer {
10741074
/// - Returns: The return value, if any, of the `body` closure parameter.
10751075
@inlinable
10761076
@_alwaysEmitIntoClient
1077-
public func withMemoryRebound<T, Result>(
1077+
public func withMemoryRebound<T, Result, E: Error>(
10781078
to type: T.Type,
1079-
_ body: (_ buffer: Unsafe${Mutable}BufferPointer<T>) throws -> Result
1080-
) rethrows -> Result {
1079+
_ body: (_ buffer: Unsafe${Mutable}BufferPointer<T>) throws(E) -> Result
1080+
) throws(E) -> Result {
10811081
guard let s = _position else {
10821082
return try body(.init(start: nil, count: 0))
10831083
}

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -372,11 +372,11 @@ public struct UnsafeRawPointer: _Pointer {
372372
/// - Returns: The return value, if any, of the `body` closure parameter.
373373
@inlinable
374374
@_alwaysEmitIntoClient
375-
public func withMemoryRebound<T, Result>(
375+
public func withMemoryRebound<T, Result, E: Error>(
376376
to type: T.Type,
377377
capacity count: Int,
378-
_ body: (_ pointer: UnsafePointer<T>) throws -> Result
379-
) rethrows -> Result {
378+
_ body: (_ pointer: UnsafePointer<T>) throws(E) -> Result
379+
) throws(E) -> Result {
380380
_debugPrecondition(
381381
Int(bitPattern: self) & (MemoryLayout<T>.alignment-1) == 0,
382382
"self must be a properly aligned pointer for type T"
@@ -941,11 +941,11 @@ public struct UnsafeMutableRawPointer: _Pointer {
941941
/// - Returns: The return value, if any, of the `body` closure parameter.
942942
@inlinable
943943
@_alwaysEmitIntoClient
944-
public func withMemoryRebound<T, Result>(
944+
public func withMemoryRebound<T, Result, E: Error>(
945945
to type: T.Type,
946946
capacity count: Int,
947-
_ body: (_ pointer: UnsafeMutablePointer<T>) throws -> Result
948-
) rethrows -> Result {
947+
_ body: (_ pointer: UnsafeMutablePointer<T>) throws(E) -> Result
948+
) throws(E) -> Result {
949949
_debugPrecondition(
950950
Int(bitPattern: self) & (MemoryLayout<T>.alignment-1) == 0,
951951
"self must be a properly aligned pointer for type T"

0 commit comments

Comments
 (0)