Skip to content

Commit a2f9f75

Browse files
committed
---
yaml --- r: 146065 b: refs/heads/try2 c: 6e6981c h: refs/heads/master i: 146063: 88f761c v: v3
1 parent f5ab535 commit a2f9f75

File tree

9 files changed

+174
-23
lines changed

9 files changed

+174
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c5346fea38ed391c7ea83b3d03354904f0f3bd39
8+
refs/heads/try2: 6e6981c3eb92ab87342ae9ccb3ead879fb7cbdb0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/back/link.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pub mod write {
297297
if !sess.no_prepopulate_passes() {
298298
llvm::LLVMRustAddAnalysisPasses(tm, fpm, llmod);
299299
llvm::LLVMRustAddAnalysisPasses(tm, mpm, llmod);
300-
populate_llvm_passess(fpm, mpm, llmod, OptLevel);
300+
populate_llvm_passes(fpm, mpm, llmod, OptLevel);
301301
}
302302

303303
for pass in sess.opts.custom_passes.iter() {
@@ -422,10 +422,10 @@ pub mod write {
422422
}
423423
}
424424

425-
unsafe fn populate_llvm_passess(fpm: lib::llvm::PassManagerRef,
426-
mpm: lib::llvm::PassManagerRef,
427-
llmod: ModuleRef,
428-
opt: lib::llvm::CodeGenOptLevel) {
425+
unsafe fn populate_llvm_passes(fpm: lib::llvm::PassManagerRef,
426+
mpm: lib::llvm::PassManagerRef,
427+
llmod: ModuleRef,
428+
opt: lib::llvm::CodeGenOptLevel) {
429429
// Create the PassManagerBuilder for LLVM. We configure it with
430430
// reasonable defaults and prepare it to actually populate the pass
431431
// manager.

branches/try2/src/libstd/libc.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ pub mod consts {
12081208
pub static ERROR_ALREADY_EXISTS : c_int = 183;
12091209
pub static ERROR_INVALID_ADDRESS : c_int = 487;
12101210
pub static ERROR_FILE_INVALID : c_int = 1006;
1211-
pub static INVALID_HANDLE_VALUE: c_int = -1;
1211+
pub static INVALID_HANDLE_VALUE : c_int = -1;
12121212

12131213
pub static DELETE : DWORD = 0x00010000;
12141214
pub static READ_CONTROL : DWORD = 0x00020000;
@@ -3352,11 +3352,14 @@ pub mod funcs {
33523352
LPSECURITY_ATTRIBUTES)
33533353
-> BOOL;
33543354
pub fn CopyFileW(lpExistingFileName: LPCWSTR,
3355-
lpNewFileName: LPCWSTR,
3356-
bFailIfExists: BOOL)
3357-
-> BOOL;
3355+
lpNewFileName: LPCWSTR,
3356+
bFailIfExists: BOOL)
3357+
-> BOOL;
33583358
pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
33593359
pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
3360+
pub fn GetCurrentDirectoryW(nBufferLength: DWORD,
3361+
lpBuffer: LPWSTR)
3362+
-> DWORD;
33603363
pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
33613364
pub fn GetLastError() -> DWORD;
33623365
pub fn FindFirstFileW(fileName: *u16, findFileData: HANDLE)
@@ -3462,6 +3465,9 @@ pub mod funcs {
34623465
-> BOOL;
34633466
pub fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
34643467
pub fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
3468+
pub fn GetCurrentDirectoryW(nBufferLength: DWORD,
3469+
lpBuffer: LPWSTR)
3470+
-> DWORD;
34653471
pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
34663472
pub fn GetLastError() -> DWORD;
34673473
pub fn FindFirstFileW(fileName: *u16, findFileData: HANDLE)

branches/try2/src/libstd/os.rs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929
#[allow(missing_doc)];
3030

31-
use c_str::{CString, ToCStr};
31+
#[cfg(unix)]
32+
use c_str::CString;
3233
use clone::Clone;
3334
use container::Container;
3435
use io;
@@ -56,6 +57,11 @@ pub fn close(fd: c_int) -> c_int {
5657
}
5758
}
5859

60+
// On Windows, wide character version of function must be used to support
61+
// unicode, so functions should be split into at least two versions,
62+
// which are for Windows and for non-Windows, if necessary.
63+
// See https://github.com/mozilla/rust/issues/9822 for more information.
64+
5965
pub mod rustrt {
6066
use libc::{c_char, c_int};
6167
use libc;
@@ -64,11 +70,19 @@ pub mod rustrt {
6470
pub fn rust_path_is_dir(path: *libc::c_char) -> c_int;
6571
pub fn rust_path_exists(path: *libc::c_char) -> c_int;
6672
}
73+
74+
// Uses _wstat instead of stat.
75+
#[cfg(windows)]
76+
extern {
77+
pub fn rust_path_is_dir_u16(path: *u16) -> c_int;
78+
pub fn rust_path_exists_u16(path: *u16) -> c_int;
79+
}
6780
}
6881

6982
pub static TMPBUF_SZ : uint = 1000u;
7083
static BUF_BYTES : uint = 2048u;
7184

85+
#[cfg(unix)]
7286
pub fn getcwd() -> Path {
7387
#[fixed_stack_segment]; #[inline(never)];
7488
let mut buf = [0 as libc::c_char, ..BUF_BYTES];
@@ -83,6 +97,22 @@ pub fn getcwd() -> Path {
8397
}
8498
}
8599

100+
#[cfg(windows)]
101+
pub fn getcwd() -> Path {
102+
#[fixed_stack_segment]; #[inline(never)];
103+
use libc::DWORD;
104+
use libc::GetCurrentDirectoryW;
105+
let mut buf = [0 as u16, ..BUF_BYTES];
106+
do buf.as_mut_buf |buf, len| {
107+
unsafe {
108+
if libc::GetCurrentDirectoryW(len as DWORD, buf) == 0 as DWORD {
109+
fail2!();
110+
}
111+
}
112+
}
113+
Path::new(str::from_utf16(buf))
114+
}
115+
86116
#[cfg(windows)]
87117
pub mod win32 {
88118
use libc;
@@ -613,6 +643,7 @@ pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool {
613643
})
614644
}
615645
646+
#[cfg(unix)]
616647
/// Indicates whether a path represents a directory
617648
pub fn path_is_dir(p: &Path) -> bool {
618649
#[fixed_stack_segment]; #[inline(never)];
@@ -623,6 +654,18 @@ pub fn path_is_dir(p: &Path) -> bool {
623654
}
624655
}
625656
657+
658+
#[cfg(windows)]
659+
pub fn path_is_dir(p: &Path) -> bool {
660+
#[fixed_stack_segment]; #[inline(never)];
661+
unsafe {
662+
do os::win32::as_utf16_p(p.as_str().unwrap()) |buf| {
663+
rustrt::rust_path_is_dir_u16(buf) != 0 as c_int
664+
}
665+
}
666+
}
667+
668+
#[cfg(unix)]
626669
/// Indicates whether a path exists
627670
pub fn path_exists(p: &Path) -> bool {
628671
#[fixed_stack_segment]; #[inline(never)];
@@ -633,6 +676,16 @@ pub fn path_exists(p: &Path) -> bool {
633676
}
634677
}
635678
679+
#[cfg(windows)]
680+
pub fn path_exists(p: &Path) -> bool {
681+
#[fixed_stack_segment]; #[inline(never)];
682+
unsafe {
683+
do os::win32::as_utf16_p(p.as_str().unwrap()) |buf| {
684+
rustrt::rust_path_exists_u16(buf) != 0 as c_int
685+
}
686+
}
687+
}
688+
636689
/**
637690
* Convert a relative path to an absolute path
638691
*
@@ -1922,15 +1975,47 @@ mod tests {
19221975
19231976
#[test]
19241977
fn path_is_dir() {
1978+
use rt::io::file::open;
1979+
use rt::io::{OpenOrCreate, Read};
1980+
19251981
assert!((os::path_is_dir(&Path::new("."))));
19261982
assert!((!os::path_is_dir(&Path::new("test/stdtest/fs.rs"))));
1983+
1984+
let mut dirpath = os::tmpdir();
1985+
dirpath.push(format!("rust-test-{}/test-\uac00\u4e00\u30fc\u4f60\u597d",
1986+
rand::random::<u32>())); // 가一ー你好
1987+
debug2!("path_is_dir dirpath: {}", dirpath.display());
1988+
1989+
let mkdir_result = os::mkdir_recursive(&dirpath, (S_IRUSR | S_IWUSR | S_IXUSR) as i32);
1990+
debug2!("path_is_dir mkdir_result: {}", mkdir_result);
1991+
1992+
assert!((os::path_is_dir(&dirpath)));
1993+
1994+
let mut filepath = dirpath;
1995+
filepath.push("unicode-file-\uac00\u4e00\u30fc\u4f60\u597d.rs");
1996+
debug2!("path_is_dir filepath: {}", filepath.display());
1997+
1998+
open(&filepath, OpenOrCreate, Read); // ignore return; touch only
1999+
assert!((!os::path_is_dir(&filepath)));
2000+
2001+
assert!((!os::path_is_dir(&Path::new(
2002+
"test/unicode-bogus-dir-\uac00\u4e00\u30fc\u4f60\u597d"))));
19272003
}
19282004
19292005
#[test]
19302006
fn path_exists() {
19312007
assert!((os::path_exists(&Path::new("."))));
19322008
assert!((!os::path_exists(&Path::new(
19332009
"test/nonexistent-bogus-path"))));
2010+
2011+
let mut dirpath = os::tmpdir();
2012+
dirpath.push(format!("rust-test-{}/test-\uac01\u4e01\u30fc\u518d\u89c1",
2013+
rand::random::<u32>())); // 각丁ー再见
2014+
2015+
os::mkdir_recursive(&dirpath, (S_IRUSR | S_IWUSR | S_IXUSR) as i32);
2016+
assert!((os::path_exists(&dirpath)));
2017+
assert!((!os::path_exists(&Path::new(
2018+
"test/unicode-bogus-path-\uac01\u4e01\u30fc\u518d\u89c1"))));
19342019
}
19352020
19362021
#[test]

branches/try2/src/libstd/rt/io/stdio.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use fmt;
1112
use libc;
1213
use option::{Option, Some, None};
1314
use result::{Ok, Err};
@@ -56,7 +57,9 @@ pub fn stderr() -> StdWriter {
5657
pub fn print(s: &str) {
5758
// XXX: need to see if not caching stdin() is the cause of performance
5859
// issues, it should be possible to cache a stdout handle in each Task
59-
// and then re-use that across calls to print/println
60+
// and then re-use that across calls to print/println. Note that the
61+
// resolution of this comment will affect all of the prints below as
62+
// well.
6063
stdout().write(s.as_bytes());
6164
}
6265

@@ -68,6 +71,20 @@ pub fn println(s: &str) {
6871
out.write(['\n' as u8]);
6972
}
7073

74+
/// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible
75+
/// with the `format_args!` macro.
76+
pub fn print_args(fmt: &fmt::Arguments) {
77+
let mut out = stdout();
78+
fmt::write(&mut out as &mut Writer, fmt);
79+
}
80+
81+
/// Similar to `println`, but takes a `fmt::Arguments` structure to be
82+
/// compatible with the `format_args!` macro.
83+
pub fn println_args(fmt: &fmt::Arguments) {
84+
let mut out = stdout();
85+
fmt::writeln(&mut out as &mut Writer, fmt);
86+
}
87+
7188
/// Representation of a reader of a standard input stream
7289
pub struct StdReader {
7390
priv inner: ~RtioFileStream

branches/try2/src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -999,16 +999,11 @@ pub fn std_macros() -> @str {
999999
macro_rules! writeln(($dst:expr, $($arg:tt)*) => (
10001000
format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*)
10011001
))
1002-
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
1003-
// allocation but should rather delegate to an invocation of
1004-
// write! instead of format!
10051002
macro_rules! print (
1006-
($($arg:tt)*) => (::std::io::print(format!($($arg)*)))
1003+
($($arg:tt)*) => (format_args!(::std::rt::io::stdio::print_args, $($arg)*))
10071004
)
1008-
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
1009-
// allocation but should rather delegate to an io::Writer
10101005
macro_rules! println (
1011-
($($arg:tt)*) => (::std::io::println(format!($($arg)*)))
1006+
($($arg:tt)*) => (format_args!(::std::rt::io::stdio::println_args, $($arg)*))
10121007
)
10131008

10141009
macro_rules! local_data_key (

branches/try2/src/rt/rust_builtin.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ rust_list_dir_wfd_fp_buf(void* wfd) {
106106
#endif
107107

108108
extern "C" CDECL int
109-
rust_path_is_dir(char *path) {
109+
rust_path_is_dir(const char *path) {
110110
struct stat buf;
111111
if (stat(path, &buf)) {
112112
return 0;
@@ -115,14 +115,48 @@ rust_path_is_dir(char *path) {
115115
}
116116

117117
extern "C" CDECL int
118-
rust_path_exists(char *path) {
118+
#if defined(__WIN32__)
119+
rust_path_is_dir_u16(const wchar_t *path) {
120+
struct _stat buf;
121+
// Don't use GetFileAttributesW, it cannot get attributes of
122+
// some system files (e.g. pagefile.sys).
123+
if (_wstat(path, &buf)) {
124+
return 0;
125+
}
126+
return S_ISDIR(buf.st_mode);
127+
}
128+
#else
129+
rust_path_is_dir_u16(const void *path) {
130+
// Wide version of function is only used on Windows.
131+
return 0;
132+
}
133+
#endif
134+
135+
extern "C" CDECL int
136+
rust_path_exists(const char *path) {
119137
struct stat buf;
120138
if (stat(path, &buf)) {
121139
return 0;
122140
}
123141
return 1;
124142
}
125143

144+
extern "C" CDECL int
145+
#if defined(__WIN32__)
146+
rust_path_exists_u16(const wchar_t *path) {
147+
struct _stat buf;
148+
if (_wstat(path, &buf)) {
149+
return 0;
150+
}
151+
return 1;
152+
}
153+
#else
154+
rust_path_exists_u16(const void *path) {
155+
// Wide version of function is only used on Windows.
156+
return 0;
157+
}
158+
#endif
159+
126160
extern "C" CDECL FILE* rust_get_stdin() {return stdin;}
127161
extern "C" CDECL FILE* rust_get_stdout() {return stdout;}
128162
extern "C" CDECL FILE* rust_get_stderr() {return stderr;}
@@ -293,8 +327,12 @@ rust_localtime(int64_t sec, int32_t nsec, rust_tm *timeptr) {
293327
const char* zone = NULL;
294328
#if defined(__WIN32__)
295329
int32_t gmtoff = -timezone;
296-
char buffer[64];
297-
if (strftime(buffer, sizeof(buffer), "%Z", &tm) > 0) {
330+
wchar_t wbuffer[64];
331+
char buffer[256];
332+
// strftime("%Z") can contain non-UTF-8 characters on non-English locale (issue #9418),
333+
// so time zone should be converted from UTF-16 string set by wcsftime.
334+
if (wcsftime(wbuffer, sizeof(wbuffer) / sizeof(wchar_t), L"%Z", &tm) > 0) {
335+
WideCharToMultiByte(CP_UTF8, 0, wbuffer, -1, buffer, sizeof(buffer), NULL, NULL);
298336
zone = buffer;
299337
}
300338
#else

branches/try2/src/rt/rust_globals.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
#include <assert.h>
5555

5656
#if defined(__WIN32__)
57+
// Prevent unnecessary #include's from <windows.h>
58+
#ifndef WIN32_LEAN_AND_MEAN
59+
#define WIN32_LEAN_AND_MEAN
60+
#endif
61+
// Prevent defining min and max macro
62+
#ifndef NOMINMAX
63+
#define NOMINMAX
64+
#endif
5765
extern "C" {
5866
#include <windows.h>
5967
#include <tchar.h>

branches/try2/src/rt/rustrt.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ rust_timegm
1010
rust_mktime
1111
precise_time_ns
1212
rust_path_is_dir
13+
rust_path_is_dir_u16
1314
rust_path_exists
15+
rust_path_exists_u16
1416
rust_get_stdin
1517
rust_get_stdout
1618
rust_get_stderr

0 commit comments

Comments
 (0)