Skip to content
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

Mojave merge addendum: CF… & NSCalendar Fixes #1755

Merged
merged 8 commits into from Nov 13, 2018
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -324,6 +324,7 @@ if(ENABLE_TESTING)
TestFoundation/TestNSArray.swift
TestFoundation/TestNSAttributedString.swift
TestFoundation/TestNSCache.swift
TestFoundation/TestNSCalendar.swift
TestFoundation/TestNSCompoundPredicate.swift
TestFoundation/TestNSData.swift
TestFoundation/TestNSDictionary.swift
Expand Down
6 changes: 6 additions & 0 deletions CoreFoundation/Base.subproj/CFInternal.h
Expand Up @@ -1005,6 +1005,12 @@ enum {
__kCFZombieMessagedEvent = 21,
};

#define _CFReleaseDeferred __attribute__((__cleanup__(_CFReleaseOnCleanup)))
static inline void _CFReleaseOnCleanup(void * CF_RELEASES_ARGUMENT ptr) {
CFTypeRef cf = *(CFTypeRef *)ptr;
if (cf) CFRelease(cf);
}

#pragma mark - CF Private Globals

CF_PRIVATE void *__CFAppleLanguages;
Expand Down
10 changes: 0 additions & 10 deletions CoreFoundation/Base.subproj/ForFoundationOnly.h
Expand Up @@ -602,16 +602,6 @@ CF_EXPORT Boolean _CFCalendarComposeAbsoluteTimeV(CFCalendarRef calendar, /* out
CF_EXPORT Boolean _CFCalendarDecomposeAbsoluteTimeV(CFCalendarRef calendar, CFAbsoluteTime at, const char *componentDesc, int32_t *_Nonnull * _Nonnull vector, int32_t count);
CF_EXPORT Boolean _CFCalendarAddComponentsV(CFCalendarRef calendar, /* inout */ CFAbsoluteTime *atp, CFOptionFlags options, const char *componentDesc, int32_t *vector, int32_t count);
CF_EXPORT Boolean _CFCalendarGetComponentDifferenceV(CFCalendarRef calendar, CFAbsoluteTime startingAT, CFAbsoluteTime resultAT, CFOptionFlags options, const char *componentDesc, int32_t *_Nonnull * _Nonnull vector, int32_t count);
CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarIsWeekend(CFCalendarRef calendar, CFAbsoluteTime at);

typedef struct {
CFTimeInterval onsetTime;
CFTimeInterval ceaseTime;
CFIndex start;
CFIndex end;
} _CFCalendarWeekendRange;

CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarGetNextWeekend(CFCalendarRef calendar, _CFCalendarWeekendRange *range);

CF_CROSS_PLATFORM_EXPORT Boolean _CFLocaleInit(CFLocaleRef locale, CFStringRef identifier);

Expand Down
27 changes: 23 additions & 4 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Expand Up @@ -29,6 +29,8 @@
#include <pthread.h>
#include <dirent.h>

#include <CoreFoundation/CFCalendar_Internal.h>

#if __has_include(<execinfo.h>)
#include <execinfo.h>
#endif
Expand All @@ -39,6 +41,11 @@

_CF_EXPORT_SCOPE_BEGIN

CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarGetNextWeekend(CFCalendarRef calendar, _CFCalendarWeekendRange *range);
CF_CROSS_PLATFORM_EXPORT void _CFCalendarEnumerateDates(CFCalendarRef calendar, CFDateRef start, CFDateComponentsRef matchingComponents, CFOptionFlags opts, void (^block)(CFDateRef, Boolean, Boolean*));
CF_EXPORT void CFCalendarSetGregorianStartDate(CFCalendarRef calendar, CFDateRef _Nullable date);
CF_EXPORT _Nullable CFDateRef CFCalendarCopyGregorianStartDate(CFCalendarRef calendar);

struct __CFSwiftObject {
uintptr_t isa;
};
Expand All @@ -51,7 +58,7 @@ typedef struct __CFSwiftObject *CFSwiftRef;
if (CF_IS_SWIFT(type, obj)) { \
return (ret)__CFSwiftBridge.fn((CFSwiftRef)obj, ##__VA_ARGS__); \
} \
} while (0)
} while (0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bleeding whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge/drop artifact :( will remove ASAP.


CF_EXPORT bool _CFIsSwift(CFTypeID type, CFSwiftRef obj);
CF_EXPORT void _CFDeinit(CFTypeRef cf);
Expand Down Expand Up @@ -243,6 +250,20 @@ struct _NSDataBridge {
_Nonnull CFTypeRef (*_Nonnull copy)(CFTypeRef obj);
};

struct _NSCalendarBridge {
_Nonnull CFTypeRef (*_Nonnull calendarIdentifier)(CFTypeRef obj);
_Nullable CFTypeRef (*_Nonnull copyLocale)(CFTypeRef obj);
void (*_Nonnull setLocale)(CFTypeRef obj, CFTypeRef _Nullable locale);
_Nonnull CFTypeRef (*_Nonnull copyTimeZone)(CFTypeRef obj);
void (*_Nonnull setTimeZone)(CFTypeRef obj, CFTypeRef _Nonnull timeZone);
CFIndex (*_Nonnull firstWeekday)(CFTypeRef obj);
void (*_Nonnull setFirstWeekday)(CFTypeRef obj, CFIndex firstWeekday);
CFIndex (*_Nonnull minimumDaysInFirstWeek)(CFTypeRef obj);
void (*_Nonnull setMinimumDaysInFirstWeek)(CFTypeRef obj, CFIndex minimumDays);
_Nullable CFTypeRef (*_Nonnull copyGregorianStartDate)(CFTypeRef obj);
void (*_Nonnull setGregorianStartDate)(CFTypeRef obj, CFTypeRef _Nullable date);
};

struct _CFSwiftBridge {
struct _NSObjectBridge NSObject;
struct _NSArrayBridge NSArray;
Expand All @@ -259,6 +280,7 @@ struct _CFSwiftBridge {
struct _NSMutableCharacterSetBridge NSMutableCharacterSet;
struct _NSNumberBridge NSNumber;
struct _NSDataBridge NSData;
struct _NSCalendarBridge NSCalendar;
};

CF_EXPORT struct _CFSwiftBridge __CFSwiftBridge;
Expand Down Expand Up @@ -306,9 +328,6 @@ extern CFIndex __CFBinaryPlistWriteToStream(CFPropertyListRef plist, CFTypeRef s
extern CFDataRef _CFPropertyListCreateXMLDataWithExtras(CFAllocatorRef allocator, CFPropertyListRef propertyList);
extern CFWriteStreamRef _CFWriteStreamCreateFromFileDescriptor(CFAllocatorRef alloc, int fd);

extern _Nullable CFDateRef CFCalendarCopyGregorianStartDate(CFCalendarRef calendar);
extern void CFCalendarSetGregorianStartDate(CFCalendarRef calendar, CFDateRef date);

CF_EXPORT char *_Nullable *_Nonnull _CFEnviron(void);

CF_EXPORT void CFLog1(CFLogLevel lev, CFStringRef message);
Expand Down
9 changes: 9 additions & 0 deletions CoreFoundation/CMakeLists.txt
Expand Up @@ -66,7 +66,10 @@ add_framework(CoreFoundation
# Error
Error.subproj/CFError_Private.h
# Locale
Locale.subproj/CFCalendar_Internal.h
Locale.subproj/CFDateComponents.h
Locale.subproj/CFDateFormatter_Private.h
Locale.subproj/CFDateInterval.h
Locale.subproj/CFICULogging.h
Locale.subproj/CFLocaleInternal.h
Locale.subproj/CFLocale_Private.h
Expand Down Expand Up @@ -119,6 +122,9 @@ add_framework(CoreFoundation
Base.subproj/CFRuntime.h
Base.subproj/ForFoundationOnly.h
Base.subproj/ForSwiftFoundationOnly.h
Locale.subproj/CFCalendar_Internal.h
Locale.subproj/CFDateComponents.h
Locale.subproj/CFDateInterval.h
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh I think that it might be nice to invest some time in actually building the private module and using that rather than adding more stuff into the public headers just for swift.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should, agreed.

Locale.subproj/CFLocaleInternal.h
Parsing.subproj/CFXMLInterface.h
PlugIn.subproj/CFBundlePriv.h
Expand Down Expand Up @@ -214,7 +220,10 @@ add_framework(CoreFoundation
Error.subproj/CFError.c
# Locale
Locale.subproj/CFCalendar.c
Locale.subproj/CFCalendar_Enumerate.c
Locale.subproj/CFDateComponents.c
Locale.subproj/CFDateFormatter.c
Locale.subproj/CFDateInterval.c
Locale.subproj/CFLocale.c
Locale.subproj/CFLocaleIdentifier.c
Locale.subproj/CFLocaleKeys.c
Expand Down