Skip to content

Port swift-demangle to Windows #6821

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
Jan 20, 2017
Merged

Port swift-demangle to Windows #6821

merged 2 commits into from
Jan 20, 2017

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Jan 14, 2017

Windows doesn't support unistd.h. Therefore, it doesn't expose any kind of getline posix function.

Instead, let's try to make the swift-demangle.cpp file platform independent by using std::getline

I've marked this as WIP as I'm not sure how similar getline and std::getline are. I'm also getting failures running the swift-demangle unit tests, but wanted to get this out there to see what I'm doing wrong!

@@ -30,12 +30,16 @@

#include <cstdlib>
#include <string>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#if !defined(_WIN32) && !defined(__MINGW32__)
Copy link
Member

Choose a reason for hiding this comment

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

I think that I would rather see this as

#if defined (__unix__) || (defined(__APPLE__) && defined(__MACH__))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - what I'm hoping for is to actually be able to get rid of this whole thing, and just import <iostream> for std::getline, so this might actually all go!

#include <unistd.h>
#else
#include <io.h>
#endif

#include <iostream>
#include <string>
#include <stdio.h>
Copy link
Member

Choose a reason for hiding this comment

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

What is this header pulling in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure. I've cleaned up the headers in the latest commit, but I haven't tested it on multiple platforms, so we'll see if it all compiles :)

@hughbe
Copy link
Contributor Author

hughbe commented Jan 19, 2017

@swift-ci please smoke test

@hughbe
Copy link
Contributor Author

hughbe commented Jan 19, 2017

Wonderful! looks like the tests are passing!

This was caused by the fact that POSIX getline includes a newline \n in the resultant string, but std::getline doesn't.

Fixed by appending a '\n' to the printing to llvm::outs()

@hughbe hughbe dismissed compnerd’s stale review January 19, 2017 16:51

Please re-review

@jrose-apple
Copy link
Contributor

I guess we don't care about <iostream>'s static constructors this time?

@jrose-apple
Copy link
Contributor

(That's the main reason LLVM doesn't use it.)

@jckarter
Copy link
Contributor

We do. We should avoid importing <iostream>.

@hughbe
Copy link
Contributor Author

hughbe commented Jan 19, 2017

Interesting, considering I actually got this code pattern from LLVM: https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-cxxfilt/llvm-cxxfilt.cpp

@compnerd was the author there.

What's the alternative, id like to remove unistd imports and make this platform independent.

@jrose-apple
Copy link
Contributor

I don't think it's so bad for a standalone tool like swift-demangle. If the constructors weren't static we'd still have to run them immediately just to read from stdin. (Admittedly swift-demangle doesn't always read from stdin.)

@jrose-apple
Copy link
Contributor

We also do care about the streaming behavior (#4412).

@hughbe
Copy link
Contributor Author

hughbe commented Jan 19, 2017

Okay, does the code look good in its current form? I'll defer to you both for a decision on the high level direction.

@jrose-apple
Copy link
Contributor

I'm okay with it if @jckarter's convinced but since @compnerd started the review I'd let him sign off before merging.

@jckarter
Copy link
Contributor

I guess it's fine for now. LLVM doesn't have a similar portable API?

@compnerd
Copy link
Member

LGTM

@slavapestov slavapestov merged commit baedff6 into swiftlang:master Jan 20, 2017
@hughbe hughbe deleted the demangle-windows branch January 20, 2017 08:07
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.

5 participants