-
Notifications
You must be signed in to change notification settings - Fork 10.5k
stdlib/public fixes for Windows support #11110
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d4a932
stdlib/public fixes for Windows support
troughton 02d822e
Rename _swift_stdlib_pthread to _swift_stdlib_tls
troughton 4a379e0
Add WIN32_LEAN_AND_MEAN et al.
troughton 627b42d
Fix VC_EXTRALEAN
troughton 13e91e1
Merge branch 'master' into windows-fixes
troughton 9f0ac24
Update UnicodeNormalization.cpp
troughton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,14 @@ | |
#include <cmath> | ||
#if defined(_WIN32) | ||
#include <io.h> | ||
#define WIN32_LEAN_AND_MEAN | ||
#define VC_EXTRALEAN | ||
#define NOMINMAX | ||
#include <windows.h> | ||
#else | ||
#include <unistd.h> | ||
#endif | ||
#include <pthread.h> | ||
#endif | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
@@ -98,33 +102,57 @@ int swift::_swift_stdlib_close(int fd) { | |
#endif | ||
} | ||
|
||
#if !defined(_WIN32) | ||
// Guard compilation on the typedef for __swift_pthread_key_t in LibcShims.h | ||
// being identical to the platform's pthread_key_t | ||
static_assert(std::is_same<__swift_pthread_key_t, pthread_key_t>::value, | ||
"This platform's pthread_key_t differs. If you hit this assert, " | ||
"fix __swift_pthread_key_t's typedef in LibcShims.h by adding an " | ||
"#if guard and definition for your platform"); | ||
#endif | ||
|
||
SWIFT_RUNTIME_STDLIB_INTERFACE | ||
int swift::_swift_stdlib_pthread_key_create( | ||
int swift::_swift_stdlib_tls_key_create( | ||
__swift_pthread_key_t * _Nonnull key, | ||
void (* _Nullable destructor)(void *) | ||
) { | ||
return pthread_key_create(key, destructor); | ||
} | ||
|
||
SWIFT_RUNTIME_STDLIB_INTERFACE | ||
void * _Nullable swift::_swift_stdlib_pthread_getspecific( | ||
#if defined(_WIN32) | ||
// We're using the Fls- (Fiber) instead of Tls- (Thread) functions since | ||
// on Windows, "If no fiber switching occurs, FLS acts exactly the same | ||
// as thread local storage," and FlsAlloc takes a destructor while | ||
// TlsAlloc doesn't. | ||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms682661.aspx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also makes the code more portable, as some Windows targets (e.g. Windows Store, Windows Phone) only support the FLS variant. |
||
__swift_pthread_key_t result = FlsAlloc(destructor); | ||
if (result != FLS_OUT_OF_INDEXES) { | ||
*key = result; | ||
return 0; | ||
} | ||
return result; | ||
#else | ||
return pthread_key_create(key, destructor); | ||
#endif | ||
} | ||
|
||
SWIFT_RUNTIME_STDLIB_INTERFACE | ||
void * _Nullable swift::_swift_stdlib_tls_getspecific( | ||
__swift_pthread_key_t key | ||
) { | ||
return pthread_getspecific(key); | ||
#if defined(_WIN32) | ||
return FlsGetValue(key); | ||
#else | ||
return pthread_getspecific(key); | ||
#endif | ||
} | ||
|
||
SWIFT_RUNTIME_STDLIB_INTERFACE | ||
int swift::_swift_stdlib_pthread_setspecific( | ||
int swift::_swift_stdlib_tls_setspecific( | ||
__swift_pthread_key_t key, const void * _Nullable value | ||
) { | ||
return pthread_setspecific(key, value); | ||
#if defined(_WIN32) | ||
return FlsSetValue(key, const_cast<void*>(value)); | ||
#else | ||
return pthread_setspecific(key, value); | ||
#endif | ||
} | ||
|
||
#if defined(__APPLE__) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
sizeof(demanglled) / sizeof(*demangled)
or defining a localarray_size
as follows would be nicer: