Skip to content

[stdlib] convert U[M]R[B]P.withMemoryRebound() to typed throws #72036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions stdlib/public/core/UnsafeBufferPointerSlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -279,9 +279,9 @@ extension Slice where Base == UnsafeMutableRawBufferPointer {
/// - Returns: The return value, if any, of the `body` closure parameter.
@inlinable
@_alwaysEmitIntoClient
public func withMemoryRebound<T, Result>(
to type: T.Type, _ body: (UnsafeMutableBufferPointer<T>) throws -> Result
) rethrows -> Result {
public func withMemoryRebound<T, Result, E: Error>(
to type: T.Type, _ body: (UnsafeMutableBufferPointer<T>) throws(E) -> Result
) throws(E) -> Result {
let buffer = Base(rebasing: self)
return try buffer.withMemoryRebound(to: T.self, body)
}
Expand Down Expand Up @@ -518,9 +518,9 @@ extension Slice where Base == UnsafeRawBufferPointer {
/// - Returns: The return value, if any, of the `body` closure parameter.
@inlinable
@_alwaysEmitIntoClient
public func withMemoryRebound<T, Result>(
to type: T.Type, _ body: (UnsafeBufferPointer<T>) throws -> Result
) rethrows -> Result {
public func withMemoryRebound<T, Result, E: Error>(
to type: T.Type, _ body: (UnsafeBufferPointer<T>) throws(E) -> Result
) throws(E) -> Result {
let buffer = Base(rebasing: self)
return try buffer.withMemoryRebound(to: T.self, body)
}
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -1074,10 +1074,10 @@ extension Unsafe${Mutable}RawBufferPointer {
/// - Returns: The return value, if any, of the `body` closure parameter.
@inlinable
@_alwaysEmitIntoClient
public func withMemoryRebound<T, Result>(
public func withMemoryRebound<T, Result, E: Error>(
to type: T.Type,
_ body: (_ buffer: Unsafe${Mutable}BufferPointer<T>) throws -> Result
) rethrows -> Result {
_ body: (_ buffer: Unsafe${Mutable}BufferPointer<T>) throws(E) -> Result
) throws(E) -> Result {
guard let s = _position else {
return try body(.init(start: nil, count: 0))
}
Expand Down
14 changes: 7 additions & 7 deletions stdlib/public/core/UnsafeRawPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -372,11 +372,11 @@ public struct UnsafeRawPointer: _Pointer {
/// - Returns: The return value, if any, of the `body` closure parameter.
@inlinable
@_alwaysEmitIntoClient
public func withMemoryRebound<T, Result>(
public func withMemoryRebound<T, Result, E: Error>(
to type: T.Type,
capacity count: Int,
_ body: (_ pointer: UnsafePointer<T>) throws -> Result
) rethrows -> Result {
_ body: (_ pointer: UnsafePointer<T>) throws(E) -> Result
) throws(E) -> Result {
_debugPrecondition(
Int(bitPattern: self) & (MemoryLayout<T>.alignment-1) == 0,
"self must be a properly aligned pointer for type T"
Expand Down Expand Up @@ -941,11 +941,11 @@ public struct UnsafeMutableRawPointer: _Pointer {
/// - Returns: The return value, if any, of the `body` closure parameter.
@inlinable
@_alwaysEmitIntoClient
public func withMemoryRebound<T, Result>(
public func withMemoryRebound<T, Result, E: Error>(
to type: T.Type,
capacity count: Int,
_ body: (_ pointer: UnsafeMutablePointer<T>) throws -> Result
) rethrows -> Result {
_ body: (_ pointer: UnsafeMutablePointer<T>) throws(E) -> Result
) throws(E) -> Result {
_debugPrecondition(
Int(bitPattern: self) & (MemoryLayout<T>.alignment-1) == 0,
"self must be a properly aligned pointer for type T"
Expand Down