Skip to content

Commit 0920e69

Browse files
author
Karl Weinmeister
committed
Merge branch 'master' of https://github.com/kweinmeister/swift-corelibs-foundation into energyformatter
# Conflicts: # TestFoundation/main.swift
2 parents e2bc6f2 + 6a7cc93 commit 0920e69

File tree

102 files changed

+2122
-802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2122
-802
lines changed

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@
6666
#if defined(__GNUC__) || TARGET_OS_WIN32
6767
#include <stdint.h>
6868
#include <stdbool.h>
69-
#endif
70-
71-
#if __BLOCKS__
72-
#include <Block.h>
7369
#endif
7470

7571
#if ((TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) && !DEPLOYMENT_RUNTIME_SWIFT

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ CF_EXTERN_C_BEGIN
104104
#endif
105105
#include <pthread.h>
106106

107-
#if __has_include(<os/log.h>)
107+
#if !DEPLOYMENT_RUNTIME_SWIFT && __has_include(<os/log.h>)
108108
#import <os/log.h>
109109
#else
110110
typedef struct os_log_s *os_log_t;
111-
#define os_log(...)
112-
#define os_log_info(...)
113-
#define os_log_debug(...)
114-
#define os_log_error(...)
111+
#define os_log(...) do { } while (0)
112+
#define os_log_info(...) do { } while (0)
113+
#define os_log_debug(...) do { } while (0)
114+
#define os_log_error(...) do { } while (0)
115115
#define os_log_create(...) (NULL)
116116
#endif
117117

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,23 @@ _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (*
13101310
return thread;
13111311
}
13121312

1313+
CF_SWIFT_EXPORT void _CFThreadSetName(const char *_Nullable name) {
1314+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
1315+
pthread_setname_np(name);
1316+
#elif DEPLOYMENT_TARGET_LINUX
1317+
pthread_setname_np(pthread_self(), name);
1318+
#endif
1319+
}
1320+
1321+
CF_SWIFT_EXPORT int _CFThreadGetName(char *buf, int length) {
1322+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
1323+
return pthread_getname_np(pthread_self(), buf, length);
1324+
#elif DEPLOYMENT_TARGET_LINUX
1325+
return pthread_getname_np(pthread_self(), buf, length);
1326+
#endif
1327+
return -1;
1328+
}
1329+
13131330
CF_EXPORT char **_CFEnviron(void) {
13141331
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
13151332
return *_NSGetEnviron();

CoreFoundation/Base.subproj/CFUtilities.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ typedef enum {
604604

605605
static bool also_do_stderr(const _cf_logging_style style) {
606606
bool result = false;
607-
#if DEPLOYMENT_TARGET_EMBEDDED_MINI
607+
#if DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX
608608
// just log to stderr, other logging facilities are out
609609
result = true;
610610
#elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED

CoreFoundation/Base.subproj/ForFoundationOnly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CF_IMPLICIT_BRIDGING_DISABLED
6363
#endif
6464

6565
#if (INCLUDE_OBJC || DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS) && !DEPLOYMENT_RUNTIME_SWIFT
66-
#import <objc/message.h>
66+
#include <objc/message.h>
6767
#endif
6868

6969
// ---- CFBundle material ----------------------------------------

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ typedef pthread_t _CFThreadRef;
298298

299299
CF_EXPORT _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *restrict _Nullable context);
300300

301+
CF_SWIFT_EXPORT void _CFThreadSetName(const char *_Nullable name);
302+
CF_SWIFT_EXPORT int _CFThreadGetName(char *buf, int length);
303+
301304
CF_EXPORT Boolean _CFCharacterSetIsLongCharacterMember(CFCharacterSetRef theSet, UTF32Char theChar);
302305
CF_EXPORT CFCharacterSetRef _CFCharacterSetCreateCopy(CFAllocatorRef alloc, CFCharacterSetRef theSet);
303306
CF_EXPORT CFMutableCharacterSetRef _CFCharacterSetCreateMutableCopy(CFAllocatorRef alloc, CFCharacterSetRef theSet);

CoreFoundation/Base.subproj/SwiftRuntime/CoreFoundation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
#include <time.h>
4141

4242
#if __has_include(<netdb.h>)
43-
#include <netdb.h> // for NSHost.swift
43+
#include <netdb.h> // for Host.swift
44+
#endif
45+
46+
#if __has_include(<ifaddrs.h>)
47+
#include <ifaddrs.h> // for Host.swift
4448
#endif
4549

4650
#if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__)

CoreFoundation/RunLoop.subproj/CFMachPort.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <stdio.h>
2121
#include "CFInternal.h"
2222
#include <os/lock.h>
23-
#include <os/log.h>
2423

2524

2625
// This queue is used for the cancel/event handler for dead name notification.

Docs/GettingStarted.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In order to build on OS X, you will need:
88

99
* The latest version of Xcode
1010
* The latest version of the OS X SDK (at this time: 10.11)
11-
* The [current Swift toolchain](https://swift.org/download/#latest-development-snapshots).
11+
* The [current Swift toolchain](https://swift.org/download/#snapshots).
1212

1313
Foundation is developed at the same time as the rest of Swift, so the most recent version of the compiler is required in order to build it.
1414

Docs/Status.md

Lines changed: 22 additions & 22 deletions
Large diffs are not rendered by default.

Foundation.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
5BF7AEAC1BCD51F9008F214A /* NSEnumerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F371BCC5DCB00ED97BB /* NSEnumerator.swift */; };
284284
5BF7AEAD1BCD51F9008F214A /* NSError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F381BCC5DCB00ED97BB /* NSError.swift */; };
285285
5BF7AEAE1BCD51F9008F214A /* NSFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F391BCC5DCB00ED97BB /* NSFormatter.swift */; };
286-
5BF7AEAF1BCD51F9008F214A /* NSHost.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F3A1BCC5DCB00ED97BB /* NSHost.swift */; };
286+
5BF7AEAF1BCD51F9008F214A /* Host.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F3A1BCC5DCB00ED97BB /* Host.swift */; };
287287
5BF7AEB01BCD51F9008F214A /* NSLocale.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F3B1BCC5DCB00ED97BB /* NSLocale.swift */; };
288288
5BF7AEB11BCD51F9008F214A /* NSLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F3C1BCC5DCB00ED97BB /* NSLock.swift */; };
289289
5BF7AEB21BCD51F9008F214A /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F3D1BCC5DCB00ED97BB /* NSNumber.swift */; };
@@ -316,6 +316,7 @@
316316
BDFDF0A71DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFDF0A61DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift */; };
317317
BF8E65311DC3B3CB005AB5C3 /* TestNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF8E65301DC3B3CB005AB5C3 /* TestNotification.swift */; };
318318
CC5249C01D341D23007CB54D /* TestUnitConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC5249BF1D341D23007CB54D /* TestUnitConverter.swift */; };
319+
CD1C7F7D1E303B47008E331C /* TestNSError.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1C7F7C1E303B47008E331C /* TestNSError.swift */; };
319320
CE19A88C1C23AA2300B4CB6A /* NSStringTestData.txt in Resources */ = {isa = PBXBuildFile; fileRef = CE19A88B1C23AA2300B4CB6A /* NSStringTestData.txt */; };
320321
D31302011C30CEA900295652 /* NSConcreteValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D31302001C30CEA900295652 /* NSConcreteValue.swift */; };
321322
D370696E1C394FBF00295652 /* NSKeyedUnarchiver-RangeTest.plist in Resources */ = {isa = PBXBuildFile; fileRef = D370696D1C394FBF00295652 /* NSKeyedUnarchiver-RangeTest.plist */; };
@@ -703,7 +704,7 @@
703704
5BDC3F371BCC5DCB00ED97BB /* NSEnumerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSEnumerator.swift; sourceTree = "<group>"; };
704705
5BDC3F381BCC5DCB00ED97BB /* NSError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NSError.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
705706
5BDC3F391BCC5DCB00ED97BB /* NSFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSFormatter.swift; sourceTree = "<group>"; };
706-
5BDC3F3A1BCC5DCB00ED97BB /* NSHost.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSHost.swift; sourceTree = "<group>"; };
707+
5BDC3F3A1BCC5DCB00ED97BB /* Host.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Host.swift; sourceTree = "<group>"; };
707708
5BDC3F3B1BCC5DCB00ED97BB /* NSLocale.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NSLocale.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
708709
5BDC3F3C1BCC5DCB00ED97BB /* NSLock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NSLock.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
709710
5BDC3F3D1BCC5DCB00ED97BB /* NSNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = NSNumber.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
@@ -761,6 +762,7 @@
761762
C2A9D75B1C15C08B00993803 /* TestNSUUID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSUUID.swift; sourceTree = "<group>"; };
762763
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSAffineTransform.swift; sourceTree = "<group>"; };
763764
CC5249BF1D341D23007CB54D /* TestUnitConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestUnitConverter.swift; sourceTree = "<group>"; };
765+
CD1C7F7C1E303B47008E331C /* TestNSError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSError.swift; sourceTree = "<group>"; };
764766
CE19A88B1C23AA2300B4CB6A /* NSStringTestData.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NSStringTestData.txt; sourceTree = "<group>"; };
765767
D3047AEB1C38BC3300295652 /* TestNSValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSValue.swift; sourceTree = "<group>"; };
766768
D31302001C30CEA900295652 /* NSConcreteValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSConcreteValue.swift; sourceTree = "<group>"; };
@@ -1398,6 +1400,7 @@
13981400
EA54A6FA1DB16D53009E0809 /* TestObjCRuntime.swift */,
13991401
BF8E65301DC3B3CB005AB5C3 /* TestNotification.swift */,
14001402
BDFDF0A61DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift */,
1403+
CD1C7F7C1E303B47008E331C /* TestNSError.swift */,
14011404
);
14021405
name = Tests;
14031406
sourceTree = "<group>";
@@ -1516,7 +1519,7 @@
15161519
5BA9BEA31CF380E8009DBD6C /* URLRequest.swift */,
15171520
EADE0B601BD15DFF00C49C64 /* NSHTTPCookie.swift */,
15181521
EADE0B611BD15DFF00C49C64 /* NSHTTPCookieStorage.swift */,
1519-
5BDC3F3A1BCC5DCB00ED97BB /* NSHost.swift */,
1522+
5BDC3F3A1BCC5DCB00ED97BB /* Host.swift */,
15201523
);
15211524
name = URL;
15221525
sourceTree = "<group>";
@@ -2084,7 +2087,7 @@
20842087
D39A14011C2D6E0A00295652 /* NSKeyedUnarchiver.swift in Sources */,
20852088
5B4092101D1B304C0022B067 /* NSStringEncodings.swift in Sources */,
20862089
5BECBA381D1CAD7000B39B1F /* Measurement.swift in Sources */,
2087-
5BF7AEAF1BCD51F9008F214A /* NSHost.swift in Sources */,
2090+
5BF7AEAF1BCD51F9008F214A /* Host.swift in Sources */,
20882091
EADE0B4E1BD09E0800C49C64 /* NSAffineTransform.swift in Sources */,
20892092
EADE0BC71BD15E0000C49C64 /* NSXMLDocument.swift in Sources */,
20902093
5BDC3FCE1BCF17D300ED97BB /* NSCFDictionary.swift in Sources */,
@@ -2279,6 +2282,7 @@
22792282
5B13B3511C582D4C00651CE2 /* TestNSByteCountFormatter.swift in Sources */,
22802283
BDFDF0A71DFF5B3E00C04CC5 /* TestNSPersonNameComponents.swift in Sources */,
22812284
5B13B3501C582D4C00651CE2 /* TestUtils.swift in Sources */,
2285+
CD1C7F7D1E303B47008E331C /* TestNSError.swift in Sources */,
22822286
294E3C1D1CC5E19300E4F44C /* TestNSAttributedString.swift in Sources */,
22832287
5B13B3431C582D4C00651CE2 /* TestNSScanner.swift in Sources */,
22842288
5B13B3401C582D4C00651CE2 /* TestNSRange.swift in Sources */,

Foundation/Boxing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
///
1515
/// Note: This assumes that the result of calling copy() is mutable. The documentation says that classes which do not have a mutable/immutable distinction should just adopt NSCopying instead of NSMutableCopying.
1616
internal final class _MutableHandle<MutableType : NSObject> where MutableType : NSCopying {
17-
fileprivate var _pointer : MutableType
17+
@_versioned internal var _pointer : MutableType
1818

1919
init(reference : MutableType) {
2020
_pointer = reference.copy() as! MutableType

Foundation/Bridging.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,18 @@ internal final class _SwiftValue : NSObject, NSCopying {
121121
}
122122

123123
override func isEqual(_ value: Any?) -> Bool {
124-
if let other = value as? _SwiftValue {
125-
if self === other {
126-
return true
127-
}
128-
if let otherHashable = other.value as? AnyHashable,
129-
let hashable = self.value as? AnyHashable {
130-
return otherHashable == hashable
131-
}
124+
switch value {
125+
case let other as _SwiftValue:
126+
guard let left = other.value as? AnyHashable,
127+
let right = self.value as? AnyHashable else { return self === other }
132128

133-
} else if let otherHashable = value as? AnyHashable,
134-
let hashable = self.value as? AnyHashable {
135-
return otherHashable == hashable
129+
return left == right
130+
case let other as AnyHashable:
131+
guard let hashable = self.value as? AnyHashable else { return false }
132+
return other == hashable
133+
default:
134+
return false
136135
}
137-
return false
138136
}
139137

140138
public func copy(with zone: NSZone?) -> Any {

Foundation/Calendar.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,15 +1132,35 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
11321132
}
11331133

11341134
extension Calendar : CustomDebugStringConvertible, CustomStringConvertible, CustomReflectable {
1135+
private var _kindDescription : String {
1136+
if self == .autoupdatingCurrent {
1137+
return "autoupdatingCurrent"
1138+
} else if self == .current {
1139+
return "current"
1140+
} else {
1141+
return "fixed"
1142+
}
1143+
}
1144+
11351145
public var description: String {
1136-
return _handle.map { $0.description }
1146+
return "\(identifier) (\(_kindDescription))"
11371147
}
11381148

11391149
public var debugDescription: String {
1140-
return _handle.map { $0.debugDescription }
1150+
return "\(identifier) (\(_kindDescription))"
11411151
}
11421152

1143-
public var customMirror: Mirror { NSUnimplemented() }
1153+
public var customMirror: Mirror {
1154+
let children: [(label: String?, value: Any)] = [
1155+
(label: "identifier", value: identifier),
1156+
(label: "kind", value: _kindDescription),
1157+
(label: "locale", value: locale as Any),
1158+
(label: "timeZone", value: timeZone),
1159+
(label: "firstWeekDay", value: firstWeekday),
1160+
(label: "minimumDaysInFirstWeek", value: minimumDaysInFirstWeek)
1161+
]
1162+
return Mirror(self, children: children, displayStyle: Mirror.DisplayStyle.struct)
1163+
}
11441164
}
11451165

11461166
extension Calendar: _ObjectTypeBridgeable {

Foundation/Data.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,17 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
971971
return _DataStorage(bytes: $0.baseAddress, length: $0.count)
972972
}
973973
}
974+
975+
/// Initialze a `Data` with a repeating byte pattern
976+
///
977+
/// - parameter repeatedValue: A byte to initialze the pattern
978+
/// - parameter count: The number of bytes the data initially contains initialzed to the repeatedValue
979+
public init(repeating repeatedValue: UInt8, count: Int) {
980+
self.init(count: count)
981+
withUnsafeMutableBytes { (bytes: UnsafeMutablePointer<UInt8>) -> Void in
982+
memset(bytes, Int32(repeatedValue), count)
983+
}
984+
}
974985

975986
/// Initialize a `Data` with the specified size.
976987
///
@@ -1266,7 +1277,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
12661277
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
12671278
@inline(__always)
12681279
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
1269-
if buffer.count == 0 { return }
1280+
if buffer.isEmpty { return }
12701281
if !isKnownUniquelyReferenced(&_backing) {
12711282
_backing = _backing.mutableCopy()
12721283
}
@@ -1293,7 +1304,9 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
12931304
for byte in newElements {
12941305
self[idx] = byte
12951306
idx += 1
1296-
count = idx
1307+
if idx > count {
1308+
count = idx
1309+
}
12971310
}
12981311
}
12991312

@@ -1390,7 +1403,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
13901403
let shift = resultCount - currentCount
13911404
let start = subrange.lowerBound
13921405

1393-
self.withUnsafeMutableBytes { (bytes : UnsafeMutablePointer<UInt8>) -> () in
1406+
self.withUnsafeMutableBytes { (bytes : UnsafeMutablePointer<UInt8>) -> Void in
13941407
if shift != 0 {
13951408
let destination = bytes + start + replacementCount
13961409
let source = bytes + start + subrangeCount
@@ -1637,7 +1650,7 @@ extension Data : CustomStringConvertible, CustomDebugStringConvertible, CustomRe
16371650

16381651
// Minimal size data is output as an array
16391652
if nBytes < 64 {
1640-
children.append((label: "bytes", value: self[0..<nBytes].map { $0 }))
1653+
children.append((label: "bytes", value: Array(self[0..<nBytes])))
16411654
}
16421655

16431656
let m = Mirror(self, children:children, displayStyle: Mirror.DisplayStyle.struct)

0 commit comments

Comments
 (0)