Skip to content

Add Unicode support for process spawning on Windows #14075

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 4 commits into from
May 14, 2014
Merged

Add Unicode support for process spawning on Windows #14075

merged 4 commits into from
May 14, 2014

Conversation

Rufflewind
Copy link
Contributor

  • Use Unicode-aware versions of CreateProcess (Fixes libnative uses CreateProcessA on windows #13815) and Get/FreeEnvironmentStrings.
    • Includes a helper function os::win32::as_mut_utf16_p, which does the same thing as os::win32::as_utf16_p except the pointer is mutable.
    • Fixed make_command_line to handle Unicode correctly.
  • Tests for the above.

@alexcrichton
Copy link
Member

Nice work, this looks great!

@Rufflewind
Copy link
Contributor Author

Updated.

@alexcrichton
Copy link
Member

Looks great, thanks! Could you squash the last two commits up into the first ones? It also looks like this needs a rebase.

@Rufflewind
Copy link
Contributor Author

Thanks :) Done and ran the tests.

Changed libnative to use CreateProcessW instead of CreateProcessA.  In
addition, the lpEnvironment parameter now uses Unicode.

Added a helper function os::win32::as_mut_utf16_p, which does basically
the same thing as os::win32::as_utf16_p except the pointer is mutable.
Previously, make_command_line iterates over each u8 in the string and
then appends them as chars, so any non-ASCII string will get horribly
mangled by this function.  This fix should allow Unicode arguments to
work correctly in native::io::process::spawn.
Changed libstd to use Get/FreeEnvironmentStringsW instead of
Get/FreeEnvironmentStringsA to support Unicode environment variables.
Added a run-pass test to ensure that processes can be correctly spawned
using non-ASCII arguments, working directory, and environment variables.
It also tests Unicode support of os::env_as_bytes.

An additional assertion was added to the test for make_command_line to
verify it handles Unicode correctly.
@Rufflewind
Copy link
Contributor Author

Fixed the merge conflict.

@alexcrichton
Copy link
Member

cc @aturon, this will affect #13954

@aturon
Copy link
Member

aturon commented May 13, 2014

Ooh, happy to see this landing! Thanks for the heads-up.

bors added a commit that referenced this pull request May 13, 2014
- Use Unicode-aware versions of `CreateProcess` (Fixes #13815) and `Get/FreeEnvironmentStrings`.
    - Includes a helper function `os::win32::as_mut_utf16_p`, which does the same thing as `os::win32::as_utf16_p` except the pointer is mutable.
    - Fixed `make_command_line` to handle Unicode correctly.
- Tests for the above.
@bors bors closed this May 14, 2014
@bors bors merged commit b8e3f3a into rust-lang:master May 14, 2014
Some(dir) => dir.with_c_str(|buf| cb(buf)),
Some(dir) => match dir.as_str() {
Some(dir_str) => os::win32::as_utf16_p(dir_str, cb),
None => cb(ptr::null())
Copy link
Member

Choose a reason for hiding this comment

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

This silently removes the working directory configuration if it's not in utf8 format (i.e., when dir.as_str() returns None). It should fail loudly, using expect.

Don't worry about changing this, though -- I'm currently rebasing another patch around this one, for dealing with non-unicode filesystems/arguments on other platforms, and I'll address the problem there.

@Rufflewind Rufflewind deleted the patch-3 branch March 3, 2015 20:52
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.

libnative uses CreateProcessA on windows
4 participants