Skip to content

Commit 2e4504f

Browse files
authored
Merge branch 'apple:main' into main
2 parents 32e5c7e + 9f53cc5 commit 2e4504f

Some content is hidden

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

43 files changed

+848
-435
lines changed

CoreFoundation/Base.subproj/CFBase.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
583583
CFAllocatorAllocateCallBack allocateFunc;
584584
void *newptr = NULL;
585585

586+
if (0 < size) {
586587
if (NULL == allocator) {
587588
allocator = __CFGetDefaultAllocator();
588589
}
@@ -594,16 +595,14 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
594595
#else
595596
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
596597
#endif
597-
if (0 == size) return NULL;
598598
#if TARGET_OS_MAC
599599
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
600600
return malloc_zone_malloc((malloc_zone_t *)allocator, size);
601601
}
602602
#endif
603-
newptr = NULL;
604603
allocateFunc = __CFAllocatorGetAllocateFunction(&allocator->_context);
605-
if (allocateFunc) {
606-
newptr = (void *)INVOKE_CALLBACK3(allocateFunc, size, hint, allocator->_context.info);
604+
if (NULL == allocateFunc) return NULL;
605+
newptr = (void *)INVOKE_CALLBACK3(allocateFunc, size, hint, allocator->_context.info);
607606
}
608607
return newptr;
609608
}
@@ -631,14 +630,12 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
631630
return malloc_zone_malloc((malloc_zone_t *)allocator, newsize);
632631
}
633632
#endif
634-
newptr = NULL;
635633
allocateFunc = __CFAllocatorGetAllocateFunction(&allocator->_context);
636-
if (allocateFunc) {
637-
newptr = (void *)INVOKE_CALLBACK3(allocateFunc, newsize, hint, allocator->_context.info);
638-
}
634+
if (NULL == allocateFunc) return NULL;
635+
newptr = (void *)INVOKE_CALLBACK3(allocateFunc, newsize, hint, allocator->_context.info);
639636
return newptr;
640637
}
641-
if (NULL != ptr && 0 == newsize) {
638+
if (NULL != ptr && 0 >= newsize) {
642639
#if TARGET_OS_MAC
643640
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
644641
#if defined(DEBUG)
@@ -655,7 +652,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
655652
}
656653
return NULL;
657654
}
658-
if (NULL == ptr && 0 == newsize) return NULL;
655+
if (NULL == ptr && 0 >= newsize) return NULL;
659656
#if TARGET_OS_MAC
660657
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
661658
return malloc_zone_realloc((malloc_zone_t *)allocator, ptr, newsize);
@@ -670,6 +667,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
670667
void CFAllocatorDeallocate(CFAllocatorRef allocator, void *ptr) {
671668
CFAllocatorDeallocateCallBack deallocateFunc;
672669

670+
if (NULL != ptr) {
673671
if (NULL == allocator) {
674672
allocator = __CFGetDefaultAllocator();
675673
}
@@ -691,35 +689,38 @@ void CFAllocatorDeallocate(CFAllocatorRef allocator, void *ptr) {
691689
}
692690
#endif
693691
deallocateFunc = __CFAllocatorGetDeallocateFunction(&allocator->_context);
694-
if (NULL != ptr && NULL != deallocateFunc) {
692+
if (NULL != deallocateFunc) {
695693
INVOKE_CALLBACK2(deallocateFunc, ptr, allocator->_context.info);
696694
}
695+
}
697696
}
698697

699698
CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint) {
700699
CFAllocatorPreferredSizeCallBack prefFunc;
701-
CFIndex newsize = 0;
700+
CFIndex newsize;
702701

702+
#if !TARGET_OS_MAC
703+
if (0 >= size) {
704+
return 0;
705+
}
706+
#endif
703707
if (NULL == allocator) {
704708
allocator = __CFGetDefaultAllocator();
705709
}
706-
707-
#if TARGET_OS_MAC
708-
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
709-
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
710-
}
711-
#else
712-
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
713-
#endif
714710
#if TARGET_OS_MAC
715711
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
716712
return malloc_good_size(size);
717713
}
714+
if (0 >= size) {
715+
return 0;
716+
}
718717
#endif
718+
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
719719
prefFunc = __CFAllocatorGetPreferredSizeFunction(&allocator->_context);
720-
if (0 < size && NULL != prefFunc) {
721-
newsize = (CFIndex)(INVOKE_CALLBACK3(prefFunc, size, hint, allocator->_context.info));
720+
if (NULL == prefFunc) {
721+
return size;
722722
}
723+
newsize = (CFIndex)(INVOKE_CALLBACK3(prefFunc, size, hint, allocator->_context.info));
723724
if (newsize < size) newsize = size;
724725
return newsize;
725726
}

CoreFoundation/Base.subproj/CFKnownLocations.c

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#include <assert.h>
1818

19+
#if TARGET_OS_WIN32
20+
#include <userenv.h>
21+
#endif
22+
1923
CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUser user, CFStringRef _Nullable username) {
2024
CFURLRef location = NULL;
2125

@@ -76,20 +80,48 @@ CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUs
7680
#elif TARGET_OS_WIN32
7781

7882
switch (user) {
79-
case _kCFKnownLocationUserAny:
80-
location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, CFSTR("\\Users\\All Users\\AppData\\Local"), kCFURLWindowsPathStyle, true);
83+
case _kCFKnownLocationUserAny: {
84+
DWORD size = 0;
85+
GetAllUsersProfileDirectoryW(NULL, &size);
86+
87+
wchar_t* path = (wchar_t*)malloc(size * sizeof(wchar_t));
88+
GetAllUsersProfileDirectoryW(path, &size);
89+
90+
CFStringRef allUsersPath = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, path, size - 1);
91+
free(path);
92+
93+
location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, allUsersPath, kCFURLWindowsPathStyle, true);
94+
CFRelease(allUsersPath);
8195
break;
96+
}
8297
case _kCFKnownLocationUserCurrent:
8398
username = CFGetUserName();
8499
// fallthrough
85-
case _kCFKnownLocationUserByName:
86-
const char *user = CFStringGetCStringPtr(username, kCFStringEncodingUTF8);
87-
CFURLRef userdir = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (const unsigned char *)user, strlen(user), true);
88-
CFURLRef homedir = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("\\Users"), kCFURLWindowsPathStyle, true, userdir);
89-
location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("\\AppData\\Local"), kCFURLWindowsPathStyle, true, homedir);
90-
CFRelease(homedir);
91-
CFRelease(userdir);
100+
case _kCFKnownLocationUserByName: {
101+
DWORD size = 0;
102+
GetProfilesDirectoryW(NULL, &size);
103+
104+
wchar_t* path = (wchar_t*)malloc(size * sizeof(wchar_t));
105+
GetProfilesDirectoryW(path, &size);
106+
107+
CFStringRef pathRef = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, path, size - 1);
108+
free(path);
109+
110+
CFURLRef profilesDir = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, pathRef, kCFURLWindowsPathStyle, true);
111+
CFRelease(pathRef);
112+
113+
CFURLRef usernameDir = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, profilesDir, username, true);
114+
CFURLRef appdataDir = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, usernameDir, CFSTR("AppData"), true);
115+
location = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, appdataDir, CFSTR("Local"), true);
116+
CFRelease(usernameDir);
117+
CFRelease(appdataDir);
118+
119+
CFRelease(profilesDir);
120+
if (user == _kCFKnownLocationUserCurrent) {
121+
CFRelease(username);
122+
}
92123
break;
124+
}
93125
}
94126

95127
#elif TARGET_OS_ANDROID

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ void __CFInitialize(void) {
11791179
if (!__CFInitialized && !__CFInitializing) {
11801180
__CFInitializing = 1;
11811181

1182-
#if __HAS_DISPATCH__
1182+
#if __HAS_DISPATCH__ && !TARGET_OS_MAC
11831183
// libdispatch has to be initialized before CoreFoundation, so to avoid
11841184
// issues with static initializer ordering, we are doing it explicitly.
11851185
libdispatch_init();

Darwin/Foundation-swiftoverlay-Tests/TestCalendar.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class TestCalendar : XCTestCase {
114114

115115
func test_properties() {
116116
// Mainly we want to just make sure these go through to the NSCalendar implementation at this point.
117-
if #available(iOS 8.0, OSX 10.7, *) {
117+
if #available(iOS 8.0, macOS 10.7, *) {
118118
var c = Calendar(identifier: .gregorian)
119119
// Use english localization
120120
c.locale = Locale(identifier: "en_US")
@@ -158,7 +158,7 @@ class TestCalendar : XCTestCase {
158158
XCTAssertEqual(Date(timeIntervalSince1970: 1468652400.0), d1)
159159
XCTAssertEqual(86400, ti)
160160

161-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
161+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
162162
let dateInterval = c.dateInterval(of: .day, for: d)
163163
XCTAssertEqual(DateInterval(start: d1, duration: ti), dateInterval)
164164
}
@@ -202,7 +202,7 @@ class TestCalendar : XCTestCase {
202202

203203
XCTAssertTrue(c.dateIntervalOfWeekend(containing: d, start: &d1, interval: &ti))
204204

205-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
205+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
206206
let thisWeekend = DateInterval(start: Date(timeIntervalSince1970: 1468652400.0), duration: 172800.0)
207207

208208
XCTAssertEqual(thisWeekend, DateInterval(start: d1, duration: ti))
@@ -212,7 +212,7 @@ class TestCalendar : XCTestCase {
212212

213213
XCTAssertTrue(c.nextWeekend(startingAfter: d, start: &d1, interval: &ti))
214214

215-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
215+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
216216
let nextWeekend = DateInterval(start: Date(timeIntervalSince1970: 1469257200.0), duration: 172800.0)
217217

218218
XCTAssertEqual(nextWeekend, DateInterval(start: d1, duration: ti))

Darwin/Foundation-swiftoverlay-Tests/TestCharacterSet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class TestCharacterSet : XCTestCase {
269269

270270
func test_setOperationsOfEmptySet() {
271271
// The following tests pass on these versions of the OS
272-
if #available(OSX 10.12.3, iOS 10.3, watchOS 3.2, tvOS 10.2, *) {
272+
if #available(macOS 10.12.3, iOS 10.3, watchOS 3.2, tvOS 10.2, *) {
273273
let emptySet = CharacterSet()
274274
let abcSet = CharacterSet(charactersIn: "abc")
275275

@@ -304,7 +304,7 @@ class TestCharacterSet : XCTestCase {
304304

305305
/* Disabled now: rdar://problem/31746923
306306
#if os(macOS)
307-
if #available(OSX 10.12.4, iOS 10.3, watchOS 3.2, tvOS 10.2, *) {
307+
if #available(macOS 10.12.4, iOS 10.3, watchOS 3.2, tvOS 10.2, *) {
308308
let abcSet = CharacterSet(charactersIn: "abc")
309309
let abcdSet = CharacterSet(charactersIn: "abcd")
310310

Darwin/Foundation-swiftoverlay-Tests/TestDateInterval.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestDateInterval : XCTestCase {
2323
}
2424

2525
func test_compareDateIntervals() {
26-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
26+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
2727
let start = dateWithString("2010-05-17 14:49:47 -0700")
2828
let duration: TimeInterval = 10000000.0
2929
let testInterval1 = DateInterval(start: start, duration: duration)
@@ -45,7 +45,7 @@ class TestDateInterval : XCTestCase {
4545
}
4646

4747
func test_isEqualToDateInterval() {
48-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
48+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
4949
let start = dateWithString("2010-05-17 14:49:47 -0700")
5050
let duration = 10000000.0
5151
let testInterval1 = DateInterval(start: start, duration: duration)
@@ -89,7 +89,7 @@ class TestDateInterval : XCTestCase {
8989
}
9090

9191
func test_checkIntersection() {
92-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
92+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
9393
let start1 = dateWithString("2010-05-17 14:49:47 -0700")
9494
let end1 = dateWithString("2010-08-17 14:49:47 -0700")
9595

@@ -112,7 +112,7 @@ class TestDateInterval : XCTestCase {
112112
}
113113

114114
func test_validIntersections() {
115-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
115+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
116116
let start1 = dateWithString("2010-05-17 14:49:47 -0700")
117117
let end1 = dateWithString("2010-08-17 14:49:47 -0700")
118118

@@ -139,7 +139,7 @@ class TestDateInterval : XCTestCase {
139139
}
140140

141141
func test_containsDate() {
142-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
142+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
143143
let start = dateWithString("2010-05-17 14:49:47 -0700")
144144
let duration = 10000000.0
145145

@@ -154,7 +154,7 @@ class TestDateInterval : XCTestCase {
154154
}
155155

156156
func test_AnyHashableContainingDateInterval() {
157-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
157+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
158158
let start = dateWithString("2010-05-17 14:49:47 -0700")
159159
let duration = 10000000.0
160160
let values: [DateInterval] = [
@@ -172,7 +172,7 @@ class TestDateInterval : XCTestCase {
172172
}
173173

174174
func test_AnyHashableCreatedFromNSDateInterval() {
175-
if #available(iOS 10.10, OSX 10.12, tvOS 10.0, watchOS 3.0, *) {
175+
if #available(iOS 10.10, macOS 10.12, tvOS 10.0, watchOS 3.0, *) {
176176
let start = dateWithString("2010-05-17 14:49:47 -0700")
177177
let duration = 10000000.0
178178
let values: [NSDateInterval] = [

Darwin/Foundation-swiftoverlay-Tests/TestJSONEncoder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TestJSONEncoder : XCTestCase {
135135
}
136136

137137
let model = Model.testValue
138-
if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
138+
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
139139
let expectedJSON = "{\"top\":{\"first\":\"Johnny Appleseed\",\"second\":\"appleseed@apple.com\"}}".data(using: .utf8)!
140140
_testRoundTrip(of: model, expectedJSON: expectedJSON, outputFormatting: [.sortedKeys])
141141
} else {
@@ -178,7 +178,7 @@ class TestJSONEncoder : XCTestCase {
178178
let model = Model.testValue
179179
// This following test would fail as it attempts to re-encode into already encoded container is invalid. This will always fail
180180
expectCrashLater()
181-
if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
181+
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
182182
_testEncodeFailure(of: model)
183183
} else {
184184
_testEncodeFailure(of: model)
@@ -200,15 +200,15 @@ class TestJSONEncoder : XCTestCase {
200200
}
201201

202202
func testEncodingOutputFormattingSortedKeys() {
203-
if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
203+
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
204204
let expectedJSON = "{\"email\":\"appleseed@apple.com\",\"name\":\"Johnny Appleseed\"}".data(using: .utf8)!
205205
let person = Person.testValue
206206
_testRoundTrip(of: person, expectedJSON: expectedJSON, outputFormatting: [.sortedKeys])
207207
}
208208
}
209209

210210
func testEncodingOutputFormattingPrettyPrintedSortedKeys() {
211-
if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
211+
if #available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
212212
let expectedJSON = "{\n \"email\" : \"appleseed@apple.com\",\n \"name\" : \"Johnny Appleseed\"\n}".data(using: .utf8)!
213213
let person = Person.testValue
214214
_testRoundTrip(of: person, expectedJSON: expectedJSON, outputFormatting: [.prettyPrinted, .sortedKeys])
@@ -307,7 +307,7 @@ class TestJSONEncoder : XCTestCase {
307307
}
308308

309309
func testEncodingDateISO8601() {
310-
if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
310+
if #available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) {
311311
let formatter = ISO8601DateFormatter()
312312
formatter.formatOptions = .withInternetDateTime
313313

Darwin/Foundation-swiftoverlay-Tests/TestMeasurement.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
import XCTest
1515

1616
// We define our own units here so that we can have closer control over checking the behavior of just struct Measurement and not the rest of Foundation
17-
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
17+
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
1818
class MyDimensionalUnit : Dimension {
1919
class var unitA : MyDimensionalUnit {
2020
return MyDimensionalUnit(symbol: "a", converter: UnitConverterLinear(coefficient: 1))
@@ -30,7 +30,7 @@ class MyDimensionalUnit : Dimension {
3030
}
3131
}
3232

33-
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
33+
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
3434
class CustomUnit : Unit {
3535
override init(symbol: String) {
3636
super.init(symbol: symbol)
@@ -44,7 +44,7 @@ class CustomUnit : Unit {
4444
public static let features = CustomUnit(symbol: "feature")
4545
}
4646

47-
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
47+
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
4848
class TestMeasurement : XCTestCase {
4949

5050
func testBasicConstruction() {

0 commit comments

Comments
 (0)