Skip to content

Commit 4a25565

Browse files
authored
Import Data and DataProtocol from the overlay (and correct some incorrect CFData and NSData usages) (#1834)
* Import Data and DataProtocol from the overlay (and correct some incorrect CFData and NSData usages) * Linux build fixes for Data and DataProtocol correcting nullability and inline/objc decorators
1 parent 95906f2 commit 4a25565

File tree

14 files changed

+2583
-1130
lines changed

14 files changed

+2583
-1130
lines changed

CMakeLists.txt

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,19 @@ add_swift_library(Foundation
130130
Foundation/CGFloat.swift
131131
Foundation/CharacterSet.swift
132132
Foundation/Codable.swift
133+
Foundation/Collections+DataProtocol.swift
134+
Foundation/ContiguousBytes.swift
133135
Foundation/Data.swift
134-
Foundation/DateComponentsFormatter.swift
136+
Foundation/DataProtocol.swift
137+
Foundation/Date.swift
135138
Foundation/DateComponents.swift
139+
Foundation/DateComponentsFormatter.swift
136140
Foundation/DateFormatter.swift
137-
Foundation/DateIntervalFormatter.swift
138141
Foundation/DateInterval.swift
139-
Foundation/Date.swift
142+
Foundation/DateIntervalFormatter.swift
140143
Foundation/Decimal.swift
141144
Foundation/Dictionary.swift
145+
Foundation/DispatchData+DataProtocol.swift
142146
Foundation/EnergyFormatter.swift
143147
Foundation/ExtraStringAPIs.swift
144148
Foundation/FileHandle.swift
@@ -147,8 +151,8 @@ add_swift_library(Foundation
147151
Foundation/Formatter.swift
148152
Foundation/FoundationErrors.swift
149153
Foundation/Host.swift
150-
Foundation/HTTPCookieStorage.swift
151154
Foundation/HTTPCookie.swift
155+
Foundation/HTTPCookieStorage.swift
152156
Foundation/IndexPath.swift
153157
Foundation/IndexSet.swift
154158
Foundation/ISO8601DateFormatter.swift
@@ -157,10 +161,10 @@ add_swift_library(Foundation
157161
Foundation/LengthFormatter.swift
158162
Foundation/Locale.swift
159163
Foundation/MassFormatter.swift
160-
Foundation/MeasurementFormatter.swift
161164
Foundation/Measurement.swift
162-
Foundation/NotificationQueue.swift
165+
Foundation/MeasurementFormatter.swift
163166
Foundation/Notification.swift
167+
Foundation/NotificationQueue.swift
164168
Foundation/NSArray.swift
165169
Foundation/NSAttributedString.swift
166170
Foundation/NSCache.swift
@@ -176,6 +180,7 @@ add_swift_library(Foundation
176180
Foundation/NSComparisonPredicate.swift
177181
Foundation/NSCompoundPredicate.swift
178182
Foundation/NSConcreteValue.swift
183+
Foundation/NSData+DataProtocol.swift
179184
Foundation/NSData.swift
180185
Foundation/NSDate.swift
181186
Foundation/NSDecimalNumber.swift
@@ -186,8 +191,8 @@ add_swift_library(Foundation
186191
Foundation/NSGeometry.swift
187192
Foundation/NSIndexPath.swift
188193
Foundation/NSIndexSet.swift
189-
Foundation/NSKeyedArchiverHelpers.swift
190194
Foundation/NSKeyedArchiver.swift
195+
Foundation/NSKeyedArchiverHelpers.swift
191196
Foundation/NSKeyedCoderOldStyleArray.swift
192197
Foundation/NSKeyedUnarchiver.swift
193198
Foundation/NSLocale.swift
@@ -209,68 +214,69 @@ add_swift_library(Foundation
209214
Foundation/NSSet.swift
210215
Foundation/NSSortDescriptor.swift
211216
Foundation/NSSpecialValue.swift
212-
Foundation/NSStringAPI.swift
213217
Foundation/NSString.swift
218+
Foundation/NSStringAPI.swift
214219
Foundation/NSSwiftRuntime.swift
215220
Foundation/NSTextCheckingResult.swift
216221
Foundation/NSTimeZone.swift
222+
Foundation/NSURL.swift
217223
Foundation/NSURLError.swift
218224
Foundation/NSURLRequest.swift
219-
Foundation/NSURL.swift
220225
Foundation/NSUUID.swift
221226
Foundation/NSValue.swift
222227
Foundation/NumberFormatter.swift
223228
Foundation/Operation.swift
224-
Foundation/PersonNameComponentsFormatter.swift
225229
Foundation/PersonNameComponents.swift
226-
Foundation/PortMessage.swift
230+
Foundation/PersonNameComponentsFormatter.swift
231+
Foundation/Pointers+DataProtocol.swift
227232
Foundation/Port.swift
228-
Foundation/ProcessInfo.swift
233+
Foundation/PortMessage.swift
229234
Foundation/Process.swift
230-
Foundation/ProgressFraction.swift
235+
Foundation/ProcessInfo.swift
231236
Foundation/Progress.swift
237+
Foundation/ProgressFraction.swift
232238
Foundation/PropertyListSerialization.swift
233239
Foundation/ReferenceConvertible.swift
234240
Foundation/RunLoop.swift
235241
Foundation/Scanner.swift
236242
Foundation/Set.swift
237243
Foundation/Stream.swift
238-
Foundation/StringEncodings.swift
239244
Foundation/String.swift
245+
Foundation/StringEncodings.swift
240246
Foundation/Thread.swift
241247
Foundation/Timer.swift
242248
Foundation/TimeZone.swift
243249
Foundation/Unit.swift
250+
Foundation/URL.swift
244251
Foundation/URLAuthenticationChallenge.swift
245252
Foundation/URLCache.swift
246253
Foundation/URLComponents.swift
247-
Foundation/URLCredentialStorage.swift
248254
Foundation/URLCredential.swift
255+
Foundation/URLCredentialStorage.swift
249256
Foundation/URLProtectionSpace.swift
250257
Foundation/URLProtocol.swift
251258
Foundation/URLRequest.swift
252259
Foundation/URLResponse.swift
253260
Foundation/URLSession/BodySource.swift
254261
Foundation/URLSession/Configuration.swift
255-
Foundation/URLSession/Message.swift
256262
Foundation/URLSession/http/HTTPMessage.swift
257263
Foundation/URLSession/http/HTTPURLProtocol.swift
258264
Foundation/URLSession/libcurl/EasyHandle.swift
259265
Foundation/URLSession/libcurl/libcurlHelpers.swift
260266
Foundation/URLSession/libcurl/MultiHandle.swift
267+
Foundation/URLSession/Message.swift
261268
Foundation/URLSession/NativeProtocol.swift
262269
Foundation/URLSession/TaskRegistry.swift
263270
Foundation/URLSession/TransferState.swift
271+
Foundation/URLSession/URLSession.swift
264272
Foundation/URLSession/URLSessionConfiguration.swift
265273
Foundation/URLSession/URLSessionDelegate.swift
266-
Foundation/URLSession/URLSession.swift
267274
Foundation/URLSession/URLSessionTask.swift
268-
Foundation/URL.swift
269275
Foundation/UserDefaults.swift
270276
Foundation/UUID.swift
271277
Foundation/XMLDocument.swift
272-
Foundation/XMLDTDNode.swift
273278
Foundation/XMLDTD.swift
279+
Foundation/XMLDTDNode.swift
274280
Foundation/XMLElement.swift
275281
Foundation/XMLNode.swift
276282
Foundation/XMLParser.swift

CoreFoundation/Collections.subproj/CFData.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ typedef enum {
8888
kCFMutable = 0x3 /* changeable and variable capacity */
8989
} _CFDataMutableVariety;
9090

91-
#define __CFGenericValidateMutability(variety) \
92-
CFAssert1((variety != kCFFixedMutable && variety != kCFMutable), __kCFLogAssertion, "%s(): variety is not mutable", __PRETTY_FUNCTION__);
93-
9491
CF_INLINE Boolean __CFDataIsMutable(CFDataRef data) {
9592
return __CFRuntimeGetFlag(data, __kCFMutable);
9693
}
@@ -377,7 +374,6 @@ static Boolean __CFDataShouldUseAllocator(CFAllocatorRef allocator) {
377374
// that there should be no deallocator, and the bytes should be copied.
378375
static CFMutableDataRef __CFDataInit(CFAllocatorRef allocator, _CFDataMutableVariety variety, CFIndex capacity, const uint8_t *bytes, CFIndex length, CFAllocatorRef bytesDeallocator) CF_RETURNS_RETAINED {
379376
CFMutableDataRef memory;
380-
__CFGenericValidateMutability(variety);
381377
CFAssert2(0 <= capacity, __kCFLogAssertion, "%s(): capacity (%ld) cannot be less than zero", __PRETTY_FUNCTION__, capacity);
382378
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);
383379
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
842838
}
843839

844840
#undef __CFDataValidateRange
845-
#undef __CFGenericValidateMutability
846841
#undef INLINE_BYTES_THRESHOLD
847842
#undef CFDATA_MAX_SIZE
848843
#undef REVERSE_BUFFER

Foundation.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@
267267
5BA9BEBD1CF4F3B8009DBD6C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA9BEBC1CF4F3B8009DBD6C /* Notification.swift */; };
268268
5BB2C75F1ED9F96200B7BDBD /* CFUserNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B5D89391BBDA7AB00234F36 /* CFUserNotification.h */; settings = {ATTRIBUTES = (Public, ); }; };
269269
5BB5256C1BEC057200E63BE3 /* module.map in Headers */ = {isa = PBXBuildFile; fileRef = 5BDC3F721BCC60EF00ED97BB /* module.map */; settings = {ATTRIBUTES = (Public, ); }; };
270+
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */; };
271+
5BC1B9A621F2759C00524D8C /* DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A521F2759C00524D8C /* DataProtocol.swift */; };
272+
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */; };
273+
5BC1B9AA21F275C400524D8C /* DispatchData+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */; };
274+
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */; };
275+
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */; };
270276
5BC2C00F1C07833200CC214E /* CFStringTransform.c in Sources */ = {isa = PBXBuildFile; fileRef = 5BC2C00D1C07832E00CC214E /* CFStringTransform.c */; };
271277
5BC46D541D05D6D900005853 /* DateInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC46D531D05D6D900005853 /* DateInterval.swift */; };
272278
5BCCA8D91CE6697F0059B963 /* URLComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BCCA8D81CE6697F0059B963 /* URLComponents.swift */; };
@@ -770,6 +776,12 @@
770776
5BA9BEA51CF3D747009DBD6C /* Data.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = "<group>"; };
771777
5BA9BEA71CF3E7E7009DBD6C /* CharacterSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterSet.swift; sourceTree = "<group>"; };
772778
5BA9BEBC1CF4F3B8009DBD6C /* Notification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
779+
5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContiguousBytes.swift; sourceTree = "<group>"; };
780+
5BC1B9A521F2759C00524D8C /* DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataProtocol.swift; sourceTree = "<group>"; };
781+
5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collections+DataProtocol.swift"; sourceTree = "<group>"; };
782+
5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchData+DataProtocol.swift"; sourceTree = "<group>"; };
783+
5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSData+DataProtocol.swift"; sourceTree = "<group>"; };
784+
5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Pointers+DataProtocol.swift"; sourceTree = "<group>"; };
773785
5BC1D8BC1BF3ADFE009D3973 /* TestCharacterSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCharacterSet.swift; sourceTree = "<group>"; };
774786
5BC2C00D1C07832E00CC214E /* CFStringTransform.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFStringTransform.c; sourceTree = "<group>"; };
775787
5BC46D531D05D6D900005853 /* DateInterval.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateInterval.swift; sourceTree = "<group>"; };
@@ -1929,6 +1941,12 @@
19291941
EADE0B6B1BD15DFF00C49C64 /* NSNull.swift */,
19301942
5BDC3F331BCC5DCB00ED97BB /* NSData.swift */,
19311943
5BA9BEA51CF3D747009DBD6C /* Data.swift */,
1944+
5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */,
1945+
5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */,
1946+
5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */,
1947+
5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */,
1948+
5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */,
1949+
5BC1B9A521F2759C00524D8C /* DataProtocol.swift */,
19321950
EADE0B741BD15DFF00C49C64 /* Progress.swift */,
19331951
EA0812681DA71C8A00651B70 /* ProgressFraction.swift */,
19341952
5BDC3F381BCC5DCB00ED97BB /* NSError.swift */,
@@ -2288,6 +2306,7 @@
22882306
buildActionMask = 2147483647;
22892307
files = (
22902308
63DCE9D21EAA430100E9CB02 /* ISO8601DateFormatter.swift in Sources */,
2309+
5BC1B9A621F2759C00524D8C /* DataProtocol.swift in Sources */,
22912310
5BF7AE831BCD50CD008F214A /* NSArray.swift in Sources */,
22922311
B9974B971EDF4A22007F15B8 /* MultiHandle.swift in Sources */,
22932312
EADE0B991BD15DFF00C49C64 /* EnergyFormatter.swift in Sources */,
@@ -2301,6 +2320,7 @@
23012320
EADE0BC01BD15E0000C49C64 /* URLProtectionSpace.swift in Sources */,
23022321
5BF7AEAC1BCD51F9008F214A /* NSEnumerator.swift in Sources */,
23032322
5BA9BEA81CF3E7E7009DBD6C /* CharacterSet.swift in Sources */,
2323+
5BC1B9AA21F275C400524D8C /* DispatchData+DataProtocol.swift in Sources */,
23042324
61E0117E1C1B55B9000037DD /* Timer.swift in Sources */,
23052325
EADE0BCD1BD15E0000C49C64 /* XMLParser.swift in Sources */,
23062326
5BDC3FD01BCF17E600ED97BB /* NSCFSet.swift in Sources */,
@@ -2315,8 +2335,10 @@
23152335
EADE0BB01BD15E0000C49C64 /* Port.swift in Sources */,
23162336
EADE0BB91BD15E0000C49C64 /* NSTextCheckingResult.swift in Sources */,
23172337
EA0812691DA71C8A00651B70 /* ProgressFraction.swift in Sources */,
2338+
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */,
23182339
5BF7AEBE1BCD51F9008F214A /* NSTimeZone.swift in Sources */,
23192340
EADE0B951BD15DFF00C49C64 /* DateComponentsFormatter.swift in Sources */,
2341+
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */,
23202342
EADE0BBD1BD15E0000C49C64 /* URLCredential.swift in Sources */,
23212343
EADE0BCA1BD15E0000C49C64 /* XMLElement.swift in Sources */,
23222344
EADE0BA21BD15E0000C49C64 /* JSONSerialization.swift in Sources */,
@@ -2422,6 +2444,7 @@
24222444
B9974B991EDF4A22007F15B8 /* HTTPURLProtocol.swift in Sources */,
24232445
5BCD03821D3EE35C00E3FF9B /* TimeZone.swift in Sources */,
24242446
EADE0BBC1BD15E0000C49C64 /* URLCache.swift in Sources */,
2447+
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */,
24252448
5B4092121D1B30B40022B067 /* ExtraStringAPIs.swift in Sources */,
24262449
5BC46D541D05D6D900005853 /* DateInterval.swift in Sources */,
24272450
EADE0BC51BD15E0000C49C64 /* UserDefaults.swift in Sources */,
@@ -2432,6 +2455,7 @@
24322455
5BDC3FCC1BCF177E00ED97BB /* NSCFString.swift in Sources */,
24332456
B9974B9A1EDF4A22007F15B8 /* HTTPMessage.swift in Sources */,
24342457
EADE0BAC1BD15E0000C49C64 /* NSOrderedSet.swift in Sources */,
2458+
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */,
24352459
EADE0BC31BD15E0000C49C64 /* URLResponse.swift in Sources */,
24362460
EADE0B971BD15DFF00C49C64 /* Decimal.swift in Sources */,
24372461
EADE0B9F1BD15DFF00C49C64 /* HTTPCookieStorage.swift in Sources */,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
//===--- DataProtocol -----------------------------------------------------===//
14+
15+
extension Array: DataProtocol where Element == UInt8 {
16+
public var regions: CollectionOfOne<Array<UInt8>> {
17+
return CollectionOfOne(self)
18+
}
19+
}
20+
21+
extension ArraySlice: DataProtocol where Element == UInt8 {
22+
public var regions: CollectionOfOne<ArraySlice<UInt8>> {
23+
return CollectionOfOne(self)
24+
}
25+
}
26+
27+
extension ContiguousArray: DataProtocol where Element == UInt8 {
28+
public var regions: CollectionOfOne<ContiguousArray<UInt8>> {
29+
return CollectionOfOne(self)
30+
}
31+
}
32+
33+
// FIXME: This currently crashes compilation in the Late Inliner.
34+
// extension CollectionOfOne : DataProtocol where Element == UInt8 {
35+
// public typealias Regions = CollectionOfOne<Data>
36+
//
37+
// public var regions: CollectionOfOne<Data> {
38+
// return CollectionOfOne<Data>(Data(self))
39+
// }
40+
// }
41+
42+
extension EmptyCollection : DataProtocol where Element == UInt8 {
43+
public var regions: EmptyCollection<Data> {
44+
return EmptyCollection<Data>()
45+
}
46+
}
47+
48+
extension Repeated: DataProtocol where Element == UInt8 {
49+
public typealias Regions = Repeated<Data>
50+
51+
public var regions: Repeated<Data> {
52+
guard self.count > 0 else { return repeatElement(Data(), count: 0) }
53+
return repeatElement(Data(CollectionOfOne(self.first!)), count: self.count)
54+
}
55+
}
56+
57+
//===--- MutableDataProtocol ----------------------------------------------===//
58+
59+
extension Array: MutableDataProtocol where Element == UInt8 { }
60+
61+
extension ContiguousArray: MutableDataProtocol where Element == UInt8 { }

0 commit comments

Comments
 (0)