Skip to content

[stdlib/msvc] Runtime with MSVC library #1918

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 2 commits into from
Jun 11, 2016

Conversation

tinysun212
Copy link
Contributor

What's in this pull request?

Resolved bug number: (SR-)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
OS X platform @swift-ci Please test OS X platform
Linux platform @swift-ci Please test Linux platform

Note: Only members of the Apple organization can trigger swift-ci.

This patch is for libswiftCore.lib, linking with the library set of Visual Studio 2015. Clang with the option -fms-extension is used to build this port.

@tkremenek
Copy link
Member

@swift-ci smoke test

@tkremenek
Copy link
Member

Patch LGTM.

@gribozavr Can you review?

@@ -89,9 +121,20 @@ _swift_stdlib_reportUnimplementedInitializer(const char *className,
intptr_t initNameLength,
uint32_t flags) {
char *log;
#if defined(_MSC_VER)
int len =
_scprintf("fatal error: use of unimplemented "
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define a shim for asprintf() instead of duplicating the code.

@tinysun212
Copy link
Contributor Author

Testing OS X Platform is failed. Is this my fault?

@gribozavr
Copy link
Contributor

@tinysun212 Currently master is passing tests on OS X, so it might be related. Let's retest to be sure:

@swift-ci Please test

@@ -27,9 +27,15 @@
#include <condition_variable>
#include <new>
#include <cctype>
#if defined(_MSC_VER)
#include <windows.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

#define NOMINMAX please.

#include <shared_mutex>
#else
#include <pthread.h>
#endif
#include <type_traits>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I should expand Mutex.h/Mutex.cpp and use it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please review the newly opened PR #1950. It adds read/write lock support as well is a little better factored to allow for alternate platforms to provide their own implementations if they don't have pthreads.

@tinysun212 tinysun212 closed this Apr 2, 2016
@tinysun212 tinysun212 deleted the pr-stdlib-msvc-1 branch April 2, 2016 09:00
@tinysun212 tinysun212 restored the pr-stdlib-msvc-1 branch April 2, 2016 09:05
@tinysun212 tinysun212 reopened this Apr 2, 2016
@tinysun212
Copy link
Contributor Author

(mistake in rebasing.. I dropped this branch and restored.)
I added MutexWin32.cpp/h and revoked the Casting.cpp which is using read/write lock. Later, Mutex.h should be patched to include MutexWin32.h.

@gribozavr
Copy link
Contributor

How does this work? I'm not seeing any code using ConditionPlatformHelper.

I thought that you would modify include/swift/Runtime/Mutex.h and add #ifs for Windows in class Mutex etc.

@shawnce
Copy link
Contributor

shawnce commented Apr 2, 2016

He is depending on my open PR #1950 which has the pthread equivalent
platform helper code.

On Sat, Apr 2, 2016 at 3:06 AM Dmitri Gribenko [email protected]
wrote:

How does this work? I'm not seeing any code using ConditionPlatformHelper.

I thought that you would modify include/swift/Runtime/Mutex.h and add #ifs
for Windows in class Mutex etc.


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
#1918 (comment)

@tinysun212
Copy link
Contributor Author

Yes, this PR should be merged with one more commit (Mutex.h patching) after #1950 merged. I'm waiting it is merged or other reviews.


void ConditionPlatformHelper::wait(CONDITION_VARIABLE &condition,
SRWLOCK &mutex) {
SleepConditionVariableSRW(&condition, &mutex, INFINITE, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is one of the few functions that return an error...

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

...consider testing for an error and calling fatalError like is done in MutexPThread.cpp.

if (LinePtr == nullptr)
return -1;

int Capacity = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably does not matter in practice, but Capacity should probably be declared as ssize_t.

@gribozavr
Copy link
Contributor

@tinysun212 Please consider submitting approved parts as a separate pull request. This will make it much easier to iterate on the other parts.

@tinysun212
Copy link
Contributor Author

@gribozavr Thanks for your reviews, I'll make separate PR containing only approved parts.

set(swift_runtime_port_sources
MutexWin32.cpp
CygwinPort.cpp)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is CygwinPort.cpp intended to be part of the MSVC build? Should it be renamed Win32.cpp or something more general instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it also used for the MSVC build. I agree it to have a new name, but leaved for another PR or iteration.

@gribozavr
Copy link
Contributor

@tinysun212 Thank you, I merged #2829. Would be happy to continue to iterate on the rest!

This patch is for libswiftCore.lib, linking with the library set of Visual Studio 2015. Clang with the option -fms-extension is used to build.
@tinysun212
Copy link
Contributor Author

@gribozavr, I rebased without any patch for the convenience. Your reviews will be applied in several commits.

@@ -24,6 +24,9 @@
#include <cstring>
#include <new>
#include <string>
#if !defined(_MSC_VER)
#include <dlfcn.h>
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need this :)

@tinysun212
Copy link
Contributor Author

tinysun212 commented Jun 3, 2016

@gribozavr, @jckarter, I'll touch all your previous reviews one by one, but it takes some time. You can know if it is touched from my comment for your review.

@gribozavr
Copy link
Contributor

@tinysun212 Just let us know when you're ready!

@jckarter
Copy link
Contributor

jckarter commented Jun 6, 2016

@gribozavr _read and _write are more-or-less equivalent to the POSIX APIs. Microsoft consistently marks non-standard APIs in their C runtime with a leading underscore.

@tinysun212
Copy link
Contributor Author

In stdlib/public/stubs/LibcShims.cpp, _read/_write/_close should be used for MSVC. The patch was omitted for some reason.

@tinysun212
Copy link
Contributor Author

@gribozavr, this PR is ready for review.

@@ -50,7 +60,7 @@ enum: uint32_t {

using namespace swift;

#if !defined(__CYGWIN__) && !defined(__ANDROID__)
#if SWIFT_SUPPORTS_BACKTRACE_REPORTING
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, this is much cleaner now!

@gribozavr
Copy link
Contributor

All changes LGTM.

@gribozavr
Copy link
Contributor

@swift-ci Please test and merge

@swift-ci swift-ci merged commit 91ffcd7 into swiftlang:master Jun 11, 2016
@tinysun212 tinysun212 deleted the pr-stdlib-msvc-1 branch October 21, 2018 00:09
MaxDesiatov pushed a commit that referenced this pull request Oct 19, 2020
[pull] swiftwasm from main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants