Skip to content

Move all uses of Core Foundation to be @_implementationOnly except getCFRunLoop(). #2876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion CoreFoundation/Base.subproj/CFRuntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,34 @@ static void _CFRelease(CFTypeRef CF_RELEASES_ARGUMENT cf) {
#if DEPLOYMENT_RUNTIME_SWIFT
struct _CFSwiftBridge __CFSwiftBridge = { { NULL } };

struct _NSCFXMLBridge __NSCFXMLBridge = {
struct _NSCFXMLBridgeStrong __NSCFXMLBridgeStrong = {
CFArrayGetCount,
CFArrayGetValueAtIndex,
CFErrorCreate,
CFStringCreateWithCString,
CFStringCreateMutable,
CFStringAppend,
CFStringAppendCString,
CFStringGetLength,
CFStringGetMaximumSizeForEncoding,
CFStringGetCString,
CFDataCreateWithBytesNoCopy,
CFRelease,
CFStringCreateWithBytes,
CFArrayCreateMutable,
CFArrayAppendValue,
CFDataGetLength,
CFDataGetBytePtr,
CFDictionaryCreateMutable,
CFDictionarySetValue,
&kCFAllocatorSystemDefault,
&kCFAllocatorNull,
&kCFCopyStringDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks,
&kCFErrorLocalizedDescriptionKey,
};

struct _NSCFXMLBridgeUntyped __NSCFXMLBridgeUntyped = {
CFArrayGetCount,
CFArrayGetValueAtIndex,
CFErrorCreate,
Expand Down
86 changes: 60 additions & 26 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,34 +280,62 @@ struct _CFSwiftBridge {
struct _NSURLBridge NSURL;
};

struct _NSCFXMLBridge {
CFIndex (* _Nonnull CFArrayGetCount)(CFArrayRef);
const void * _Null_unspecified (* _Nonnull CFArrayGetValueAtIndex)(CFArrayRef, CFIndex);
_Null_unspecified CFErrorRef (* _Nonnull CFErrorCreate)(CFAllocatorRef _Nullable, CFStringRef, CFIndex, CFDictionaryRef _Nullable);
_Null_unspecified CFStringRef (* _Nonnull CFStringCreateWithCString)(CFAllocatorRef _Nullable, const char * _Null_unspecified, CFStringEncoding);
_Null_unspecified CFMutableStringRef (* _Nonnull CFStringCreateMutable)(CFAllocatorRef _Nullable, CFIndex);
void (* _Nonnull CFStringAppend)(CFMutableStringRef, CFStringRef);
void (* _Nonnull CFStringAppendCString)(CFMutableStringRef, const char * _Null_unspecified, CFStringEncoding);
CFIndex (* _Nonnull CFStringGetLength)(CFStringRef);
CFIndex (* _Nonnull CFStringGetMaximumSizeForEncoding)(CFIndex, CFStringEncoding);
Boolean (* _Nonnull CFStringGetCString)(CFStringRef, char *, CFIndex, CFStringEncoding);
_Null_unspecified CFDataRef (* _Nonnull CFDataCreateWithBytesNoCopy)(CFAllocatorRef _Nullable, const uint8_t *, CFIndex, CFAllocatorRef);
void (* _Nonnull CFRelease)(CFTypeRef);
_Null_unspecified CFStringRef (* _Nonnull CFStringCreateWithBytes)(CFAllocatorRef _Nullable, const UInt8 *, CFIndex, CFStringEncoding, Boolean);
_Null_unspecified CFMutableArrayRef (* _Nonnull CFArrayCreateMutable)(CFAllocatorRef _Nullable, CFIndex, const CFArrayCallBacks *_Nullable);
void (* _Nonnull CFArrayAppendValue)(CFMutableArrayRef, const void *);
CFIndex (* _Nonnull CFDataGetLength)(CFDataRef);
const uint8_t * _Null_unspecified (* _Nonnull CFDataGetBytePtr)(CFDataRef);
_Null_unspecified CFMutableDictionaryRef (* _Nonnull CFDictionaryCreateMutable)(CFAllocatorRef _Nullable, CFIndex, const CFDictionaryKeyCallBacks *, const CFDictionaryValueCallBacks *);
void (* _Nonnull CFDictionarySetValue)(CFMutableDictionaryRef, const void * _Null_Unspecified, const void * _Null_unspecified);
const _Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorSystemDefault;
const _Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorNull;
const CFDictionaryKeyCallBacks * _Nonnull kCFCopyStringDictionaryKeyCallBacks;
const CFDictionaryValueCallBacks * _Nonnull kCFTypeDictionaryValueCallBacks;
_Null_unspecified const CFStringRef * _Nonnull kCFErrorLocalizedDescriptionKey;
struct _NSCFXMLBridgeStrong {
CFIndex (* _Nonnull CFArrayGetCount)(CFArrayRef);
const void * _Null_unspecified (* _Nonnull CFArrayGetValueAtIndex)(CFArrayRef, CFIndex);
_Null_unspecified CFErrorRef (* _Nonnull CFErrorCreate)(CFAllocatorRef _Nullable, CFStringRef, CFIndex, CFDictionaryRef _Nullable);
_Null_unspecified CFStringRef (* _Nonnull CFStringCreateWithCString)(CFAllocatorRef _Nullable, const char * _Null_unspecified, CFStringEncoding);
_Null_unspecified CFMutableStringRef (* _Nonnull CFStringCreateMutable)(CFAllocatorRef _Nullable, CFIndex);
void (* _Nonnull CFStringAppend)(CFMutableStringRef, CFStringRef);
void (* _Nonnull CFStringAppendCString)(CFMutableStringRef, const char * _Null_unspecified, CFStringEncoding);
CFIndex (* _Nonnull CFStringGetLength)(CFStringRef);
CFIndex (* _Nonnull CFStringGetMaximumSizeForEncoding)(CFIndex, CFStringEncoding);
Boolean (* _Nonnull CFStringGetCString)(CFStringRef, char *, CFIndex, CFStringEncoding);
_Null_unspecified CFDataRef (* _Nonnull CFDataCreateWithBytesNoCopy)(CFAllocatorRef _Nullable, const uint8_t *, CFIndex, CFAllocatorRef);
void (* _Nonnull CFRelease)(CFTypeRef);
_Null_unspecified CFStringRef (* _Nonnull CFStringCreateWithBytes)(CFAllocatorRef _Nullable, const UInt8 *, CFIndex, CFStringEncoding, Boolean);
_Null_unspecified CFMutableArrayRef (* _Nonnull CFArrayCreateMutable)(CFAllocatorRef _Nullable, CFIndex, const CFArrayCallBacks *_Nullable);
void (* _Nonnull CFArrayAppendValue)(CFMutableArrayRef, const void *);
CFIndex (* _Nonnull CFDataGetLength)(CFDataRef);
const uint8_t * _Null_unspecified (* _Nonnull CFDataGetBytePtr)(CFDataRef);
_Null_unspecified CFMutableDictionaryRef (* _Nonnull CFDictionaryCreateMutable)(CFAllocatorRef _Nullable, CFIndex, const CFDictionaryKeyCallBacks *, const CFDictionaryValueCallBacks *);
void (* _Nonnull CFDictionarySetValue)(CFMutableDictionaryRef, const void * _Null_Unspecified, const void * _Null_unspecified);
const _Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorSystemDefault;
const _Null_unspecified CFAllocatorRef * _Nonnull kCFAllocatorNull;
const CFDictionaryKeyCallBacks * _Nonnull kCFCopyStringDictionaryKeyCallBacks;
const CFDictionaryValueCallBacks * _Nonnull kCFTypeDictionaryValueCallBacks;
_Null_unspecified const CFStringRef * _Nonnull kCFErrorLocalizedDescriptionKey;
};

CF_EXPORT struct _NSCFXMLBridge __NSCFXMLBridge;
struct _NSCFXMLBridgeUntyped {
void *CFArrayGetCount;
void *CFArrayGetValueAtIndex;
void *CFErrorCreate;
void *CFStringCreateWithCString;
void *CFStringCreateMutable;
void *CFStringAppend;
void *CFStringAppendCString;
void *CFStringGetLength;
void *CFStringGetMaximumSizeForEncoding;
void *CFStringGetCString;
void *CFDataCreateWithBytesNoCopy;
void *CFRelease;
void *CFStringCreateWithBytes;
void *CFArrayCreateMutable;
void *CFArrayAppendValue;
void *CFDataGetLength;
void *CFDataGetBytePtr;
void *CFDictionaryCreateMutable;
void *CFDictionarySetValue;
void *kCFAllocatorSystemDefault;
void *kCFAllocatorNull;
void *kCFCopyStringDictionaryKeyCallBacks;
void *kCFTypeDictionaryValueCallBacks;
void *kCFErrorLocalizedDescriptionKey;
};

CF_EXPORT struct _NSCFXMLBridgeStrong __NSCFXMLBridgeStrong;
CF_EXPORT struct _NSCFXMLBridgeUntyped __NSCFXMLBridgeUntyped;

CF_EXPORT struct _CFSwiftBridge __CFSwiftBridge;

Expand Down Expand Up @@ -478,6 +506,12 @@ static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((n
return true;
}

static inline _Bool _withStackOrHeapBufferWithResultInArguments(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(void *_Nonnull memory, size_t capacity, _Bool onStack)) {
return _withStackOrHeapBuffer(amount, ^(_ConditionalAllocationBuffer *buffer) {
applier(buffer->memory, buffer->capacity, buffer->onStack);
});
}

#pragma mark - Character Set

CF_CROSS_PLATFORM_EXPORT CFIndex __CFCharDigitValue(UniChar ch);
Expand Down
Loading