-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0101] Implement: Reconfiguring sizeof and related functions into a unified MemoryLayout struct - Part 1 #3854
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { | |
var size = 0 | ||
let data = __dispatch_data_create_map(__wrapped, &ptr, &size) | ||
let contentPtr = ptr!.bindMemory( | ||
to: ContentType.self, capacity: size / strideof(ContentType.self)) | ||
to: ContentType.self, capacity: size / MemoryLayout<ContentType>.stride) | ||
defer { _fixLifetime(data) } | ||
return try body(contentPtr) | ||
} | ||
|
@@ -114,8 +114,8 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { | |
/// | ||
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`. | ||
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) { | ||
buffer.baseAddress!.withMemoryRebound(to: UInt8.self, capacity: buffer.count * strideof(SourceType.self)) { | ||
self.append($0, count: buffer.count * sizeof(SourceType.self)) | ||
buffer.baseAddress!.withMemoryRebound(to: UInt8.self, capacity: buffer.count * MemoryLayout<SourceType>.stride) { | ||
self.append($0, count: buffer.count * MemoryLayout<SourceType>.stride) | ||
} | ||
} | ||
|
||
|
@@ -149,7 +149,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { | |
|
||
/// Copy the contents of the data into a buffer. | ||
/// | ||
/// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `sizeof(DestinationType) * buffer.count` then the first N bytes will be copied into the buffer. | ||
/// This function copies the bytes in `range` from the data into the buffer. If the count of the `range` is greater than `MemoryLayout<DestinationType>.size * buffer.count` then the first N bytes will be copied into the buffer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/// - precondition: The range must be within the bounds of the data. Otherwise `fatalError` is called. | ||
/// - parameter buffer: A buffer to copy the data into. | ||
/// - parameter range: A range in the data to copy into the buffer. If the range is empty, this function will return 0 without copying anything. If the range is nil, as much data as will fit into `buffer` is copied. | ||
|
@@ -167,9 +167,9 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable { | |
precondition(r.endIndex >= 0) | ||
precondition(r.endIndex <= cnt, "The range is outside the bounds of the data") | ||
|
||
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * sizeof(DestinationType.self), r.count)) | ||
copyRange = r.startIndex..<(r.startIndex + Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, r.count)) | ||
} else { | ||
copyRange = 0..<Swift.min(buffer.count * sizeof(DestinationType.self), cnt) | ||
copyRange = 0..<Swift.min(buffer.count * MemoryLayout<DestinationType>.stride, cnt) | ||
} | ||
|
||
guard !copyRange.isEmpty else { return 0 } | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gribozavr You didn't mention this
sizeof
->stride
change. This should be.size
?This was introduced in recent change.(https://github.com/apple/swift/blob/0b75ee975e55ffa7c8a69a0f076f33ff82b64f44/stdlib/public/SDK/Dispatch/Data.swift#L118) @atrick ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is supposed to be .stride on both modified lines.
I forgot to change the original code to strideof() and hadn't pushed my fix yet.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atrick
Thank you! If you have more fix, feel free to push them first.
I'd happy to rebase on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't push my fix, it makes more sense as part of your PR. Thanks.