Skip to content

Commit b1de8e7

Browse files
committed
Import Data and DataProtocol from the overlay (and correct some incorrect CFData and NSData usages)
1 parent b8888e5 commit b1de8e7

File tree

14 files changed

+2582
-1132
lines changed

14 files changed

+2582
-1132
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: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@
269269
5BA9BEBD1CF4F3B8009DBD6C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA9BEBC1CF4F3B8009DBD6C /* Notification.swift */; };
270270
5BB2C75F1ED9F96200B7BDBD /* CFUserNotification.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B5D89391BBDA7AB00234F36 /* CFUserNotification.h */; settings = {ATTRIBUTES = (Public, ); }; };
271271
5BB5256C1BEC057200E63BE3 /* module.map in Headers */ = {isa = PBXBuildFile; fileRef = 5BDC3F721BCC60EF00ED97BB /* module.map */; settings = {ATTRIBUTES = (Public, ); }; };
272+
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */; };
273+
5BC1B9A621F2759C00524D8C /* DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A521F2759C00524D8C /* DataProtocol.swift */; };
274+
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */; };
275+
5BC1B9AA21F275C400524D8C /* DispatchData+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */; };
276+
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */; };
277+
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */; };
272278
5BC2C00F1C07833200CC214E /* CFStringTransform.c in Sources */ = {isa = PBXBuildFile; fileRef = 5BC2C00D1C07832E00CC214E /* CFStringTransform.c */; };
273279
5BC46D541D05D6D900005853 /* DateInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC46D531D05D6D900005853 /* DateInterval.swift */; };
274280
5BCCA8D91CE6697F0059B963 /* URLComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BCCA8D81CE6697F0059B963 /* URLComponents.swift */; };
@@ -774,6 +780,12 @@
774780
5BA9BEA51CF3D747009DBD6C /* Data.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = "<group>"; };
775781
5BA9BEA71CF3E7E7009DBD6C /* CharacterSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterSet.swift; sourceTree = "<group>"; };
776782
5BA9BEBC1CF4F3B8009DBD6C /* Notification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
783+
5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContiguousBytes.swift; sourceTree = "<group>"; };
784+
5BC1B9A521F2759C00524D8C /* DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataProtocol.swift; sourceTree = "<group>"; };
785+
5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collections+DataProtocol.swift"; sourceTree = "<group>"; };
786+
5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchData+DataProtocol.swift"; sourceTree = "<group>"; };
787+
5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSData+DataProtocol.swift"; sourceTree = "<group>"; };
788+
5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Pointers+DataProtocol.swift"; sourceTree = "<group>"; };
777789
5BC1D8BC1BF3ADFE009D3973 /* TestCharacterSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestCharacterSet.swift; sourceTree = "<group>"; };
778790
5BC2C00D1C07832E00CC214E /* CFStringTransform.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFStringTransform.c; sourceTree = "<group>"; };
779791
5BC46D531D05D6D900005853 /* DateInterval.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateInterval.swift; sourceTree = "<group>"; };
@@ -1935,6 +1947,12 @@
19351947
EADE0B6B1BD15DFF00C49C64 /* NSNull.swift */,
19361948
5BDC3F331BCC5DCB00ED97BB /* NSData.swift */,
19371949
5BA9BEA51CF3D747009DBD6C /* Data.swift */,
1950+
5BC1B9A321F2757F00524D8C /* ContiguousBytes.swift */,
1951+
5BC1B9A721F275B000524D8C /* Collections+DataProtocol.swift */,
1952+
5BC1B9A921F275C400524D8C /* DispatchData+DataProtocol.swift */,
1953+
5BC1B9AB21F275D500524D8C /* NSData+DataProtocol.swift */,
1954+
5BC1B9AD21F275E900524D8C /* Pointers+DataProtocol.swift */,
1955+
5BC1B9A521F2759C00524D8C /* DataProtocol.swift */,
19381956
EADE0B741BD15DFF00C49C64 /* Progress.swift */,
19391957
EA0812681DA71C8A00651B70 /* ProgressFraction.swift */,
19401958
5BDC3F381BCC5DCB00ED97BB /* NSError.swift */,
@@ -2295,6 +2313,7 @@
22952313
buildActionMask = 2147483647;
22962314
files = (
22972315
63DCE9D21EAA430100E9CB02 /* ISO8601DateFormatter.swift in Sources */,
2316+
5BC1B9A621F2759C00524D8C /* DataProtocol.swift in Sources */,
22982317
5BF7AE831BCD50CD008F214A /* NSArray.swift in Sources */,
22992318
B9974B971EDF4A22007F15B8 /* MultiHandle.swift in Sources */,
23002319
EADE0B991BD15DFF00C49C64 /* EnergyFormatter.swift in Sources */,
@@ -2308,6 +2327,7 @@
23082327
EADE0BC01BD15E0000C49C64 /* URLProtectionSpace.swift in Sources */,
23092328
5BF7AEAC1BCD51F9008F214A /* NSEnumerator.swift in Sources */,
23102329
5BA9BEA81CF3E7E7009DBD6C /* CharacterSet.swift in Sources */,
2330+
5BC1B9AA21F275C400524D8C /* DispatchData+DataProtocol.swift in Sources */,
23112331
61E0117E1C1B55B9000037DD /* Timer.swift in Sources */,
23122332
EADE0BCD1BD15E0000C49C64 /* XMLParser.swift in Sources */,
23132333
5BDC3FD01BCF17E600ED97BB /* NSCFSet.swift in Sources */,
@@ -2322,8 +2342,10 @@
23222342
EADE0BB01BD15E0000C49C64 /* Port.swift in Sources */,
23232343
EADE0BB91BD15E0000C49C64 /* NSTextCheckingResult.swift in Sources */,
23242344
EA0812691DA71C8A00651B70 /* ProgressFraction.swift in Sources */,
2345+
5BC1B9A821F275B000524D8C /* Collections+DataProtocol.swift in Sources */,
23252346
5BF7AEBE1BCD51F9008F214A /* NSTimeZone.swift in Sources */,
23262347
EADE0B951BD15DFF00C49C64 /* DateComponentsFormatter.swift in Sources */,
2348+
5BC1B9AE21F275E900524D8C /* Pointers+DataProtocol.swift in Sources */,
23272349
EADE0BBD1BD15E0000C49C64 /* URLCredential.swift in Sources */,
23282350
EADE0BCA1BD15E0000C49C64 /* XMLElement.swift in Sources */,
23292351
EADE0BA21BD15E0000C49C64 /* JSONSerialization.swift in Sources */,
@@ -2429,6 +2451,7 @@
24292451
B9974B991EDF4A22007F15B8 /* HTTPURLProtocol.swift in Sources */,
24302452
5BCD03821D3EE35C00E3FF9B /* TimeZone.swift in Sources */,
24312453
EADE0BBC1BD15E0000C49C64 /* URLCache.swift in Sources */,
2454+
5BC1B9AC21F275D500524D8C /* NSData+DataProtocol.swift in Sources */,
24322455
5B4092121D1B30B40022B067 /* ExtraStringAPIs.swift in Sources */,
24332456
5BC46D541D05D6D900005853 /* DateInterval.swift in Sources */,
24342457
EADE0BC51BD15E0000C49C64 /* UserDefaults.swift in Sources */,
@@ -2439,6 +2462,7 @@
24392462
5BDC3FCC1BCF177E00ED97BB /* NSCFString.swift in Sources */,
24402463
B9974B9A1EDF4A22007F15B8 /* HTTPMessage.swift in Sources */,
24412464
EADE0BAC1BD15E0000C49C64 /* NSOrderedSet.swift in Sources */,
2465+
5BC1B9A421F2757F00524D8C /* ContiguousBytes.swift in Sources */,
24422466
EADE0BC31BD15E0000C49C64 /* URLResponse.swift in Sources */,
24432467
EADE0B971BD15DFF00C49C64 /* Decimal.swift in Sources */,
24442468
EADE0B9F1BD15DFF00C49C64 /* HTTPCookieStorage.swift in Sources */,
@@ -3096,7 +3120,7 @@
30963120
PRODUCT_NAME = "$(TARGET_NAME)";
30973121
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
30983122
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
3099-
SWIFT_VERSION = 3.0;
3123+
SWIFT_VERSION = 4.2;
31003124
};
31013125
name = Debug;
31023126
};
@@ -3116,7 +3140,7 @@
31163140
MACOSX_DEPLOYMENT_TARGET = 10.12;
31173141
PRODUCT_BUNDLE_IDENTIFIER = org.swift.xdgTestHelper;
31183142
PRODUCT_NAME = "$(TARGET_NAME)";
3119-
SWIFT_VERSION = 3.0;
3143+
SWIFT_VERSION = 4.2;
31203144
};
31213145
name = Release;
31223146
};
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)