Skip to content

Commit ae5e4d0

Browse files
committed
---
yaml --- r: 114577 b: refs/heads/master c: d35a380 h: refs/heads/master i: 114575: 6280c33 v: v3
1 parent 536f90f commit ae5e4d0

File tree

11 files changed

+222
-100
lines changed

11 files changed

+222
-100
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3b56724c217612b4adc64a59dca9b1fd8cff081d
2+
refs/heads/master: d35a38087088301aa58f244ae99d48b282df6fb2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/mk/docs.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ $(foreach crate,$(COMPILER_DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),COMPIL
287287
ifdef CFG_DISABLE_DOCS
288288
$(info cfg: disabling doc build (CFG_DISABLE_DOCS))
289289
DOC_TARGETS :=
290+
COMPILER_DOC_TARGETS :=
290291
endif
291292

292293
docs: $(DOC_TARGETS)

trunk/src/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ trait Circle : Shape { fn radius() -> f64; }
14351435
~~~~
14361436

14371437
the syntax `Circle : Shape` means that types that implement `Circle` must also have an implementation for `Shape`.
1438-
Multiple supertraits are separated by spaces, `trait Circle : Shape Eq { }`.
1438+
Multiple supertraits are separated by `+`, `trait Circle : Shape + Eq { }`.
14391439
In an implementation of `Circle` for a given type `T`, methods can refer to `Shape` methods,
14401440
since the typechecker checks that any type with an implementation of `Circle` also has an implementation of `Shape`.
14411441

trunk/src/libcore/failure.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,25 @@
2828
2929
#![allow(dead_code, missing_doc)]
3030

31-
#[cfg(not(test))]
32-
use str::raw::c_str_to_static_slice;
3331
use fmt;
32+
use intrinsics;
33+
#[cfg(not(test), stage0)]
34+
use str::raw::c_str_to_static_slice;
35+
36+
#[cold] #[inline(never)] // this is the slow path, always
37+
#[lang="fail_"]
38+
#[cfg(not(test), not(stage0))]
39+
fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! {
40+
format_args!(|args| -> () {
41+
begin_unwind(args, file, line);
42+
}, "{}", expr);
43+
44+
unsafe { intrinsics::abort() }
45+
}
3446

3547
#[cold] #[inline(never)] // this is the slow path, always
3648
#[lang="fail_"]
37-
#[cfg(not(test))]
49+
#[cfg(not(test), stage0)]
3850
fn fail_(expr: *u8, file: *u8, line: uint) -> ! {
3951
unsafe {
4052
let expr = c_str_to_static_slice(expr as *i8);
@@ -43,19 +55,30 @@ fn fail_(expr: *u8, file: *u8, line: uint) -> ! {
4355
begin_unwind(args, file, line);
4456
}, "{}", expr);
4557

46-
loop {}
58+
intrinsics::abort()
4759
}
4860
}
4961

5062
#[cold]
5163
#[lang="fail_bounds_check"]
52-
#[cfg(not(test))]
64+
#[cfg(not(test), not(stage0))]
65+
fn fail_bounds_check(file: &'static str, line: uint,
66+
index: uint, len: uint) -> ! {
67+
format_args!(|args| -> () {
68+
begin_unwind(args, file, line);
69+
}, "index out of bounds: the len is {} but the index is {}", len, index);
70+
unsafe { intrinsics::abort() }
71+
}
72+
73+
#[cold]
74+
#[lang="fail_bounds_check"]
75+
#[cfg(not(test), stage0)]
5376
fn fail_bounds_check(file: *u8, line: uint, index: uint, len: uint) -> ! {
5477
let file = unsafe { c_str_to_static_slice(file as *i8) };
5578
format_args!(|args| -> () {
5679
begin_unwind(args, file, line);
5780
}, "index out of bounds: the len is {} but the index is {}", len, index);
58-
loop {}
81+
unsafe { intrinsics::abort() }
5982
}
6083

6184
#[cold]

trunk/src/liblibc/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ pub use funcs::bsd43::{shutdown};
235235
#[cfg(windows)] pub use types::os::arch::extra::{LARGE_INTEGER, LPVOID, LONG};
236236
#[cfg(windows)] pub use types::os::arch::extra::{time64_t, OVERLAPPED, LPCWSTR};
237237
#[cfg(windows)] pub use types::os::arch::extra::{LPOVERLAPPED, SIZE_T, LPDWORD};
238+
#[cfg(windows)] pub use types::os::arch::extra::{SECURITY_ATTRIBUTES};
238239
#[cfg(windows)] pub use funcs::c95::string::{wcslen};
239240
#[cfg(windows)] pub use funcs::posix88::stat_::{wstat, wutime, wchmod, wrmdir};
240241
#[cfg(windows)] pub use funcs::bsd43::{closesocket};
@@ -1140,8 +1141,12 @@ pub mod types {
11401141
pub type LPWCH = *mut WCHAR;
11411142
pub type LPCH = *mut CHAR;
11421143

1143-
// Not really, but opaque to us.
1144-
pub type LPSECURITY_ATTRIBUTES = LPVOID;
1144+
pub struct SECURITY_ATTRIBUTES {
1145+
pub nLength: DWORD,
1146+
pub lpSecurityDescriptor: LPVOID,
1147+
pub bInheritHandle: BOOL,
1148+
}
1149+
pub type LPSECURITY_ATTRIBUTES = *mut SECURITY_ATTRIBUTES;
11451150

11461151
pub type LPVOID = *mut c_void;
11471152
pub type LPCVOID = *c_void;

trunk/src/libnative/io/process.rs

Lines changed: 78 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ struct SpawnProcessResult {
244244
}
245245

246246
#[cfg(windows)]
247-
fn spawn_process_os(cfg: ProcessConfig, in_fd: c_int, out_fd: c_int, err_fd: c_int)
247+
fn spawn_process_os(cfg: ProcessConfig,
248+
in_fd: c_int, out_fd: c_int, err_fd: c_int)
248249
-> IoResult<SpawnProcessResult> {
249250
use libc::types::os::arch::extra::{DWORD, HANDLE, STARTUPINFO};
250251
use libc::consts::os::extra::{
@@ -278,38 +279,51 @@ fn spawn_process_os(cfg: ProcessConfig, in_fd: c_int, out_fd: c_int, err_fd: c_i
278279

279280
let cur_proc = GetCurrentProcess();
280281

281-
if in_fd != -1 {
282-
let orig_std_in = get_osfhandle(in_fd) as HANDLE;
283-
if orig_std_in == INVALID_HANDLE_VALUE as HANDLE {
284-
fail!("failure in get_osfhandle: {}", os::last_os_error());
285-
}
286-
if DuplicateHandle(cur_proc, orig_std_in, cur_proc, &mut si.hStdInput,
287-
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
288-
fail!("failure in DuplicateHandle: {}", os::last_os_error());
289-
}
290-
}
291-
292-
if out_fd != -1 {
293-
let orig_std_out = get_osfhandle(out_fd) as HANDLE;
294-
if orig_std_out == INVALID_HANDLE_VALUE as HANDLE {
295-
fail!("failure in get_osfhandle: {}", os::last_os_error());
296-
}
297-
if DuplicateHandle(cur_proc, orig_std_out, cur_proc, &mut si.hStdOutput,
298-
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
299-
fail!("failure in DuplicateHandle: {}", os::last_os_error());
282+
// Similarly to unix, we don't actually leave holes for the stdio file
283+
// descriptors, but rather open up /dev/null equivalents. These
284+
// equivalents are drawn from libuv's windows process spawning.
285+
let set_fd = |fd: c_int, slot: &mut HANDLE, is_stdin: bool| {
286+
if fd == -1 {
287+
let access = if is_stdin {
288+
libc::FILE_GENERIC_READ
289+
} else {
290+
libc::FILE_GENERIC_WRITE | libc::FILE_READ_ATTRIBUTES
291+
};
292+
let size = mem::size_of::<libc::SECURITY_ATTRIBUTES>();
293+
let mut sa = libc::SECURITY_ATTRIBUTES {
294+
nLength: size as libc::DWORD,
295+
lpSecurityDescriptor: ptr::mut_null(),
296+
bInheritHandle: 1,
297+
};
298+
*slot = os::win32::as_utf16_p("NUL", |filename| {
299+
libc::CreateFileW(filename,
300+
access,
301+
libc::FILE_SHARE_READ |
302+
libc::FILE_SHARE_WRITE,
303+
&mut sa,
304+
libc::OPEN_EXISTING,
305+
0,
306+
ptr::mut_null())
307+
});
308+
if *slot == INVALID_HANDLE_VALUE as libc::HANDLE {
309+
return Err(super::last_error())
310+
}
311+
} else {
312+
let orig = get_osfhandle(fd) as HANDLE;
313+
if orig == INVALID_HANDLE_VALUE as HANDLE {
314+
return Err(super::last_error())
315+
}
316+
if DuplicateHandle(cur_proc, orig, cur_proc, slot,
317+
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
318+
return Err(super::last_error())
319+
}
300320
}
301-
}
321+
Ok(())
322+
};
302323

303-
if err_fd != -1 {
304-
let orig_std_err = get_osfhandle(err_fd) as HANDLE;
305-
if orig_std_err == INVALID_HANDLE_VALUE as HANDLE {
306-
fail!("failure in get_osfhandle: {}", os::last_os_error());
307-
}
308-
if DuplicateHandle(cur_proc, orig_std_err, cur_proc, &mut si.hStdError,
309-
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
310-
fail!("failure in DuplicateHandle: {}", os::last_os_error());
311-
}
312-
}
324+
try!(set_fd(in_fd, &mut si.hStdInput, true));
325+
try!(set_fd(out_fd, &mut si.hStdOutput, false));
326+
try!(set_fd(err_fd, &mut si.hStdError, false));
313327

314328
let cmd_str = make_command_line(cfg.program, cfg.args);
315329
let mut pi = zeroed_process_information();
@@ -338,9 +352,9 @@ fn spawn_process_os(cfg: ProcessConfig, in_fd: c_int, out_fd: c_int, err_fd: c_i
338352
})
339353
});
340354

341-
if in_fd != -1 { assert!(CloseHandle(si.hStdInput) != 0); }
342-
if out_fd != -1 { assert!(CloseHandle(si.hStdOutput) != 0); }
343-
if err_fd != -1 { assert!(CloseHandle(si.hStdError) != 0); }
355+
assert!(CloseHandle(si.hStdInput) != 0);
356+
assert!(CloseHandle(si.hStdOutput) != 0);
357+
assert!(CloseHandle(si.hStdError) != 0);
344358

345359
match create_err {
346360
Some(err) => return Err(err),
@@ -379,9 +393,9 @@ fn zeroed_startupinfo() -> libc::types::os::arch::extra::STARTUPINFO {
379393
wShowWindow: 0,
380394
cbReserved2: 0,
381395
lpReserved2: ptr::mut_null(),
382-
hStdInput: ptr::mut_null(),
383-
hStdOutput: ptr::mut_null(),
384-
hStdError: ptr::mut_null()
396+
hStdInput: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
397+
hStdOutput: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
398+
hStdError: libc::INVALID_HANDLE_VALUE as libc::HANDLE,
385399
}
386400
}
387401

@@ -489,6 +503,10 @@ fn spawn_process_os(cfg: ProcessConfig, in_fd: c_int, out_fd: c_int, err_fd: c_i
489503
let mut input = file::FileDesc::new(pipe.input, true);
490504
let mut output = file::FileDesc::new(pipe.out, true);
491505

506+
// We may use this in the child, so perform allocations before the
507+
// fork
508+
let devnull = "/dev/null".to_c_str();
509+
492510
set_cloexec(output.fd());
493511

494512
let pid = fork();
@@ -563,21 +581,29 @@ fn spawn_process_os(cfg: ProcessConfig, in_fd: c_int, out_fd: c_int, err_fd: c_i
563581

564582
rustrt::rust_unset_sigprocmask();
565583

566-
if in_fd == -1 {
567-
let _ = libc::close(libc::STDIN_FILENO);
568-
} else if retry(|| dup2(in_fd, 0)) == -1 {
569-
fail(&mut output);
570-
}
571-
if out_fd == -1 {
572-
let _ = libc::close(libc::STDOUT_FILENO);
573-
} else if retry(|| dup2(out_fd, 1)) == -1 {
574-
fail(&mut output);
575-
}
576-
if err_fd == -1 {
577-
let _ = libc::close(libc::STDERR_FILENO);
578-
} else if retry(|| dup2(err_fd, 2)) == -1 {
579-
fail(&mut output);
580-
}
584+
// If a stdio file descriptor is set to be ignored (via a -1 file
585+
// descriptor), then we don't actually close it, but rather open
586+
// up /dev/null into that file descriptor. Otherwise, the first file
587+
// descriptor opened up in the child would be numbered as one of the
588+
// stdio file descriptors, which is likely to wreak havoc.
589+
let setup = |src: c_int, dst: c_int| {
590+
let src = if src == -1 {
591+
let flags = if dst == libc::STDIN_FILENO {
592+
libc::O_RDONLY
593+
} else {
594+
libc::O_RDWR
595+
};
596+
devnull.with_ref(|p| libc::open(p, flags, 0))
597+
} else {
598+
src
599+
};
600+
src != -1 && retry(|| dup2(src, dst)) != -1
601+
};
602+
603+
if !setup(in_fd, libc::STDIN_FILENO) { fail(&mut output) }
604+
if !setup(out_fd, libc::STDOUT_FILENO) { fail(&mut output) }
605+
if !setup(err_fd, libc::STDERR_FILENO) { fail(&mut output) }
606+
581607
// close all other fds
582608
for fd in range(3, getdtablesize()).rev() {
583609
if fd != output.fd() {

trunk/src/librustc/back/link.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,8 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
10191019
a.add_native_library("compiler-rt").unwrap();
10201020

10211021
let crates = sess.cstore.get_used_crates(cstore::RequireStatic);
1022+
let mut all_native_libs = vec![];
1023+
10221024
for &(cnum, ref path) in crates.iter() {
10231025
let name = sess.cstore.get_crate_data(cnum).name.clone();
10241026
let p = match *path {
@@ -1029,17 +1031,25 @@ fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
10291031
}
10301032
};
10311033
a.add_rlib(&p, name.as_slice(), sess.lto()).unwrap();
1034+
10321035
let native_libs = csearch::get_native_libraries(&sess.cstore, cnum);
1033-
for &(kind, ref lib) in native_libs.iter() {
1034-
let name = match kind {
1035-
cstore::NativeStatic => "static library",
1036-
cstore::NativeUnknown => "library",
1037-
cstore::NativeFramework => "framework",
1038-
};
1039-
sess.warn(format!("unlinked native {}: {}",
1040-
name,
1041-
*lib).as_slice());
1042-
}
1036+
all_native_libs.extend(native_libs.move_iter());
1037+
}
1038+
1039+
if !all_native_libs.is_empty() {
1040+
sess.warn("link against the following native artifacts when linking against \
1041+
this static library");
1042+
sess.note("the order and any duplication can be significant on some platforms, \
1043+
and so may need to be preserved");
1044+
}
1045+
1046+
for &(kind, ref lib) in all_native_libs.iter() {
1047+
let name = match kind {
1048+
cstore::NativeStatic => "static library",
1049+
cstore::NativeUnknown => "library",
1050+
cstore::NativeFramework => "framework",
1051+
};
1052+
sess.note(format!("{}: {}", name, *lib).as_slice());
10431053
}
10441054
}
10451055

trunk/src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
596596
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
597597
unsafe {
598598
let len = s.get().len();
599-
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s, false), Type::i8p(cx).to_ref());
599+
let cs = llvm::LLVMConstPointerCast(C_cstr(cx, s, false),
600+
Type::i8p(cx).to_ref());
600601
C_struct(cx, [cs, C_uint(cx, len)], false)
601602
}
602603
}
@@ -843,19 +844,6 @@ pub fn find_vtable(tcx: &ty::ctxt,
843844
param_bounds.get(n_bound).clone()
844845
}
845846

846-
pub fn filename_and_line_num_from_span(bcx: &Block, span: Span)
847-
-> (ValueRef, ValueRef) {
848-
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
849-
let filename_cstr = C_cstr(bcx.ccx(),
850-
token::intern_and_get_ident(loc.file
851-
.name
852-
.as_slice()),
853-
true);
854-
let filename = build::PointerCast(bcx, filename_cstr, Type::i8p(bcx.ccx()));
855-
let line = C_int(bcx.ccx(), loc.line as int);
856-
(filename, line)
857-
}
858-
859847
// Casts a Rust bool value to an i1.
860848
pub fn bool_to_i1(bcx: &Block, llval: ValueRef) -> ValueRef {
861849
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(bcx.ccx(), false))

0 commit comments

Comments
 (0)