Skip to content

Allow Swift 4.2 to be parsed with C++ and linked from external #1702

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 3 commits into from
Sep 26, 2018
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
11 changes: 11 additions & 0 deletions CoreFoundation/Base.subproj/CFInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@
#define _CF_RELEASES_ARGUMENT_OBJ
#endif

#if DEPLOYMENT_TARGET_WINDOWS
// No C99 support
#define _CF_RESTRICT
#else
#if defined(__cplusplus)
#define _CF_RESTRICT __restrict__
#else
#define _CF_RESTRICT restrict
#endif
#endif

CF_EXTERN_C_BEGIN

#include <CoreFoundation/CFBase.h>
Expand Down
2 changes: 1 addition & 1 deletion CoreFoundation/Base.subproj/CFPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ void _CFThreadSpecificSet(_CFThreadSpecificKey key, CFTypeRef _Nullable value) {
}
}

_CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *restrict _Nullable context) {
_CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *_CF_RESTRICT _Nullable context) {
pthread_t thread;
pthread_create(&thread, &attrs, startfn, context);
return thread;
Expand Down
4 changes: 4 additions & 0 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ CF_EXPORT _CFThreadSpecificKey _CFThreadSpecificKeyCreate(void);
typedef pthread_attr_t _CFThreadAttributes;
typedef pthread_t _CFThreadRef;

#if defined(__cplusplus)
CF_EXPORT _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *__restrict__ _Nullable context);
#else
CF_EXPORT _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *restrict _Nullable context);
#endif

CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(pthread_t thread, const char *_Nonnull name);
CF_CROSS_PLATFORM_EXPORT int _CFThreadGetName(char *_Nonnull buf, int length);
Expand Down
8 changes: 3 additions & 5 deletions CoreFoundation/Collections.subproj/CFStorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#endif

#if DEPLOYMENT_TARGET_WINDOWS
// No C99 support
#define restrict

// Replace bzero
#define bzero(dst, size) ZeroMemory(dst, size)
Expand Down Expand Up @@ -244,7 +242,7 @@ static inline void __CFStorageSetChild(CFStorageNode *parentNode, CFIndex childI
*((void **)&parentNode->info.notLeaf.child[childIndex]) = newChild;
}

static inline void __CFStorageGetChildren(const CFStorageNode *parent, CFStorageNode ** restrict resultArray, bool shouldRetain, bool shouldFreeze) {
static inline void __CFStorageGetChildren(const CFStorageNode *parent, CFStorageNode ** _CF_RESTRICT resultArray, bool shouldRetain, bool shouldFreeze) {
ASSERT(! parent->isLeaf);
CFIndex i;
for (i=0; i < 3; i++) {
Expand Down Expand Up @@ -272,7 +270,7 @@ CF_INLINE void __CFStorageSetCache(CFStorageRef storage, CFStorageNode *node, CF
/* Gets the location for the specified absolute loc from the cached info.
Returns NULL if the location is not in the cache.
*/
CF_INLINE uint8_t *__CFStorageGetFromCache(CFStorageRef storage, CFIndex loc, CFRange * restrict validConsecutiveValueRange, bool requireUnfrozenNode) {
CF_INLINE uint8_t *__CFStorageGetFromCache(CFStorageRef storage, CFIndex loc, CFRange * _CF_RESTRICT validConsecutiveValueRange, bool requireUnfrozenNode) {
CFStorageNode * const cachedNode = storage->cacheNode; /* It's important we read from this field no more than once, for thread safety with other concurrent reads; that is why the field is marked volatile. */
if (! cachedNode) return NULL; /* No cache */

Expand Down Expand Up @@ -307,7 +305,7 @@ CF_INLINE uint8_t *__CFStorageGetFromCache(CFStorageRef storage, CFIndex loc, CF
relativeByteNum (not optional, for performance reasons) returns the relative byte number of the specified byte in the child.
Don't call with leaf nodes!
*/
CF_INLINE CFStorageNode *__CFStorageFindChild(const CFStorageNode * restrict node, CFIndex byteNum, bool forInsertionOrDeletion, CFIndex * restrict childNum, CFIndex * restrict relativeByteNum) {
CF_INLINE CFStorageNode *__CFStorageFindChild(const CFStorageNode * _CF_RESTRICT node, CFIndex byteNum, bool forInsertionOrDeletion, CFIndex * _CF_RESTRICT childNum, CFIndex * _CF_RESTRICT relativeByteNum) {
if (forInsertionOrDeletion) byteNum--; /* If for insertion, we do <= checks, not <, so this accomplishes the same thing */
CFStorageNode *result;
result = node->info.notLeaf.child[0];
Expand Down
2 changes: 1 addition & 1 deletion CoreFoundation/Parsing.subproj/CFXMLInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ typedef void* _CFXMLEntityPtr;
typedef void* _CFXMLDTDPtr;
typedef void* _CFXMLDTDNodePtr;

_CFXMLNodePtr _CFXMLNewNode(_CFXMLNamespacePtr _Nullable namespace, const char* name);
_CFXMLNodePtr _CFXMLNewNode(_CFXMLNamespacePtr _Nullable name_space, const char* name);
_CFXMLNodePtr _CFXMLCopyNode(_CFXMLNodePtr node, bool recursive);

_CFXMLDocPtr _CFXMLNewDoc(const unsigned char* version);
Expand Down
1 change: 1 addition & 0 deletions Foundation/NSCFString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ internal class _NSCFString : NSMutableString {
}
}

@usableFromInline
internal final class _NSCFConstantString : _NSCFString {
internal var _ptr : UnsafePointer<UInt8> {
// FIXME: Split expression as a work-around for slow type
Expand Down