Skip to content

Commit dd6c3d9

Browse files
committed
---
yaml --- r: 120249 b: refs/heads/dist-snap c: e12aeb3 h: refs/heads/master i: 120247: e5c00bc v: v3
1 parent 48ce258 commit dd6c3d9

File tree

5 files changed

+26
-71
lines changed

5 files changed

+26
-71
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 1813e5aa1a03b0596b8de7abd1af31edf5d6098f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 5ad42b3ae97fd363b1a13c43305995fe139fc8ef
9+
refs/heads/dist-snap: e12aeb39bc4221421890011006c5ae23154cc695
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/liblibc/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub use funcs::bsd43::{shutdown};
208208
#[cfg(windows)] pub use consts::os::extra::{TRUE, FALSE, INFINITE};
209209
#[cfg(windows)] pub use consts::os::extra::{PROCESS_TERMINATE, PROCESS_QUERY_INFORMATION};
210210
#[cfg(windows)] pub use consts::os::extra::{STILL_ACTIVE, DETACHED_PROCESS};
211-
#[cfg(windows)] pub use consts::os::extra::{CREATE_NEW_PROCESS_GROUP};
211+
#[cfg(windows)] pub use consts::os::extra::{CREATE_NEW_PROCESS_GROUP, CREATE_UNICODE_ENVIRONMENT};
212212
#[cfg(windows)] pub use consts::os::extra::{FILE_BEGIN, FILE_END, FILE_CURRENT};
213213
#[cfg(windows)] pub use consts::os::extra::{FILE_GENERIC_READ, FILE_GENERIC_WRITE};
214214
#[cfg(windows)] pub use consts::os::extra::{FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_DELETE};
@@ -1937,6 +1937,7 @@ pub mod consts {
19371937

19381938
pub static DETACHED_PROCESS: DWORD = 0x00000008;
19391939
pub static CREATE_NEW_PROCESS_GROUP: DWORD = 0x00000200;
1940+
pub static CREATE_UNICODE_ENVIRONMENT: DWORD = 0x00000400;
19401941

19411942
pub static PIPE_ACCESS_DUPLEX: DWORD = 0x00000003;
19421943
pub static PIPE_ACCESS_INBOUND: DWORD = 0x00000001;
@@ -4193,7 +4194,7 @@ pub mod funcs {
41934194
pub mod kernel32 {
41944195
use types::os::arch::c95::{c_uint};
41954196
use types::os::arch::extra::{BOOL, DWORD, SIZE_T, HMODULE,
4196-
LPCWSTR, LPWSTR, LPCSTR, LPSTR,
4197+
LPCWSTR, LPWSTR,
41974198
LPCH, LPDWORD, LPVOID,
41984199
LPCVOID, LPOVERLAPPED,
41994200
LPSECURITY_ATTRIBUTES,
@@ -4251,16 +4252,16 @@ pub mod funcs {
42514252
dwProcessId: DWORD)
42524253
-> HANDLE;
42534254
pub fn GetCurrentProcess() -> HANDLE;
4254-
pub fn CreateProcessA(lpApplicationName: LPCSTR,
4255-
lpCommandLine: LPSTR,
4255+
pub fn CreateProcessW(lpApplicationName: LPCWSTR,
4256+
lpCommandLine: LPWSTR,
42564257
lpProcessAttributes:
42574258
LPSECURITY_ATTRIBUTES,
42584259
lpThreadAttributes:
42594260
LPSECURITY_ATTRIBUTES,
42604261
bInheritHandles: BOOL,
42614262
dwCreationFlags: DWORD,
42624263
lpEnvironment: LPVOID,
4263-
lpCurrentDirectory: LPCSTR,
4264+
lpCurrentDirectory: LPCWSTR,
42644265
lpStartupInfo: LPSTARTUPINFO,
42654266
lpProcessInformation:
42664267
LPPROCESS_INFORMATION)

branches/dist-snap/src/libnative/io/process.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn spawn_process_os(config: p::ProcessConfig,
258258
GetCurrentProcess,
259259
DuplicateHandle,
260260
CloseHandle,
261-
CreateProcessA
261+
CreateProcessW
262262
};
263263
use libc::funcs::extra::msvcrt::get_osfhandle;
264264

@@ -318,15 +318,15 @@ fn spawn_process_os(config: p::ProcessConfig,
318318
let mut create_err = None;
319319

320320
// stolen from the libuv code.
321-
let mut flags = 0;
321+
let mut flags = libc::CREATE_UNICODE_ENVIRONMENT;
322322
if config.detach {
323323
flags |= libc::DETACHED_PROCESS | libc::CREATE_NEW_PROCESS_GROUP;
324324
}
325325

326326
with_envp(env, |envp| {
327327
with_dirp(dir, |dirp| {
328-
cmd.with_c_str(|cmdp| {
329-
let created = CreateProcessA(ptr::null(), mem::transmute(cmdp),
328+
os::win32::as_mut_utf16_p(cmd, |cmdp| {
329+
let created = CreateProcessW(ptr::null(), cmdp,
330330
ptr::mut_null(), ptr::mut_null(), TRUE,
331331
flags, envp, dirp, &mut si,
332332
&mut pi);
@@ -691,7 +691,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T {
691691

692692
for pair in env.iter() {
693693
let kv = format!("{}={}", *pair.ref0(), *pair.ref1());
694-
blk.push_all(kv.as_bytes());
694+
blk.push_all(kv.to_utf16().as_slice());
695695
blk.push(0);
696696
}
697697

@@ -704,9 +704,12 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T {
704704
}
705705

706706
#[cfg(windows)]
707-
fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T {
707+
fn with_dirp<T>(d: Option<&Path>, cb: |*u16| -> T) -> T {
708708
match d {
709-
Some(dir) => dir.with_c_str(|buf| cb(buf)),
709+
Some(dir) => match dir.as_str() {
710+
Some(dir_str) => os::win32::as_utf16_p(dir_str, cb),
711+
None => cb(ptr::null())
712+
},
710713
None => cb(ptr::null())
711714
}
712715
}

branches/dist-snap/src/libstd/os.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,14 @@ pub mod win32 {
141141
}
142142

143143
pub fn as_utf16_p<T>(s: &str, f: |*u16| -> T) -> T {
144+
as_mut_utf16_p(s, |t| { f(t as *u16) })
145+
}
146+
147+
pub fn as_mut_utf16_p<T>(s: &str, f: |*mut u16| -> T) -> T {
144148
let mut t = s.to_utf16();
145149
// Null terminate before passing on.
146150
t.push(0u16);
147-
f(t.as_ptr())
151+
f(t.as_mut_ptr())
148152
}
149153
}
150154

branches/dist-snap/src/libstd/strbuf.rs

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use iter::{Extendable, FromIterator, Iterator, range};
1919
use mem;
2020
use option::{None, Option, Some};
2121
use ptr::RawPtr;
22-
use ptr;
2322
use slice::{OwnedVector, Vector, CloneableVector};
24-
use str::{CharRange, OwnedStr, Str, StrSlice, StrAllocating};
23+
use str::{OwnedStr, Str, StrSlice, StrAllocating};
2524
use str;
2625
use vec::Vec;
2726

@@ -216,49 +215,19 @@ impl StrBuf {
216215
Some(byte)
217216
}
218217

219-
/// Removes the last character from the string buffer and returns it. Returns `None` if this
220-
/// string buffer is empty.
221-
#[inline]
222-
pub fn pop_char(&mut self) -> Option<char> {
223-
let len = self.len();
224-
if len == 0 {
225-
return None
226-
}
227-
228-
let CharRange {ch, next} = self.as_slice().char_range_at_reverse(len);
229-
unsafe {
230-
self.vec.set_len(next);
231-
}
232-
Some(ch)
233-
}
234-
235218
/// Removes the first byte from the string buffer and returns it. Returns `None` if this string
236219
/// buffer is empty.
237220
///
238221
/// The caller must preserve the valid UTF-8 property.
239222
pub unsafe fn shift_byte(&mut self) -> Option<u8> {
240-
self.vec.shift()
241-
}
242-
243-
/// Removes the first character from the string buffer and returns it. Returns `None` if this
244-
/// string buffer is empty.
245-
///
246-
/// # Warning
247-
///
248-
/// This is a O(n) operation as it requires copying every element in the buffer.
249-
pub fn shift_char (&mut self) -> Option<char> {
250223
let len = self.len();
251224
if len == 0 {
252225
return None
253226
}
254227

255-
let CharRange {ch, next} = self.as_slice().char_range_at(0);
256-
let new_len = len - next;
257-
unsafe {
258-
ptr::copy_memory(self.vec.as_mut_ptr(), self.vec.as_ptr().offset(next as int), new_len);
259-
self.vec.set_len(new_len);
260-
}
261-
Some(ch)
228+
let byte = self.as_slice()[0];
229+
*self = self.as_slice().slice(1, len).into_strbuf();
230+
Some(byte)
262231
}
263232

264233
/// Views the string buffer as a mutable sequence of bytes.
@@ -388,28 +357,6 @@ mod tests {
388357
assert_eq!(data.as_slice(), "ประเทศไทย中华b¢€𤭢");
389358
}
390359

391-
#[test]
392-
fn test_pop_char() {
393-
let mut data = StrBuf::from_str("ประเทศไทย中华b¢€𤭢");
394-
assert_eq!(data.pop_char().unwrap(), '𤭢'); // 4 bytes
395-
assert_eq!(data.pop_char().unwrap(), '€'); // 3 bytes
396-
assert_eq!(data.pop_char().unwrap(), '¢'); // 2 bytes
397-
assert_eq!(data.pop_char().unwrap(), 'b'); // 1 bytes
398-
assert_eq!(data.pop_char().unwrap(), '华');
399-
assert_eq!(data.as_slice(), "ประเทศไทย中");
400-
}
401-
402-
#[test]
403-
fn test_shift_char() {
404-
let mut data = StrBuf::from_str("𤭢€¢b华ประเทศไทย中");
405-
assert_eq!(data.shift_char().unwrap(), '𤭢'); // 4 bytes
406-
assert_eq!(data.shift_char().unwrap(), '€'); // 3 bytes
407-
assert_eq!(data.shift_char().unwrap(), '¢'); // 2 bytes
408-
assert_eq!(data.shift_char().unwrap(), 'b'); // 1 bytes
409-
assert_eq!(data.shift_char().unwrap(), '华');
410-
assert_eq!(data.as_slice(), "ประเทศไทย中");
411-
}
412-
413360
#[test]
414361
fn test_str_truncate() {
415362
let mut s = StrBuf::from_str("12345");

0 commit comments

Comments
 (0)