Skip to content

Commit bd97fe2

Browse files
committed
Merge branch 'master' into fix-Data.count-setter
2 parents 215b87a + 9991f6a commit bd97fe2

File tree

392 files changed

+5757
-3239
lines changed

Some content is hidden

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

392 files changed

+5757
-3239
lines changed

CMakeLists.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ enable_testing()
1717
# Cache the variable to allow the user to alter the configuration.
1818
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE
1919
STRING "MSVC Runtime Library")
20+
2021
if(CMAKE_VERSION VERSION_LESS 3.16.0)
2122
if(NOT (CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin))
2223
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG "-Xlinker -rpath -Xlinker ")
2324
set(CMAKE_SHARED_LIBRARY_RUNTIME_Swift_FLAG_SEP ":")
2425
endif()
26+
# Workaround for CMake 3.15 which doesn't link libraries properly on Windows
27+
set(CMAKE_LINK_LIBRARY_FLAG "-l")
2528
endif()
2629

2730
option(BUILD_SHARED_LIBS "build shared libraries" ON)
31+
option(NS_CURL_ASSUME_FEATURES_MISSING "Assume that optional libcurl features are missing rather than test the library's version, for build debugging" NO)
2832

2933
find_package(dispatch CONFIG REQUIRED)
3034

@@ -40,16 +44,22 @@ add_subdirectory(CoreFoundation EXCLUDE_FROM_ALL)
4044
set(BUILD_SHARED_LIBS ${SAVED_BUILD_SHARED_LIBS})
4145

4246
# Setup include paths for uuid/uuid.h
47+
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h
48+
COMMAND
49+
${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/uuid-headers/uuid
50+
COMMAND
51+
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Sources/UUID/uuid.h ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h)
52+
add_custom_target(uuid-headers
53+
DEPENDS ${CMAKE_BINARY_DIR}/uuid-headers/uuid/uuid.h)
54+
add_dependencies(CoreFoundation uuid-headers)
4355
target_include_directories(CoreFoundation PRIVATE
44-
${CMAKE_CURRENT_SOURCE_DIR}
56+
${CMAKE_BINARY_DIR}/uuid-headers
4557
${CMAKE_CURRENT_BINARY_DIR}/CoreFoundation.framework/Headers)
4658

47-
add_subdirectory(uuid)
48-
add_subdirectory(Foundation)
49-
add_subdirectory(Tools)
59+
add_subdirectory(Sources)
5060
if(ENABLE_TESTING)
5161
find_package(XCTest CONFIG REQUIRED)
52-
add_subdirectory(TestFoundation)
62+
add_subdirectory(Tests)
5363
endif()
5464

5565
if(NOT BUILD_SHARED_LIBS)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ By submitting a pull request, you represent that you have the right to license y
1111

1212
You can use the `Foundation` component in the [bug reporter](https://bugs.swift.org) if you know your bug is specifically about Swift Foundation.
1313

14-
Please remember to include platform information with your report. If the bug is about the Foundation framework on Darwin, then please use the [Apple bug reporting system](https://bugreport.apple.com).
14+
Please remember to include platform information with your report. If the bug is about the Foundation framework on Darwin, then please use [Feedback Assistant](https://feedbackassistant.apple.com).
1515

1616
## Pull Requests
1717

CoreFoundation/Base.subproj/CFAvailability.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
#if !defined(__COREFOUNDATION_CFAVAILABILITY__)
1111
#define __COREFOUNDATION_CFAVAILABILITY__ 1
1212

13-
#if __has_include(<CoreFoundation/TargetConditionals.h>)
1413
#include <CoreFoundation/TargetConditionals.h>
15-
#elif __has_include(<TargetConditionals.h>)
16-
#include <TargetConditionals.h>
17-
#else
18-
#error Missing header TargetConditionals.h
19-
#endif
2014

2115
#if __has_include(<Availability.h>) && __has_include(<os/availability.h>) && __has_include(<AvailabilityMacros.h>)
2216
#include <Availability.h>

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
#if !defined(__COREFOUNDATION_CFBASE__)
1111
#define __COREFOUNDATION_CFBASE__ 1
1212

13-
#if DEPLOYMENT_RUNTIME_SWIFT
1413
#include <CoreFoundation/TargetConditionals.h>
15-
#else
16-
#include <TargetConditionals.h>
17-
#endif
1814
#include <CoreFoundation/CFAvailability.h>
1915

2016
#if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined(__WIN32__)

CoreFoundation/Base.subproj/CFFileUtilities.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
372372
}
373373
}
374374

375-
struct dirent buffer;
376375
struct dirent *dp;
377376
int err;
378377

@@ -389,7 +388,7 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
389388
}
390389
files = CFArrayCreateMutable(alloc, 0, & kCFTypeArrayCallBacks);
391390

392-
while((0 == readdir_r(dirp, &buffer, &dp)) && dp) {
391+
while((dp = readdir(dirp))) {
393392
CFURLRef fileURL;
394393
unsigned namelen = strlen(dp->d_name);
395394

@@ -1059,14 +1058,28 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
10591058
continue;
10601059
}
10611060

1062-
assert(!stuffToPrefix && "prefix not yet implemented");
1061+
const UniChar kSlash = CFPreferredSlash;
1062+
1063+
CFStringAppendBuffer buffer;
1064+
CFStringInitAppendBuffer(kCFAllocatorSystemDefault, &buffer);
1065+
1066+
if (stuffToPrefix) {
1067+
for (CFIndex i = 0, e = CFArrayGetCount(stuffToPrefix); i < e; i++) {
1068+
CFStringRef entry = CFArrayGetValueAtIndex(stuffToPrefix, i);
1069+
CFStringAppendStringToAppendBuffer(&buffer, entry);
1070+
if (CFStringGetCharacterAtIndex(entry, CFStringGetLength(entry) - 1) != _CFGetSlash()) {
1071+
CFStringAppendCharactersToAppendBuffer(&buffer, &kSlash, 1);
1072+
}
1073+
}
1074+
}
1075+
1076+
CFStringAppendStringToAppendBuffer(&buffer, fileName);
10631077
Boolean isDirectory = file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
1064-
CFMutableStringRef filePath = CFStringCreateMutableCopy(kCFAllocatorSystemDefault, nameLen + 1, fileName);
10651078
if (appendSlashForDirectories && isDirectory) {
1066-
UniChar slash = CFPreferredSlash;
1067-
CFStringAppendCharacters(filePath, &slash, 1);
1079+
CFStringAppendCharactersToAppendBuffer(&buffer, &kSlash, 1);
10681080
}
10691081

1082+
CFMutableStringRef filePath = CFStringCreateMutableWithAppendBuffer(&buffer);
10701083
Boolean result = fileHandler(fileName, filePath, isDirectory ? DT_DIR : DT_REG);
10711084
CFRelease(fileName);
10721085
CFRelease(filePath);

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <WinIoCtl.h>
2929
#include <direct.h>
3030
#include <process.h>
31+
#include <processthreadsapi.h>
3132
#define SECURITY_WIN32
3233
#include <Security.h>
3334

@@ -1337,10 +1338,7 @@ void _CF_dispatch_once(dispatch_once_t *predicate, void (^block)(void)) {
13371338
} else {
13381339
dow.dow_sema = _CF_get_thread_semaphore();
13391340
next = *vval;
1340-
for (;;) {
1341-
if (next == CF_DISPATCH_ONCE_DONE) {
1342-
break;
1343-
}
1341+
while (next != CF_DISPATCH_ONCE_DONE) {
13441342
if (__sync_bool_compare_and_swap(vval, next, tail, &next)) {
13451343
dow.dow_thread = next->dow_thread;
13461344
dow.dow_next = next;
@@ -1453,43 +1451,29 @@ _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (*
14531451
#endif
14541452
}
14551453

1456-
#if TARGET_OS_WIN32
1457-
1458-
// This code from here:
1459-
// http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
1460-
1461-
const DWORD MS_VC_EXCEPTION=0x406D1388;
1462-
#pragma pack(push,8)
1463-
typedef struct tagTHREADNAME_INFO
1464-
{
1465-
DWORD dwType; // Must be 0x1000.
1466-
LPCSTR szName; // Pointer to name (in user addr space).
1467-
DWORD dwThreadID; // Thread ID (-1=caller thread).
1468-
DWORD dwFlags; // Reserved for future use, must be zero.
1469-
} THREADNAME_INFO;
1470-
#pragma pack(pop)
1471-
1472-
#endif
1473-
14741454
CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(_CFThreadRef thread, const char *_Nonnull name) {
14751455
#if TARGET_OS_MAC
14761456
if (pthread_equal(pthread_self(), thread)) {
14771457
return pthread_setname_np(name);
14781458
}
14791459
return EINVAL;
14801460
#elif TARGET_OS_WIN32
1481-
THREADNAME_INFO info;
1461+
// Convert To UTF-16
1462+
int szLength =
1463+
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1, NULL, 0);
1464+
if (szLength == 0) {
1465+
return EINVAL;
1466+
}
14821467

1483-
info.dwType = 0x1000;
1484-
info.szName = name;
1485-
info.dwThreadID = GetThreadId(thread);
1486-
info.dwFlags = 0;
1468+
WCHAR *pszThreadDescription = calloc(szLength + 1, sizeof(WCHAR));
1469+
MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1,
1470+
pszThreadDescription, szLength);
14871471

1488-
__try {
1489-
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR),
1490-
(ULONG_PTR*)&info);
1491-
} __except(EXCEPTION_EXECUTE_HANDLER) {
1492-
}
1472+
// Set Thread Name
1473+
SetThreadDescription(thread, pszThreadDescription);
1474+
1475+
// Free Conversion
1476+
free(pszThreadDescription);
14931477

14941478
return 0;
14951479
#elif TARGET_OS_LINUX
@@ -1513,6 +1497,33 @@ CF_CROSS_PLATFORM_EXPORT int _CFThreadGetName(char *buf, int length) {
15131497
return 0;
15141498
#elif TARGET_OS_LINUX
15151499
return pthread_getname_np(pthread_self(), buf, length);
1500+
#elif TARGET_OS_WIN32
1501+
*buf = '\0';
1502+
1503+
// Get Thread Name
1504+
PWSTR pszThreadDescription = NULL;
1505+
HRESULT hr = GetThreadDescription(GetCurrentThread(), &pszThreadDescription);
1506+
if (FAILED(hr)) {
1507+
return -1;
1508+
}
1509+
1510+
// Convert to UTF-8
1511+
int szLength =
1512+
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, pszThreadDescription,
1513+
-1, NULL, 0, NULL, NULL);
1514+
if (szLength) {
1515+
char *buffer = calloc(szLength + 1, sizeof(char));
1516+
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, pszThreadDescription,
1517+
-1, buffer, szLength, NULL, NULL);
1518+
memcpy(buf, buffer, length - 1);
1519+
buf[MIN(szLength, length - 1)] = '\0';
1520+
free(buffer);
1521+
}
1522+
1523+
// Free Result
1524+
LocalFree(pszThreadDescription);
1525+
1526+
return 0;
15161527
#endif
15171528
return -1;
15181529
}
@@ -1527,9 +1538,15 @@ CF_EXPORT char **_CFEnviron(void) {
15271538
#endif
15281539
}
15291540

1541+
#if TARGET_OS_WIN32
1542+
CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const unsigned short *path, int opts, mode_t mode) {
1543+
return _wopen(path, opts, mode);
1544+
}
1545+
#else
15301546
CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const char *path, int opts, mode_t mode) {
15311547
return open(path, opts, mode);
15321548
}
1549+
#endif
15331550

15341551
int _CFOpenFile(const char *path, int opts) {
15351552
return open(path, opts, 0);

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ CF_INLINE uint64_t mach_absolute_time() {
219219
return (uint64_t)ts.tv_nsec + (uint64_t)ts.tv_sec * 1000000000UL;
220220
#endif
221221
}
222+
223+
#define malloc_default_zone() (void *)0
222224
#endif // TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WIN32
223225

224226
#if TARGET_OS_LINUX || TARGET_OS_WIN32 || defined(__OpenBSD__)
@@ -268,9 +270,6 @@ typedef unsigned long fd_mask;
268270
CF_INLINE size_t malloc_size(void *memblock) {
269271
return malloc_usable_size(memblock);
270272
}
271-
272-
#define malloc_default_zone() (void *)0
273-
274273
#endif
275274

276275
#if TARGET_OS_BSD
@@ -324,7 +323,6 @@ CF_EXPORT int _NS_access(const char *name, int amode);
324323

325324
#define __PRETTY_FUNCTION__ __FUNCTION__
326325

327-
#define malloc_default_zone() (void *)0
328326
#define malloc_zone_from_ptr(a) (void *)0
329327
#define malloc_zone_malloc(zone,size) malloc(size)
330328
#define malloc_zone_memalign(zone,align,size) malloc(size)

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,13 @@ struct _NSCFXMLBridge {
293293
_Null_unspecified CFMutableArrayRef (* _Nonnull CFArrayCreateMutable)(CFAllocatorRef _Nullable, CFIndex, const CFArrayCallBacks *_Nullable);
294294
void (* _Nonnull CFArrayAppendValue)(CFMutableArrayRef, const void *);
295295
CFIndex (* _Nonnull CFDataGetLength)(CFDataRef);
296-
uint8_t * _Null_unspecified (* _Nonnull CFDataGetBytePtr)(CFDataRef);
296+
const uint8_t * _Null_unspecified (* _Nonnull CFDataGetBytePtr)(CFDataRef);
297297
_Null_unspecified CFMutableDictionaryRef (* _Nonnull CFDictionaryCreateMutable)(CFAllocatorRef _Nullable, CFIndex, const CFDictionaryKeyCallBacks *, const CFDictionaryValueCallBacks *);
298298
void (* _Nonnull CFDictionarySetValue)(CFMutableDictionaryRef, const void * _Null_Unspecified, const void * _Null_unspecified);
299-
_Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorSystemDefault;
300-
_Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorNull;
301-
CFDictionaryKeyCallBacks * _Nonnull kCFCopyStringDictionaryKeyCallBacks;
302-
CFDictionaryValueCallBacks * _Nonnull kCFTypeDictionaryValueCallBacks;
299+
const _Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorSystemDefault;
300+
const _Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorNull;
301+
const CFDictionaryKeyCallBacks * _Nonnull kCFCopyStringDictionaryKeyCallBacks;
302+
const CFDictionaryValueCallBacks * _Nonnull kCFTypeDictionaryValueCallBacks;
303303
_Null_unspecified const CFStringRef * _Nonnull kCFErrorLocalizedDescriptionKey;
304304
};
305305

@@ -480,7 +480,11 @@ CF_CROSS_PLATFORM_EXPORT CFIndex __CFCharDigitValue(UniChar ch);
480480

481481
#pragma mark - File Functions
482482

483+
#if TARGET_OS_WIN32
484+
CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const unsigned short *path, int opts, mode_t mode);
485+
#else
483486
CF_CROSS_PLATFORM_EXPORT int _CFOpenFileWithMode(const char *path, int opts, mode_t mode);
487+
#endif
484488
CF_CROSS_PLATFORM_EXPORT void *_CFReallocf(void *ptr, size_t size);
485489
CF_CROSS_PLATFORM_EXPORT int _CFOpenFile(const char *path, int opts);
486490

CoreFoundation/Base.subproj/SymbolAliases

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,3 @@ _kCFNumberFormatterZeroSymbolKey _kCFNumberFormatterZeroSymbol
9898
_kCFNumberFormatterUsesCharacterDirectionKey _kCFNumberFormatterUsesCharacterDirection
9999
_kCFDateFormatterUsesCharacterDirectionKey _kCFDateFormatterUsesCharacterDirection
100100
_kCFDateFormatterCalendarIdentifierKey _kCFDateFormatterCalendarName
101-
102-
# Workaround for being able to compile with a swift compiler with the old mangling prefix $S.
103-
# This can eventually be removed if everyone compiles with the ABI-stable Swift 5.0 compiler.
104-
_$S15SwiftFoundation19_NSCFConstantStringCN _$s15SwiftFoundation19_NSCFConstantStringCN
105-

CoreFoundation/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE YES)
2222

2323
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
2424
set(THREADS_PREFER_PTHREAD_FLAG OFF)
25-
find_package(Threads)
25+
find_package(Threads REQUIRED)
2626

2727
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
2828
find_package(LibXml2 REQUIRED)
@@ -398,6 +398,16 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
398398
ICU::i18n)
399399
endif()
400400

401+
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
402+
if((NS_CURL_ASSUME_FEATURES_MISSING) OR (CURL_VERSION_STRING VERSION_LESS "7.32.0"))
403+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:NS_CURL_MISSING_XFERINFOFUNCTION>)
404+
endif()
405+
406+
if((NS_CURL_ASSUME_FEATURES_MISSING) OR (CURL_VERSION_STRING VERSION_LESS "7.30.0"))
407+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:NS_CURL_MISSING_MAX_HOST_CONNECTIONS>)
408+
endif()
409+
endif()
410+
401411
add_framework(CFURLSessionInterface
402412
${FRAMEWORK_LIBRARY_TYPE}
403413
FRAMEWORK_DIRECTORY

CoreFoundation/Collections.subproj/CFBasicHash.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ CF_PRIVATE size_t CFBasicHashGetSize(CFConstBasicHashRef ht, Boolean total) {
14421442
if (ht->bits.keys_offset) size += sizeof(CFBasicHashValue *);
14431443
if (ht->bits.counts_offset) size += sizeof(void *);
14441444
if (__CFBasicHashHasHashCache(ht)) size += sizeof(uintptr_t *);
1445+
#if ENABLE_MEMORY_COUNTERS || ENABLE_DTRACE_PROBES
14451446
if (total) {
14461447
CFIndex num_buckets = __CFBasicHashTableSizes[ht->bits.num_buckets_idx];
14471448
if (0 < num_buckets) {
@@ -1451,6 +1452,9 @@ CF_PRIVATE size_t CFBasicHashGetSize(CFConstBasicHashRef ht, Boolean total) {
14511452
if (__CFBasicHashHasHashCache(ht)) size += malloc_size(__CFBasicHashGetHashes(ht));
14521453
}
14531454
}
1455+
#else
1456+
(void)total;
1457+
#endif
14541458
return size;
14551459
}
14561460

CoreFoundation/Collections.subproj/CFStorage.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,21 +1366,6 @@ static void __CFStorageApplyNodeBlock(CFStorageRef storage, void (^block)(CFStor
13661366
__CFStorageApplyNodeBlockInterior(storage, &storage->rootNode, block);
13671367
}
13681368

1369-
static CFIndex __CFStorageEstimateTotalAllocatedSize(CFStorageRef storage) __attribute__((unused));
1370-
static CFIndex __CFStorageEstimateTotalAllocatedSize(CFStorageRef storage) {
1371-
__block CFIndex nodeResult = 0;
1372-
__block CFIndex contentsResult = 0;
1373-
__CFStorageApplyNodeBlock(storage, ^(CFStorageRef storage, CFStorageNode *node) {
1374-
if (node != &storage->rootNode) {
1375-
nodeResult += malloc_size(node);
1376-
if (node->isLeaf && node->info.leaf.memory != NULL) {
1377-
contentsResult += malloc_size(node->info.leaf.memory);
1378-
}
1379-
}
1380-
});
1381-
return nodeResult + contentsResult;
1382-
}
1383-
13841369
void __CFStorageSetAlwaysFrozen(CFStorageRef storage, bool alwaysFrozen) {
13851370
storage->alwaysFrozen = alwaysFrozen;
13861371
}

0 commit comments

Comments
 (0)