Skip to content

[5.0] Import Data and DataProtocol from the overlay (and correct some incorrect CFData and NSData usages) #1853

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 1 commit into from
Jan 28, 2019
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
44 changes: 25 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,19 @@ add_swift_library(Foundation
Foundation/CGFloat.swift
Foundation/CharacterSet.swift
Foundation/Codable.swift
Foundation/Collections+DataProtocol.swift
Foundation/ContiguousBytes.swift
Foundation/Data.swift
Foundation/DateComponentsFormatter.swift
Foundation/DataProtocol.swift
Foundation/Date.swift
Foundation/DateComponents.swift
Foundation/DateComponentsFormatter.swift
Foundation/DateFormatter.swift
Foundation/DateIntervalFormatter.swift
Foundation/DateInterval.swift
Foundation/Date.swift
Foundation/DateIntervalFormatter.swift
Foundation/Decimal.swift
Foundation/Dictionary.swift
Foundation/DispatchData+DataProtocol.swift
Foundation/EnergyFormatter.swift
Foundation/ExtraStringAPIs.swift
Foundation/FileHandle.swift
Expand All @@ -147,8 +151,8 @@ add_swift_library(Foundation
Foundation/Formatter.swift
Foundation/FoundationErrors.swift
Foundation/Host.swift
Foundation/HTTPCookieStorage.swift
Foundation/HTTPCookie.swift
Foundation/HTTPCookieStorage.swift
Foundation/IndexPath.swift
Foundation/IndexSet.swift
Foundation/ISO8601DateFormatter.swift
Expand All @@ -157,10 +161,10 @@ add_swift_library(Foundation
Foundation/LengthFormatter.swift
Foundation/Locale.swift
Foundation/MassFormatter.swift
Foundation/MeasurementFormatter.swift
Foundation/Measurement.swift
Foundation/NotificationQueue.swift
Foundation/MeasurementFormatter.swift
Foundation/Notification.swift
Foundation/NotificationQueue.swift
Foundation/NSArray.swift
Foundation/NSAttributedString.swift
Foundation/NSCache.swift
Expand All @@ -176,6 +180,7 @@ add_swift_library(Foundation
Foundation/NSComparisonPredicate.swift
Foundation/NSCompoundPredicate.swift
Foundation/NSConcreteValue.swift
Foundation/NSData+DataProtocol.swift
Foundation/NSData.swift
Foundation/NSDate.swift
Foundation/NSDecimalNumber.swift
Expand All @@ -186,8 +191,8 @@ add_swift_library(Foundation
Foundation/NSGeometry.swift
Foundation/NSIndexPath.swift
Foundation/NSIndexSet.swift
Foundation/NSKeyedArchiverHelpers.swift
Foundation/NSKeyedArchiver.swift
Foundation/NSKeyedArchiverHelpers.swift
Foundation/NSKeyedCoderOldStyleArray.swift
Foundation/NSKeyedUnarchiver.swift
Foundation/NSLocale.swift
Expand All @@ -209,68 +214,69 @@ add_swift_library(Foundation
Foundation/NSSet.swift
Foundation/NSSortDescriptor.swift
Foundation/NSSpecialValue.swift
Foundation/NSStringAPI.swift
Foundation/NSString.swift
Foundation/NSStringAPI.swift
Foundation/NSSwiftRuntime.swift
Foundation/NSTextCheckingResult.swift
Foundation/NSTimeZone.swift
Foundation/NSURL.swift
Foundation/NSURLError.swift
Foundation/NSURLRequest.swift
Foundation/NSURL.swift
Foundation/NSUUID.swift
Foundation/NSValue.swift
Foundation/NumberFormatter.swift
Foundation/Operation.swift
Foundation/PersonNameComponentsFormatter.swift
Foundation/PersonNameComponents.swift
Foundation/PortMessage.swift
Foundation/PersonNameComponentsFormatter.swift
Foundation/Pointers+DataProtocol.swift
Foundation/Port.swift
Foundation/ProcessInfo.swift
Foundation/PortMessage.swift
Foundation/Process.swift
Foundation/ProgressFraction.swift
Foundation/ProcessInfo.swift
Foundation/Progress.swift
Foundation/ProgressFraction.swift
Foundation/PropertyListSerialization.swift
Foundation/ReferenceConvertible.swift
Foundation/RunLoop.swift
Foundation/Scanner.swift
Foundation/Set.swift
Foundation/Stream.swift
Foundation/StringEncodings.swift
Foundation/String.swift
Foundation/StringEncodings.swift
Foundation/Thread.swift
Foundation/Timer.swift
Foundation/TimeZone.swift
Foundation/Unit.swift
Foundation/URL.swift
Foundation/URLAuthenticationChallenge.swift
Foundation/URLCache.swift
Foundation/URLComponents.swift
Foundation/URLCredentialStorage.swift
Foundation/URLCredential.swift
Foundation/URLCredentialStorage.swift
Foundation/URLProtectionSpace.swift
Foundation/URLProtocol.swift
Foundation/URLRequest.swift
Foundation/URLResponse.swift
Foundation/URLSession/BodySource.swift
Foundation/URLSession/Configuration.swift
Foundation/URLSession/Message.swift
Foundation/URLSession/http/HTTPMessage.swift
Foundation/URLSession/http/HTTPURLProtocol.swift
Foundation/URLSession/libcurl/EasyHandle.swift
Foundation/URLSession/libcurl/libcurlHelpers.swift
Foundation/URLSession/libcurl/MultiHandle.swift
Foundation/URLSession/Message.swift
Foundation/URLSession/NativeProtocol.swift
Foundation/URLSession/TaskRegistry.swift
Foundation/URLSession/TransferState.swift
Foundation/URLSession/URLSession.swift
Foundation/URLSession/URLSessionConfiguration.swift
Foundation/URLSession/URLSessionDelegate.swift
Foundation/URLSession/URLSession.swift
Foundation/URLSession/URLSessionTask.swift
Foundation/URL.swift
Foundation/UserDefaults.swift
Foundation/UUID.swift
Foundation/XMLDocument.swift
Foundation/XMLDTDNode.swift
Foundation/XMLDTD.swift
Foundation/XMLDTDNode.swift
Foundation/XMLElement.swift
Foundation/XMLNode.swift
Foundation/XMLParser.swift
Expand Down
5 changes: 0 additions & 5 deletions CoreFoundation/Collections.subproj/CFData.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
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);
Expand Down Expand Up @@ -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
24 changes: 24 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@
5BA9BEBD1CF4F3B8009DBD6C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA9BEBC1CF4F3B8009DBD6C /* Notification.swift */; };
5BB2C75F1ED9F96200B7BDBD /* CFUserNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B5D89391BBDA7AB00234F36 /* CFUserNotification.h */; settings = {ATTRIBUTES = (Public, ); }; };
5BB5256C1BEC057200E63BE3 /* module.map in Headers */ = {isa = PBXBuildFile; fileRef = 5BDC3F721BCC60EF00ED97BB /* module.map */; settings = {ATTRIBUTES = (Public, ); }; };
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */; };
5BC1B9A621F2759C00524D8C /* DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A521F2759C00524D8C /* DataProtocol.swift */; };
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */; };
5BC1B9AA21F275C400524D8C /* DispatchData+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */; };
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */; };
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */; };
5BC2C00F1C07833200CC214E /* CFStringTransform.c in Sources */ = {isa = PBXBuildFile; fileRef = 5BC2C00D1C07832E00CC214E /* CFStringTransform.c */; };
5BC46D541D05D6D900005853 /* DateInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC46D531D05D6D900005853 /* DateInterval.swift */; };
5BCCA8D91CE6697F0059B963 /* URLComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BCCA8D81CE6697F0059B963 /* URLComponents.swift */; };
Expand Down Expand Up @@ -770,6 +776,12 @@
5BA9BEA51CF3D747009DBD6C /* Data.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = "<group>"; };
5BA9BEA71CF3E7E7009DBD6C /* CharacterSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterSet.swift; sourceTree = "<group>"; };
5BA9BEBC1CF4F3B8009DBD6C /* Notification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContiguousBytes.swift; sourceTree = "<group>"; };
5BC1B9A521F2759C00524D8C /* DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataProtocol.swift; sourceTree = "<group>"; };
5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collections+DataProtocol.swift"; sourceTree = "<group>"; };
5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchData+DataProtocol.swift"; sourceTree = "<group>"; };
5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSData+DataProtocol.swift"; sourceTree = "<group>"; };
5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Pointers+DataProtocol.swift"; sourceTree = "<group>"; };
5BC1D8BC1BF3ADFE009D3973 /* TestCharacterSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCharacterSet.swift; sourceTree = "<group>"; };
5BC2C00D1C07832E00CC214E /* CFStringTransform.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFStringTransform.c; sourceTree = "<group>"; };
5BC46D531D05D6D900005853 /* DateInterval.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateInterval.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1929,6 +1941,12 @@
EADE0B6B1BD15DFF00C49C64 /* NSNull.swift */,
5BDC3F331BCC5DCB00ED97BB /* NSData.swift */,
5BA9BEA51CF3D747009DBD6C /* Data.swift */,
5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */,
5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */,
5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */,
5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */,
5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */,
5BC1B9A521F2759C00524D8C /* DataProtocol.swift */,
EADE0B741BD15DFF00C49C64 /* Progress.swift */,
EA0812681DA71C8A00651B70 /* ProgressFraction.swift */,
5BDC3F381BCC5DCB00ED97BB /* NSError.swift */,
Expand Down Expand Up @@ -2288,6 +2306,7 @@
buildActionMask = 2147483647;
files = (
63DCE9D21EAA430100E9CB02 /* ISO8601DateFormatter.swift in Sources */,
5BC1B9A621F2759C00524D8C /* DataProtocol.swift in Sources */,
5BF7AE831BCD50CD008F214A /* NSArray.swift in Sources */,
B9974B971EDF4A22007F15B8 /* MultiHandle.swift in Sources */,
EADE0B991BD15DFF00C49C64 /* EnergyFormatter.swift in Sources */,
Expand All @@ -2301,6 +2320,7 @@
EADE0BC01BD15E0000C49C64 /* URLProtectionSpace.swift in Sources */,
5BF7AEAC1BCD51F9008F214A /* NSEnumerator.swift in Sources */,
5BA9BEA81CF3E7E7009DBD6C /* CharacterSet.swift in Sources */,
5BC1B9AA21F275C400524D8C /* DispatchData+DataProtocol.swift in Sources */,
61E0117E1C1B55B9000037DD /* Timer.swift in Sources */,
EADE0BCD1BD15E0000C49C64 /* XMLParser.swift in Sources */,
5BDC3FD01BCF17E600ED97BB /* NSCFSet.swift in Sources */,
Expand All @@ -2315,8 +2335,10 @@
EADE0BB01BD15E0000C49C64 /* Port.swift in Sources */,
EADE0BB91BD15E0000C49C64 /* NSTextCheckingResult.swift in Sources */,
EA0812691DA71C8A00651B70 /* ProgressFraction.swift in Sources */,
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */,
5BF7AEBE1BCD51F9008F214A /* NSTimeZone.swift in Sources */,
EADE0B951BD15DFF00C49C64 /* DateComponentsFormatter.swift in Sources */,
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */,
EADE0BBD1BD15E0000C49C64 /* URLCredential.swift in Sources */,
EADE0BCA1BD15E0000C49C64 /* XMLElement.swift in Sources */,
EADE0BA21BD15E0000C49C64 /* JSONSerialization.swift in Sources */,
Expand Down Expand Up @@ -2422,6 +2444,7 @@
B9974B991EDF4A22007F15B8 /* HTTPURLProtocol.swift in Sources */,
5BCD03821D3EE35C00E3FF9B /* TimeZone.swift in Sources */,
EADE0BBC1BD15E0000C49C64 /* URLCache.swift in Sources */,
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */,
5B4092121D1B30B40022B067 /* ExtraStringAPIs.swift in Sources */,
5BC46D541D05D6D900005853 /* DateInterval.swift in Sources */,
EADE0BC51BD15E0000C49C64 /* UserDefaults.swift in Sources */,
Expand All @@ -2432,6 +2455,7 @@
5BDC3FCC1BCF177E00ED97BB /* NSCFString.swift in Sources */,
B9974B9A1EDF4A22007F15B8 /* HTTPMessage.swift in Sources */,
EADE0BAC1BD15E0000C49C64 /* NSOrderedSet.swift in Sources */,
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */,
EADE0BC31BD15E0000C49C64 /* URLResponse.swift in Sources */,
EADE0B971BD15DFF00C49C64 /* Decimal.swift in Sources */,
EADE0B9F1BD15DFF00C49C64 /* HTTPCookieStorage.swift in Sources */,
Expand Down
61 changes: 61 additions & 0 deletions Foundation/Collections+DataProtocol.swift
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 { }
Loading