Skip to content

Commit f8c8bb8

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 7f959e6 + 702ee49 commit f8c8bb8

Some content is hidden

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

57 files changed

+1823
-409
lines changed

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ const char *_NSPrintForDebugger(void *cf) {
18081808
}
18091809
}
18101810

1811-
#if DEPLOYMENT_RUNTIME_SWIFT && DEPLOYMENT_TARGET_LINUX
1811+
#if DEPLOYMENT_RUNTIME_SWIFT
18121812

18131813
// For CF functions with 'Get' semantics, the compiler currently assumes that the result is autoreleased and must be retained. It does so on all platforms by emitting a call to objc_retainAutoreleasedReturnValue. On Darwin, this is implemented by the ObjC runtime. On Linux, there is no runtime, and therefore we have to stub it out here ourselves. The compiler will eventually call swift_release to balance the retain below. This is a workaround until the compiler no longer emits this callout on Linux.
18141814
CFTypeRef objc_retainAutoreleasedReturnValue(CFTypeRef cf) {

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <fts.h>
2020

2121
CF_ASSUME_NONNULL_BEGIN
22+
CF_IMPLICIT_BRIDGING_ENABLED
2223

2324
struct __CFSwiftObject {
2425
uintptr_t isa;
@@ -209,6 +210,7 @@ extern void _CFURLInitWithFileSystemPathRelativeToBase(CFURLRef url, CFStringRef
209210
extern Boolean _CFURLInitWithURLString(CFURLRef url, CFStringRef string, Boolean checkForLegalCharacters, _Nullable CFURLRef baseURL);
210211
extern Boolean _CFURLInitAbsoluteURLWithBytes(CFURLRef url, const UInt8 *relativeURLBytes, CFIndex length, CFStringEncoding encoding, _Nullable CFURLRef baseURL);
211212

213+
extern CFHashCode CFHashBytes(uint8_t *bytes, CFIndex length);
212214
extern CFIndex __CFProcessorCount();
213215
extern uint64_t __CFMemorySize();
214216
extern CFIndex __CFActiveProcessorCount();
@@ -271,6 +273,7 @@ extern void _cf_uuid_unparse(const _cf_uuid_t uu, _cf_uuid_string_t out);
271273
extern void _cf_uuid_unparse_lower(const _cf_uuid_t uu, _cf_uuid_string_t out);
272274
extern void _cf_uuid_unparse_upper(const _cf_uuid_t uu, _cf_uuid_string_t out);
273275

276+
CF_IMPLICIT_BRIDGING_DISABLED
274277
CF_ASSUME_NONNULL_END
275278

276279
#endif /* __COREFOUNDATION_FORSWIFTFOUNDATIONONLY__ */

CoreFoundation/Locale.subproj/CFCalendar.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ static CFStringRef __CFCalendarCopyDescription(CFTypeRef cf) {
4949

5050
static void __CFCalendarDeallocate(CFTypeRef cf) {
5151
CFCalendarRef calendar = (CFCalendarRef)cf;
52-
CFRelease(calendar->_identifier);
52+
if (calendar->_identifier) CFRelease(calendar->_identifier);
5353
if (calendar->_locale) CFRelease(calendar->_locale);
5454
if (calendar->_localeID) CFRelease(calendar->_localeID);
55-
CFRelease(calendar->_tz);
55+
if (calendar->_tz) CFRelease(calendar->_tz);
5656
if (calendar->_cal) ucal_close(calendar->_cal);
5757
}
5858

@@ -236,15 +236,14 @@ CFCalendarRef CFCalendarCopyCurrent(void) {
236236
}
237237

238238
Boolean _CFCalendarInitWithIdentifier(CFCalendarRef calendar, CFStringRef identifier) {
239-
if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar) {
240-
// if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar && identifier != kCFChineseCalendar) {
239+
if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar && identifier != kCFChineseCalendar) {
241240
if (CFEqual(kCFGregorianCalendar, identifier)) identifier = kCFGregorianCalendar;
242241
else if (CFEqual(kCFBuddhistCalendar, identifier)) identifier = kCFBuddhistCalendar;
243242
else if (CFEqual(kCFJapaneseCalendar, identifier)) identifier = kCFJapaneseCalendar;
244243
else if (CFEqual(kCFIslamicCalendar, identifier)) identifier = kCFIslamicCalendar;
245244
else if (CFEqual(kCFIslamicCivilCalendar, identifier)) identifier = kCFIslamicCivilCalendar;
246245
else if (CFEqual(kCFHebrewCalendar, identifier)) identifier = kCFHebrewCalendar;
247-
// else if (CFEqual(kCFChineseCalendar, identifier)) identifier = kCFChineseCalendar;
246+
else if (CFEqual(kCFChineseCalendar, identifier)) identifier = kCFChineseCalendar;
248247
else return false;
249248
}
250249

@@ -261,15 +260,14 @@ CFCalendarRef CFCalendarCreateWithIdentifier(CFAllocatorRef allocator, CFStringR
261260
__CFGenericValidateType(allocator, CFAllocatorGetTypeID());
262261
__CFGenericValidateType(identifier, CFStringGetTypeID());
263262
// return NULL until Chinese calendar is available
264-
if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar) {
265-
// if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar && identifier != kCFChineseCalendar) {
263+
if (identifier != kCFGregorianCalendar && identifier != kCFBuddhistCalendar && identifier != kCFJapaneseCalendar && identifier != kCFIslamicCalendar && identifier != kCFIslamicCivilCalendar && identifier != kCFHebrewCalendar && identifier != kCFChineseCalendar) {
266264
if (CFEqual(kCFGregorianCalendar, identifier)) identifier = kCFGregorianCalendar;
267265
else if (CFEqual(kCFBuddhistCalendar, identifier)) identifier = kCFBuddhistCalendar;
268266
else if (CFEqual(kCFJapaneseCalendar, identifier)) identifier = kCFJapaneseCalendar;
269267
else if (CFEqual(kCFIslamicCalendar, identifier)) identifier = kCFIslamicCalendar;
270268
else if (CFEqual(kCFIslamicCivilCalendar, identifier)) identifier = kCFIslamicCivilCalendar;
271269
else if (CFEqual(kCFHebrewCalendar, identifier)) identifier = kCFHebrewCalendar;
272-
// else if (CFEqual(kCFChineseCalendar, identifier)) identifier = kCFChineseCalendar;
270+
else if (CFEqual(kCFChineseCalendar, identifier)) identifier = kCFChineseCalendar;
273271
else return NULL;
274272
}
275273
struct __CFCalendar *calendar = NULL;
@@ -422,6 +420,7 @@ static UCalendarDateFields __CFCalendarGetICUFieldCodeFromChar(char ch) {
422420
case 'G': return UCAL_ERA;
423421
case 'y': return UCAL_YEAR;
424422
case 'M': return UCAL_MONTH;
423+
case 'l': return UCAL_IS_LEAP_MONTH;
425424
case 'd': return UCAL_DAY_OF_MONTH;
426425
case 'h': return UCAL_HOUR;
427426
case 'H': return UCAL_HOUR_OF_DAY;

CoreFoundation/NumberDate.subproj/CFNumber.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ static inline void _CFNumberInit(CFNumberRef result, CFNumberType type, const vo
10991099
case kCFNumberFloat32Type: memmove((void *)&result->_pad, valuePtr, 4); break;
11001100
case kCFNumberFloat64Type: memmove((void *)&result->_pad, valuePtr, 8); break;
11011101
}
1102+
__CFBitfieldSetValue(((struct __CFNumber *)result)->_base._cfinfo[CF_INFO_BITS], 4, 0, (uint8_t)__CFNumberTypeTable[type].canonicalType);
11021103
}
11031104

11041105
CF_EXPORT void _CFNumberInitBool(CFNumberRef result, Boolean value) {

CoreFoundation/Stream.subproj/CFConcreteStreams.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,21 +592,23 @@ static CFIndex dataRead(CFReadStreamRef stream, UInt8 *buffer, CFIndex bufferLen
592592

593593
static const UInt8 *dataGetBuffer(CFReadStreamRef stream, CFIndex maxBytesToRead, CFIndex *numBytesRead, CFStreamError *error, Boolean *atEOF, void *info) {
594594
_CFReadDataStreamContext *dataCtxt = (_CFReadDataStreamContext *)info;
595-
const UInt8 *bytes = CFDataGetBytePtr(dataCtxt->data);
596-
if (dataCtxt->loc - bytes > maxBytesToRead) {
595+
const UInt8 *bytePtr = CFDataGetBytePtr(dataCtxt->data);
596+
CFIndex length = CFDataGetLength(dataCtxt->data);
597+
CFIndex bytesToRead = bytePtr + length - dataCtxt->loc;
598+
if (bytesToRead > maxBytesToRead) {
597599
*numBytesRead = maxBytesToRead;
598600
*atEOF = FALSE;
599601
} else {
600-
*numBytesRead = dataCtxt->loc - bytes;
602+
*numBytesRead = bytesToRead;
601603
*atEOF = TRUE;
602604
}
603605
error->error = 0;
604-
bytes = dataCtxt->loc;
606+
const UInt8 *buffer = dataCtxt->loc;
605607
dataCtxt->loc += *numBytesRead;
606608
if (dataCtxt->scheduled && !*atEOF) {
607609
CFReadStreamSignalEvent(stream, kCFStreamEventHasBytesAvailable, NULL);
608610
}
609-
return bytes;
611+
return buffer;
610612
}
611613

612614
static Boolean dataCanRead(CFReadStreamRef stream, void *info) {

Docs/Design.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ In a very limited number of cases, key Foundation API as it exists on Apple plat
1313

1414
A significant portion of the implementation of Foundation on Apple platforms is provided by another framework called CoreFoundation (a.k.a. CF). CF is written primarily in C and is very portable. Therefore we have chosen to use it for the internal implementation of Swift Foundation where possible. As CF is present on all platforms, we can use it to provide a common implementation everywhere.
1515

16+
Another aspect of portability is keeping dependencies to an absolute minimum. With fewer dependencies to port, it is more likely that Foundation will be able to easily compile and run on new platforms. Therefore, we will prefer solutions that are implemented in Foundation itself. Exceptions can be made for major functionality (for example, `ICU`, `libdispatch`, and `libxml2`).
17+
1618
## A Taxonomy of Types
1719

1820
A key to the internal design of the framework is the split between the CF implementation and Swift implementation of the Foundation classes. They can be organized into several categories.

Docs/GettingStarted.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,11 @@ LD_LIBRARY_PATH=../build/Ninja-ReleaseAssert/foundation-linux-x86_64/Foundation/
7474
```
7575

7676
Just copy & paste the correct line.
77+
78+
When new source files or flags are added to the `build.py` script, the project will need to be reconfigured in order for the build system to pick them up. The top-level `swift/utils/build-script` can be used, but for quicker iteration you can use the following command to limit the reconfiguration to just the Foundation project:
79+
80+
```
81+
% ninja reconfigure
82+
% ninja
83+
```
84+

0 commit comments

Comments
 (0)