Skip to content

Commit 400195a

Browse files
committed
Merge branch 'master' of github.com:apple/swift-corelibs-foundation into cg-api
2 parents e081f2c + 1099962 commit 400195a

File tree

105 files changed

+8578
-2297
lines changed

Some content is hidden

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

105 files changed

+8578
-2297
lines changed

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ CF_EXPORT void _CFMachPortInstallNotifyPort(CFRunLoopRef rl, CFStringRef mode);
157157

158158
CF_PRIVATE os_log_t _CFOSLog(void);
159159

160-
CF_PRIVATE CFIndex __CFActiveProcessorCount();
160+
CF_PRIVATE CFIndex __CFActiveProcessorCount(void);
161161

162162
#ifndef CLANG_ANALYZER_NORETURN
163163
#if __has_feature(attribute_analyzer_noreturn)
@@ -325,7 +325,7 @@ extern Boolean __CFStringScanHex(CFStringInlineBuffer *buf, SInt32 *indexPtr, un
325325
extern const char *__CFgetenv(const char *n);
326326
extern const char *__CFgetenvIfNotRestricted(const char *n); // Returns NULL in a restricted process
327327

328-
CF_PRIVATE Boolean __CFProcessIsRestricted();
328+
CF_PRIVATE Boolean __CFProcessIsRestricted(void);
329329

330330
// This is really about the availability of C99. We don't have that on Windows, but we should everywhere else.
331331
#if DEPLOYMENT_TARGET_WINDOWS
@@ -587,8 +587,8 @@ CF_PRIVATE SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, B
587587

588588
/* ==================== Simple path manipulation ==================== */
589589

590-
CF_EXPORT UniChar _CFGetSlash();
591-
CF_PRIVATE CFStringRef _CFGetSlashStr();
590+
CF_EXPORT UniChar _CFGetSlash(void);
591+
CF_PRIVATE CFStringRef _CFGetSlashStr(void);
592592
CF_EXPORT Boolean _CFIsAbsolutePath(UniChar *unichars, CFIndex length);
593593
CF_PRIVATE void _CFAppendTrailingPathSlash2(CFMutableStringRef path);
594594
CF_PRIVATE void _CFAppendConditionalTrailingPathSlash2(CFMutableStringRef path);
@@ -733,7 +733,7 @@ extern void *__CFLookupCoreServicesInternalFunction(const char *name);
733733
CF_PRIVATE CFComparisonResult _CFCompareStringsWithLocale(CFStringInlineBuffer *str1, CFRange str1Range, CFStringInlineBuffer *str2, CFRange str2Range, CFOptionFlags options, const void *compareLocale);
734734

735735

736-
CF_PRIVATE CFArrayRef _CFBundleCopyUserLanguages();
736+
CF_PRIVATE CFArrayRef _CFBundleCopyUserLanguages(void);
737737

738738

739739
// This should only be used in CF types, not toll-free bridged objects!

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ const char *_CFProcessPath(void) {
180180
}
181181
return __CFProcessPath;
182182
}
183+
184+
#else
185+
186+
Boolean _CFIsMainThread(void) {
187+
return pthread_main_np() == 1;
188+
}
183189
#endif
184190

185191
CF_PRIVATE CFStringRef _CFProcessNameString(void) {
@@ -1295,7 +1301,7 @@ CFTypeRef _Nullable _CFThreadSpecificGet(_CFThreadSpecificKey key) {
12951301
return (CFTypeRef)pthread_getspecific(key);
12961302
}
12971303

1298-
void _CThreadSpecificSet(_CFThreadSpecificKey key, CFTypeRef _Nullable value) {
1304+
void _CFThreadSpecificSet(_CFThreadSpecificKey key, CFTypeRef _Nullable value) {
12991305
if (value != NULL) {
13001306
swift_retain((void *)value);
13011307
pthread_setspecific(key, value);

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,11 @@ CFAllocatorRef CFGetAllocator(CFTypeRef cf) {
808808
}
809809

810810

811-
extern CFTypeID CFBinaryHeapGetTypeID();
812-
extern CFTypeID CFBitVectorGetTypeID();
813-
extern CFTypeID CFTreeGetTypeID();
814-
extern CFTypeID CFPlugInInstanceGetTypeID();
815-
extern CFTypeID CFStringTokenizerGetTypeID();
811+
extern CFTypeID CFBinaryHeapGetTypeID(void);
812+
extern CFTypeID CFBitVectorGetTypeID(void);
813+
extern CFTypeID CFTreeGetTypeID(void);
814+
extern CFTypeID CFPlugInInstanceGetTypeID(void);
815+
extern CFTypeID CFStringTokenizerGetTypeID(void);
816816
extern CFTypeID CFStorageGetTypeID(void);
817817
extern void __CFAllocatorInitialize(void);
818818
extern void __CFStringInitialize(void);
@@ -821,7 +821,7 @@ extern void __CFCharacterSetInitialize(void);
821821
extern void __CFPFactoryInitialize(void);
822822
extern void __CFPlugInInitialize(void);
823823
#if (DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_MACOSX) && DEPLOYMENT_RUNTIME_SWIFT
824-
CF_PRIVATE void __CFTSDInitialize();
824+
CF_PRIVATE void __CFTSDInitialize(void);
825825
#endif
826826
#if DEPLOYMENT_TARGET_WINDOWS
827827
// From CFPlatform.c
@@ -1005,7 +1005,7 @@ void __CFInitialize(void) {
10051005
memset(__CFRuntimeObjCClassTable, 0, sizeof(__CFRuntimeObjCClassTable));
10061006

10071007
#if DEPLOYMENT_RUNTIME_SWIFT
1008-
extern uintptr_t __CFSwiftGetBaseClass();
1008+
extern uintptr_t __CFSwiftGetBaseClass(void);
10091009

10101010
uintptr_t NSCFType = __CFSwiftGetBaseClass();
10111011
for (CFIndex idx = 1; idx < __CFRuntimeClassTableSize; idx++) {
@@ -1107,7 +1107,7 @@ void __CFInitialize(void) {
11071107
#endif
11081108

11091109
#if DEPLOYMENT_RUNTIME_SWIFT
1110-
extern void __CFInitializeSwift();
1110+
extern void __CFInitializeSwift(void);
11111111
__CFInitializeSwift();
11121112
__CFNumberInitialize(); /* needs to happen after Swift bridge is initialized */
11131113
#endif

CoreFoundation/Base.subproj/ForFoundationOnly.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,12 @@ CF_EXPORT _CFStringFileSystemRepresentationError _CFStringGetFileSystemRepresent
631631

632632

633633

634-
CF_EXPORT CFIndex __CFProcessorCount();
635-
CF_EXPORT uint64_t __CFMemorySize();
634+
CF_EXPORT CFIndex __CFProcessorCount(void);
635+
CF_EXPORT uint64_t __CFMemorySize(void);
636636
CF_EXPORT CFStringRef _CFProcessNameString(void);
637-
CF_EXPORT CFIndex __CFActiveProcessorCount();
638-
CF_EXPORT CFDictionaryRef __CFGetEnvironment();
639-
CF_EXPORT int32_t __CFGetPid();
637+
CF_EXPORT CFIndex __CFActiveProcessorCount(void);
638+
CF_EXPORT CFDictionaryRef __CFGetEnvironment(void);
639+
CF_EXPORT int32_t __CFGetPid(void);
640640
CF_EXPORT CFTimeInterval CFGetSystemUptime(void);
641641
CF_EXPORT CFStringRef CFCopySystemVersionString(void);
642642
CF_EXPORT CFDictionaryRef _CFCopySystemVersionDictionary(void);

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
#include <CoreFoundation/ForFoundationOnly.h>
2828
#include <fts.h>
2929
#include <pthread.h>
30+
#include <execinfo.h>
31+
32+
#if __has_include(<malloc/malloc.h>)
33+
#include <malloc/malloc.h>
34+
#endif
35+
36+
#if __has_include(<malloc/malloc.h>)
37+
#include <malloc/malloc.h>
38+
#endif
3039

3140
_CF_EXPORT_SCOPE_BEGIN
3241

@@ -138,7 +147,7 @@ struct _NSMutableStringBridge {
138147
};
139148

140149
struct _NSXMLParserBridge {
141-
_CFXMLInterface _Nullable (*_Nonnull currentParser)();
150+
_CFXMLInterface _Nullable (*_Nonnull currentParser)(void);
142151
_CFXMLInterfaceParserInput _Nullable (*_Nonnull _xmlExternalEntityWithURL)(_CFXMLInterface interface, const char *url, const char * identifier, _CFXMLInterfaceParserContext context, _CFXMLInterfaceExternalEntityLoader originalLoaderFunction);
143152

144153
_CFXMLInterfaceParserContext _Nonnull (*_Nonnull getContext)(_CFXMLInterface ctx);
@@ -294,13 +303,14 @@ CF_EXPORT char *_Nullable *_Nonnull _CFEnviron(void);
294303
CF_EXPORT void CFLog1(CFLogLevel lev, CFStringRef message);
295304

296305
CF_EXPORT Boolean _CFIsMainThread(void);
306+
CF_EXPORT pthread_t _CFMainPThread;
297307

298308
CF_EXPORT CFHashCode __CFHashDouble(double d);
299309

300310
typedef pthread_key_t _CFThreadSpecificKey;
301311
CF_EXPORT CFTypeRef _Nullable _CFThreadSpecificGet(_CFThreadSpecificKey key);
302-
CF_EXPORT void _CThreadSpecificSet(_CFThreadSpecificKey key, CFTypeRef _Nullable value);
303-
CF_EXPORT _CFThreadSpecificKey _CFThreadSpecificKeyCreate();
312+
CF_EXPORT void _CFThreadSpecificSet(_CFThreadSpecificKey key, CFTypeRef _Nullable value);
313+
CF_EXPORT _CFThreadSpecificKey _CFThreadSpecificKeyCreate(void);
304314

305315
typedef pthread_attr_t _CFThreadAttributes;
306316
typedef pthread_t _CFThreadRef;
@@ -343,6 +353,54 @@ CF_EXPORT CFStringRef _CFXDGCreateCacheDirectoryPath(void);
343353
/// a single base directory relative to which user-specific runtime files and other file objects should be placed. This directory is defined by the environment variable $XDG_RUNTIME_DIR.
344354
CF_EXPORT CFStringRef _CFXDGCreateRuntimeDirectoryPath(void);
345355

356+
357+
typedef struct {
358+
void *_Nonnull memory;
359+
size_t capacity;
360+
_Bool onStack;
361+
} _ConditionalAllocationBuffer;
362+
363+
static inline _Bool _resizeConditionalAllocationBuffer(_ConditionalAllocationBuffer *_Nonnull buffer, size_t amt) {
364+
#if TARGET_OS_MAC
365+
size_t amount = malloc_good_size(amt);
366+
#else
367+
size_t amount = amt;
368+
#endif
369+
if (amount <= buffer->capacity) { return true; }
370+
void *newMemory;
371+
if (buffer->onStack) {
372+
newMemory = malloc(amount);
373+
if (newMemory == NULL) { return false; }
374+
memcpy(newMemory, buffer->memory, buffer->capacity);
375+
buffer->onStack = false;
376+
} else {
377+
newMemory = realloc(buffer->memory, amount);
378+
if (newMemory == NULL) { return false; }
379+
}
380+
if (newMemory == NULL) { return false; }
381+
buffer->memory = newMemory;
382+
buffer->capacity = amount;
383+
return true;
384+
}
385+
386+
static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(_ConditionalAllocationBuffer *_Nonnull)) {
387+
_ConditionalAllocationBuffer buffer;
388+
#if TARGET_OS_MAC
389+
buffer.capacity = malloc_good_size(amount);
390+
#else
391+
buffer.capacity = amount;
392+
#endif
393+
buffer.onStack = (_CFIsMainThread() != 0 ? buffer.capacity < 2048 : buffer.capacity < 512);
394+
buffer.memory = buffer.onStack ? alloca(buffer.capacity) : malloc(buffer.capacity);
395+
if (buffer.memory == NULL) { return false; }
396+
applier(&buffer);
397+
if (!buffer.onStack) {
398+
free(buffer.memory);
399+
}
400+
return true;
401+
}
402+
403+
346404
_CF_EXPORT_SCOPE_END
347405

348406
#endif /* __COREFOUNDATION_FORSWIFTFOUNDATIONONLY__ */

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) {
793793
size_t zoneInfoDirLen = CFStringGetLength(__tzZoneInfo);
794794
if (strncmp(linkbuf, tzZoneInfo, zoneInfoDirLen) == 0) {
795795
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf + zoneInfoDirLen,
796-
strlen(linkbuf) - zoneInfoDirLen + 2, kCFStringEncodingUTF8, false);
796+
strlen(linkbuf) - zoneInfoDirLen + 1, kCFStringEncodingUTF8, false);
797797
} else {
798798
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf, strlen(linkbuf), kCFStringEncodingUTF8, false);
799799
}

CoreFoundation/Parsing.subproj/CFXMLInterface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,8 @@ CFArrayRef _CFXMLNodesForXPath(_CFXMLNodePtr node, const unsigned char* xpath) {
893893
CFArrayAppendValue(results, nodes->nodeTab[i]);
894894
}
895895

896-
xmlFree(context);
897-
xmlFree(evalResult);
896+
xmlXPathFreeContext(context);
897+
xmlXPathFreeObject(evalResult);
898898

899899
return results;
900900
}

CoreFoundation/Parsing.subproj/CFXMLInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ typedef void (*_CFXMLInterfaceStructuredErrorFunc)(_CFXMLInterface ctx, _CFXMLIn
100100

101101
void _CFSetupXMLInterface(void);
102102
_CFXMLInterfaceParserInput _CFXMLInterfaceNoNetExternalEntityLoader(const char *URL, const char *ID, _CFXMLInterfaceParserContext ctxt);
103-
_CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler();
103+
_CFXMLInterfaceSAXHandler _CFXMLInterfaceCreateSAXHandler(void);
104104
void _CFXMLInterfaceDestroySAXHandler(_CFXMLInterfaceSAXHandler handler);
105105
void _CFXMLInterfaceSetStructuredErrorFunc(_CFXMLInterface ctx, _CFXMLInterfaceStructuredErrorFunc _Nullable handler);
106106
_CFXMLInterfaceParserContext _CFXMLInterfaceCreatePushParserCtxt(_CFXMLInterfaceSAXHandler _Nullable sax, _CFXMLInterface user_data, const char * chunk, int size, const char *_Nullable filename);

CoreFoundation/PlugIn.subproj/CFBundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ static const CFRuntimeClass __CFBundleClass = {
882882
};
883883

884884
// From CFBundle_Resources.c
885-
CF_PRIVATE void _CFBundleResourcesInitialize();
885+
CF_PRIVATE void _CFBundleResourcesInitialize(void);
886886

887887
CFTypeID CFBundleGetTypeID(void) {
888888
static dispatch_once_t initOnce;

CoreFoundation/PlugIn.subproj/CFBundle_Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ CF_PRIVATE SInt32 _CFBundleCurrentArchitecture(void);
144144
CF_PRIVATE Boolean _CFBundleGetObjCImageInfo(CFBundleRef bundle, uint32_t *objcVersion, uint32_t *objcFlags);
145145

146146
#if defined(BINARY_SUPPORT_DYLD)
147-
CF_PRIVATE CFMutableDictionaryRef _CFBundleCreateInfoDictFromMainExecutable();
147+
CF_PRIVATE CFMutableDictionaryRef _CFBundleCreateInfoDictFromMainExecutable(void);
148148
CF_PRIVATE Boolean _CFBundleGrokObjCImageInfoFromMainExecutable(uint32_t *objcVersion, uint32_t *objcFlags);
149149
#endif
150150

0 commit comments

Comments
 (0)