-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Import Data and DataProtocol from the overlay (and correct some incorrect CFData and NSData usages) #1834
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
Import Data and DataProtocol from the overlay (and correct some incorrect CFData and NSData usages) #1834
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,9 +88,6 @@ typedef enum { | |
kCFMutable = 0x3 /* changeable and variable capacity */ | ||
} _CFDataMutableVariety; | ||
|
||
#define __CFGenericValidateMutability(variety) \ | ||
CFAssert1((variety != kCFFixedMutable && variety != kCFMutable), __kCFLogAssertion, "%s(): variety is not mutable", __PRETTY_FUNCTION__); | ||
|
||
CF_INLINE Boolean __CFDataIsMutable(CFDataRef data) { | ||
return __CFRuntimeGetFlag(data, __kCFMutable); | ||
} | ||
|
@@ -377,7 +374,6 @@ static Boolean __CFDataShouldUseAllocator(CFAllocatorRef allocator) { | |
// that there should be no deallocator, and the bytes should be copied. | ||
static CFMutableDataRef __CFDataInit(CFAllocatorRef allocator, _CFDataMutableVariety variety, CFIndex capacity, const uint8_t *bytes, CFIndex length, CFAllocatorRef bytesDeallocator) CF_RETURNS_RETAINED { | ||
CFMutableDataRef memory; | ||
__CFGenericValidateMutability(variety); | ||
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. This is inappropriate and does not match the Darwin behavior. 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. It must've been a merge artifact. |
||
CFAssert2(0 <= capacity, __kCFLogAssertion, "%s(): capacity (%ld) cannot be less than zero", __PRETTY_FUNCTION__, capacity); | ||
CFAssert3(kCFFixedMutable != variety || length <= capacity, __kCFLogAssertion, "%s(): for kCFFixedMutable type, capacity (%ld) must be greater than or equal to number of initial elements (%ld)", __PRETTY_FUNCTION__, capacity, length); | ||
CFAssert2(0 <= length, __kCFLogAssertion, "%s(): length (%ld) cannot be less than zero", __PRETTY_FUNCTION__, length); | ||
|
@@ -842,7 +838,6 @@ CFRange CFDataFind(CFDataRef data, CFDataRef dataToFind, CFRange searchRange, CF | |
} | ||
|
||
#undef __CFDataValidateRange | ||
#undef __CFGenericValidateMutability | ||
#undef INLINE_BYTES_THRESHOLD | ||
#undef CFDATA_MAX_SIZE | ||
#undef REVERSE_BUFFER |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2018 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 | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
//===--- DataProtocol -----------------------------------------------------===// | ||
|
||
extension Array: DataProtocol where Element == UInt8 { | ||
public var regions: CollectionOfOne<Array<UInt8>> { | ||
return CollectionOfOne(self) | ||
} | ||
} | ||
|
||
extension ArraySlice: DataProtocol where Element == UInt8 { | ||
public var regions: CollectionOfOne<ArraySlice<UInt8>> { | ||
return CollectionOfOne(self) | ||
} | ||
} | ||
|
||
extension ContiguousArray: DataProtocol where Element == UInt8 { | ||
public var regions: CollectionOfOne<ContiguousArray<UInt8>> { | ||
return CollectionOfOne(self) | ||
} | ||
} | ||
|
||
// FIXME: This currently crashes compilation in the Late Inliner. | ||
// extension CollectionOfOne : DataProtocol where Element == UInt8 { | ||
// public typealias Regions = CollectionOfOne<Data> | ||
// | ||
// public var regions: CollectionOfOne<Data> { | ||
// return CollectionOfOne<Data>(Data(self)) | ||
// } | ||
// } | ||
|
||
extension EmptyCollection : DataProtocol where Element == UInt8 { | ||
public var regions: EmptyCollection<Data> { | ||
return EmptyCollection<Data>() | ||
} | ||
} | ||
|
||
extension Repeated: DataProtocol where Element == UInt8 { | ||
public typealias Regions = Repeated<Data> | ||
|
||
public var regions: Repeated<Data> { | ||
guard self.count > 0 else { return repeatElement(Data(), count: 0) } | ||
return repeatElement(Data(CollectionOfOne(self.first!)), count: self.count) | ||
} | ||
} | ||
|
||
//===--- MutableDataProtocol ----------------------------------------------===// | ||
|
||
extension Array: MutableDataProtocol where Element == UInt8 { } | ||
|
||
extension ContiguousArray: MutableDataProtocol where Element == UInt8 { } |
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.
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 sorted this section: hopefully that does not pose any issue.
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.
If it does, it will be immediately apparent. The places where things were out of order were due to the compiler requiring the interfaces to be processed earlier.