Skip to content
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

[stdlib]Catch the reasonable mistake 'UnsafeRawMutableBufferPointer' #69948

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a8fc95b
[stdlib]Catch the reasonable mistake 'UnsafeRawMutableBufferPointer'
devKobe24 Nov 15, 2023
86a5010
[stdlidt]Restore Original File Code.
devKobe24 Nov 15, 2023
2ca5c32
[stdlib]Catch the reasonable mistake 'UnsafeRawMutableBufferPointer'
devKobe24 Nov 16, 2023
6818328
Merge branch 'apple:main' into develop-kobe
devKobe24 Nov 16, 2023
30faaa1
[stdlib]Catch the reasonable mistake 'UnsafeRawMutableBufferPointer'
devKobe24 Nov 16, 2023
243984d
[stdlib]fix typealias for written code to guide developers.
devKobe24 Nov 16, 2023
d1212f5
[stdlib]Catch the reasonable mistake 'UnsafeRawMutableBufferPointer'
devKobe24 Nov 16, 2023
66afef9
Merge pull request #3 from devKobe24/develop-kobe
devKobe24 Nov 16, 2023
af2964f
Merge remote-tracking branch 'origin-kobe/main'
devKobe24 Nov 16, 2023
23c7abd
Merge branch 'apple:main' into develop-kobe
devKobe24 Nov 16, 2023
8207d9f
Merge remote-tracking branch 'refs/remotes/origin/main'
devKobe24 Nov 17, 2023
7f816c7
[stdlib]Delete unnecessary file.
devKobe24 Nov 17, 2023
2573c4d
[stdlib]Restore the whitespace changes in the file to their original …
devKobe24 Nov 17, 2023
0a7c7ef
[stdlib]Add test case code.
devKobe24 Nov 17, 2023
38b4a68
Merge branch 'main' into develop-kobe
devKobe24 Nov 17, 2023
384fd44
Merge pull request #4 from devKobe24/develop-kobe
devKobe24 Nov 17, 2023
1151034
Merge branch 'apple:main' into main
devKobe24 Nov 18, 2023
174ea6d
Merge branch 'apple:main' into develop-kobe
devKobe24 Nov 18, 2023
ecd0975
Merge pull request #5 from devKobe24/develop-kobe
devKobe24 Nov 18, 2023
169973f
[stdlib]Delete unnecessary file.
devKobe24 Nov 18, 2023
15e7298
[stdlib]Add test case code.
devKobe24 Nov 18, 2023
49e3bca
Merge pull request #6 from devKobe24/develop-kobe
devKobe24 Nov 18, 2023
dcd46c6
[stdlib]Code indentation and line alignment adjustment.
devKobe24 Nov 18, 2023
46bd22a
[stdlib]Code indentation and line alignment adjustment.
devKobe24 Nov 18, 2023
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
26 changes: 14 additions & 12 deletions stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

%import gyb

@available(*, unavailable, renamed: "UnsafeMutableRawBufferPointer")
typealias UnsafeRawMutableBufferPointer = UnsafeMutableRawBufferPointer
% for mutable in (True, False):
% Self = 'UnsafeMutableRawBufferPointer' if mutable else 'UnsafeRawBufferPointer'
% Mutable = 'Mutable' if mutable else ''
Expand Down Expand Up @@ -515,7 +517,7 @@ extension Unsafe${Mutable}RawBufferPointer {
/// must be properly aligned for accessing `T`, and `source.count` must be a
/// multiple of `MemoryLayout<T>.stride`.
///
/// The memory referenced by `source` may overlap with the memory referenced
/// The memory referenced by `source` may overlap with the memory referenced
/// by this buffer.
///
/// After calling `copyMemory(from:)`, the first `source.count` bytes of
Expand Down Expand Up @@ -709,7 +711,7 @@ extension Unsafe${Mutable}RawBufferPointer {
/// initialized to a trivial type, and must be properly aligned for
/// accessing `T`.
///
/// After calling this method on a raw buffer with non-nil `baseAddress` `b`,
/// After calling this method on a raw buffer with non-nil `baseAddress` `b`,
/// the region starting at `b` and continuing up to
/// `b + self.count - self.count % MemoryLayout<T>.stride` is bound
/// to type `T` and is initialized. If `T` is a nontrivial type, you must
Expand All @@ -720,8 +722,8 @@ extension Unsafe${Mutable}RawBufferPointer {
/// - Parameters:
/// - type: The type to bind this buffer’s memory to.
/// - repeatedValue: The instance to copy into memory.
/// - Returns: A typed buffer of the memory referenced by this raw buffer.
/// The typed buffer contains `self.count / MemoryLayout<T>.stride`
/// - Returns: A typed buffer of the memory referenced by this raw buffer.
/// The typed buffer contains `self.count / MemoryLayout<T>.stride`
/// instances of `T`.
@inlinable
@discardableResult
Expand Down Expand Up @@ -775,20 +777,20 @@ extension Unsafe${Mutable}RawBufferPointer {
"insufficient space to accommodate source.underestimatedCount elements")
guard let base = baseAddress else {
// this can be a precondition since only an invalid argument should be costly
_precondition(source.underestimatedCount == 0,
_precondition(source.underestimatedCount == 0,
"no memory available to initialize from source")
return (it, UnsafeMutableBufferPointer(start: nil, count: 0))
}
}

_debugPrecondition(
Int(bitPattern: base) % MemoryLayout<S.Element>.stride == 0,
"buffer base address must be properly aligned to access S.Element"
)

_internalInvariant(_end != nil)
for p in stride(from: base,
for p in stride(from: base,
// only advance to as far as the last element that will fit
to: _end._unsafelyUnwrappedUnchecked - elementStride + 1,
to: _end._unsafelyUnwrappedUnchecked - elementStride + 1,
by: elementStride
) {
// underflow is permitted -- e.g. a sequence into
Expand All @@ -799,7 +801,7 @@ extension Unsafe${Mutable}RawBufferPointer {
}

return (it, UnsafeMutableBufferPointer(
start: base.assumingMemoryBound(to: S.Element.self),
start: base.assumingMemoryBound(to: S.Element.self),
count: idx / elementStride))
}

Expand Down Expand Up @@ -983,7 +985,7 @@ extension Unsafe${Mutable}RawBufferPointer {

% end # mutable

/// Binds this buffer’s memory to the specified type and returns a typed buffer
/// Binds this buffer’s memory to the specified type and returns a typed buffer
/// of the bound memory.
///
/// Use the `bindMemory(to:)` method to bind the memory referenced
Expand Down Expand Up @@ -1153,7 +1155,7 @@ extension Unsafe${Mutable}RawBufferPointer: CustomDebugStringConvertible {
}

extension ${Self} {
@available(*, unavailable,
@available(*, unavailable,
message: "use 'Unsafe${Mutable}RawBufferPointer(rebasing:)' to convert a slice into a zero-based raw buffer.")
public subscript(bounds: Range<Int>) -> ${Self} {
get { return ${Self}(start: nil, count: 0) }
Expand All @@ -1163,7 +1165,7 @@ extension ${Self} {
}

% if mutable:
@available(*, unavailable,
@available(*, unavailable,
message: "use 'UnsafeRawBufferPointer(rebasing:)' to convert a slice into a zero-based raw buffer.")
public subscript(bounds: Range<Int>) -> UnsafeRawBufferPointer {
get { return UnsafeRawBufferPointer(start: nil, count: 0) }
Expand Down
Loading