Skip to content

Commit 6b26ed1

Browse files
authored
Merge pull request swiftlang#1755 from millenomi/cfcalendar
Mojave merge addendum: CF… & NSCalendar Fixes
2 parents 17f150f + 405214e commit 6b26ed1

21 files changed

+7235
-801
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ if(ENABLE_TESTING)
324324
TestFoundation/TestNSArray.swift
325325
TestFoundation/TestNSAttributedString.swift
326326
TestFoundation/TestNSCache.swift
327+
TestFoundation/TestNSCalendar.swift
327328
TestFoundation/TestNSCompoundPredicate.swift
328329
TestFoundation/TestNSData.swift
329330
TestFoundation/TestNSDictionary.swift

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,12 @@ enum {
10051005
__kCFZombieMessagedEvent = 21,
10061006
};
10071007

1008+
#define _CFReleaseDeferred __attribute__((__cleanup__(_CFReleaseOnCleanup)))
1009+
static inline void _CFReleaseOnCleanup(void * CF_RELEASES_ARGUMENT ptr) {
1010+
CFTypeRef cf = *(CFTypeRef *)ptr;
1011+
if (cf) CFRelease(cf);
1012+
}
1013+
10081014
#pragma mark - CF Private Globals
10091015

10101016
CF_PRIVATE void *__CFAppleLanguages;

CoreFoundation/Base.subproj/ForFoundationOnly.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,6 @@ CF_EXPORT Boolean _CFCalendarComposeAbsoluteTimeV(CFCalendarRef calendar, /* out
602602
CF_EXPORT Boolean _CFCalendarDecomposeAbsoluteTimeV(CFCalendarRef calendar, CFAbsoluteTime at, const char *componentDesc, int32_t *_Nonnull * _Nonnull vector, int32_t count);
603603
CF_EXPORT Boolean _CFCalendarAddComponentsV(CFCalendarRef calendar, /* inout */ CFAbsoluteTime *atp, CFOptionFlags options, const char *componentDesc, int32_t *vector, int32_t count);
604604
CF_EXPORT Boolean _CFCalendarGetComponentDifferenceV(CFCalendarRef calendar, CFAbsoluteTime startingAT, CFAbsoluteTime resultAT, CFOptionFlags options, const char *componentDesc, int32_t *_Nonnull * _Nonnull vector, int32_t count);
605-
CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarIsWeekend(CFCalendarRef calendar, CFAbsoluteTime at);
606-
607-
typedef struct {
608-
CFTimeInterval onsetTime;
609-
CFTimeInterval ceaseTime;
610-
CFIndex start;
611-
CFIndex end;
612-
} _CFCalendarWeekendRange;
613-
614-
CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarGetNextWeekend(CFCalendarRef calendar, _CFCalendarWeekendRange *range);
615605

616606
CF_CROSS_PLATFORM_EXPORT Boolean _CFLocaleInit(CFLocaleRef locale, CFStringRef identifier);
617607

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <pthread.h>
3030
#include <dirent.h>
3131

32+
#include <CoreFoundation/CFCalendar_Internal.h>
33+
3234
#if __has_include(<execinfo.h>)
3335
#include <execinfo.h>
3436
#endif
@@ -39,6 +41,11 @@
3941

4042
_CF_EXPORT_SCOPE_BEGIN
4143

44+
CF_CROSS_PLATFORM_EXPORT Boolean _CFCalendarGetNextWeekend(CFCalendarRef calendar, _CFCalendarWeekendRange *range);
45+
CF_CROSS_PLATFORM_EXPORT void _CFCalendarEnumerateDates(CFCalendarRef calendar, CFDateRef start, CFDateComponentsRef matchingComponents, CFOptionFlags opts, void (^block)(CFDateRef, Boolean, Boolean*));
46+
CF_EXPORT void CFCalendarSetGregorianStartDate(CFCalendarRef calendar, CFDateRef _Nullable date);
47+
CF_EXPORT _Nullable CFDateRef CFCalendarCopyGregorianStartDate(CFCalendarRef calendar);
48+
4249
struct __CFSwiftObject {
4350
uintptr_t isa;
4451
};
@@ -51,7 +58,7 @@ typedef struct __CFSwiftObject *CFSwiftRef;
5158
if (CF_IS_SWIFT(type, obj)) { \
5259
return (ret)__CFSwiftBridge.fn((CFSwiftRef)obj, ##__VA_ARGS__); \
5360
} \
54-
} while (0)
61+
} while (0)
5562

5663
CF_EXPORT bool _CFIsSwift(CFTypeID type, CFSwiftRef obj);
5764
CF_EXPORT void _CFDeinit(CFTypeRef cf);
@@ -243,6 +250,20 @@ struct _NSDataBridge {
243250
_Nonnull CFTypeRef (*_Nonnull copy)(CFTypeRef obj);
244251
};
245252

253+
struct _NSCalendarBridge {
254+
_Nonnull CFTypeRef (*_Nonnull calendarIdentifier)(CFTypeRef obj);
255+
_Nullable CFTypeRef (*_Nonnull copyLocale)(CFTypeRef obj);
256+
void (*_Nonnull setLocale)(CFTypeRef obj, CFTypeRef _Nullable locale);
257+
_Nonnull CFTypeRef (*_Nonnull copyTimeZone)(CFTypeRef obj);
258+
void (*_Nonnull setTimeZone)(CFTypeRef obj, CFTypeRef _Nonnull timeZone);
259+
CFIndex (*_Nonnull firstWeekday)(CFTypeRef obj);
260+
void (*_Nonnull setFirstWeekday)(CFTypeRef obj, CFIndex firstWeekday);
261+
CFIndex (*_Nonnull minimumDaysInFirstWeek)(CFTypeRef obj);
262+
void (*_Nonnull setMinimumDaysInFirstWeek)(CFTypeRef obj, CFIndex minimumDays);
263+
_Nullable CFTypeRef (*_Nonnull copyGregorianStartDate)(CFTypeRef obj);
264+
void (*_Nonnull setGregorianStartDate)(CFTypeRef obj, CFTypeRef _Nullable date);
265+
};
266+
246267
struct _CFSwiftBridge {
247268
struct _NSObjectBridge NSObject;
248269
struct _NSArrayBridge NSArray;
@@ -259,6 +280,7 @@ struct _CFSwiftBridge {
259280
struct _NSMutableCharacterSetBridge NSMutableCharacterSet;
260281
struct _NSNumberBridge NSNumber;
261282
struct _NSDataBridge NSData;
283+
struct _NSCalendarBridge NSCalendar;
262284
};
263285

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

309-
extern _Nullable CFDateRef CFCalendarCopyGregorianStartDate(CFCalendarRef calendar);
310-
extern void CFCalendarSetGregorianStartDate(CFCalendarRef calendar, CFDateRef date);
311-
312331
CF_EXPORT char *_Nullable *_Nonnull _CFEnviron(void);
313332

314333
CF_EXPORT void CFLog1(CFLogLevel lev, CFStringRef message);

CoreFoundation/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ add_framework(CoreFoundation
6666
# Error
6767
Error.subproj/CFError_Private.h
6868
# Locale
69+
Locale.subproj/CFCalendar_Internal.h
70+
Locale.subproj/CFDateComponents.h
6971
Locale.subproj/CFDateFormatter_Private.h
72+
Locale.subproj/CFDateInterval.h
7073
Locale.subproj/CFICULogging.h
7174
Locale.subproj/CFLocaleInternal.h
7275
Locale.subproj/CFLocale_Private.h
@@ -119,6 +122,9 @@ add_framework(CoreFoundation
119122
Base.subproj/CFRuntime.h
120123
Base.subproj/ForFoundationOnly.h
121124
Base.subproj/ForSwiftFoundationOnly.h
125+
Locale.subproj/CFCalendar_Internal.h
126+
Locale.subproj/CFDateComponents.h
127+
Locale.subproj/CFDateInterval.h
122128
Locale.subproj/CFLocaleInternal.h
123129
Parsing.subproj/CFXMLInterface.h
124130
PlugIn.subproj/CFBundlePriv.h
@@ -214,7 +220,10 @@ add_framework(CoreFoundation
214220
Error.subproj/CFError.c
215221
# Locale
216222
Locale.subproj/CFCalendar.c
223+
Locale.subproj/CFCalendar_Enumerate.c
224+
Locale.subproj/CFDateComponents.c
217225
Locale.subproj/CFDateFormatter.c
226+
Locale.subproj/CFDateInterval.c
218227
Locale.subproj/CFLocale.c
219228
Locale.subproj/CFLocaleIdentifier.c
220229
Locale.subproj/CFLocaleKeys.c

0 commit comments

Comments
 (0)