native: Require all results are used and fix fallout

This commit is contained in:
Alex Crichton 2014-01-30 14:28:28 -08:00
parent 41cde566bb
commit ae581a0103
7 changed files with 26 additions and 22 deletions

View File

@ -23,7 +23,7 @@ static mut TASK_COUNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
static mut TASK_LOCK: Mutex = MUTEX_INIT; static mut TASK_LOCK: Mutex = MUTEX_INIT;
pub fn increment() { pub fn increment() {
unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst); } let _ = unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst) };
} }
pub fn decrement() { pub fn decrement() {

View File

@ -422,7 +422,7 @@ impl rtio::RtioFileStream for CFile {
impl Drop for CFile { impl Drop for CFile {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { libc::fclose(self.file); } unsafe { let _ = libc::fclose(self.file); }
} }
} }
@ -512,7 +512,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
paths.push(Path::new(cstr)); paths.push(Path::new(cstr));
entry_ptr = readdir(dir_ptr); entry_ptr = readdir(dir_ptr);
} }
closedir(dir_ptr); assert_eq!(closedir(dir_ptr), 0);
Ok(paths) Ok(paths)
} else { } else {
Err(super::last_error()) Err(super::last_error())
@ -932,7 +932,7 @@ mod tests {
let mut reader = FileDesc::new(input, true); let mut reader = FileDesc::new(input, true);
let mut writer = FileDesc::new(out, true); let mut writer = FileDesc::new(out, true);
writer.inner_write(bytes!("test")); writer.inner_write(bytes!("test")).unwrap();
let mut buf = [0u8, ..4]; let mut buf = [0u8, ..4];
match reader.inner_read(buf) { match reader.inner_read(buf) {
Ok(4) => { Ok(4) => {
@ -957,9 +957,9 @@ mod tests {
assert!(!f.is_null()); assert!(!f.is_null());
let mut file = CFile::new(f); let mut file = CFile::new(f);
file.write(bytes!("test")); file.write(bytes!("test")).unwrap();
let mut buf = [0u8, ..4]; let mut buf = [0u8, ..4];
file.seek(0, io::SeekSet); let _ = file.seek(0, io::SeekSet).unwrap();
match file.read(buf) { match file.read(buf) {
Ok(4) => { Ok(4) => {
assert_eq!(buf[0], 't' as u8); assert_eq!(buf[0], 't' as u8);

View File

@ -112,8 +112,8 @@ fn setsockopt<T>(fd: sock_t, opt: libc::c_int, val: libc::c_int,
} }
} }
#[cfg(windows)] unsafe fn close(sock: sock_t) { libc::closesocket(sock); } #[cfg(windows)] unsafe fn close(sock: sock_t) { let _ = libc::closesocket(sock); }
#[cfg(unix)] unsafe fn close(sock: sock_t) { libc::close(sock); } #[cfg(unix)] unsafe fn close(sock: sock_t) { let _ = libc::close(sock); }
fn sockname(fd: sock_t, fn sockname(fd: sock_t,
f: extern "system" unsafe fn(sock_t, *mut libc::sockaddr, f: extern "system" unsafe fn(sock_t, *mut libc::sockaddr,

View File

@ -102,9 +102,9 @@ impl Process {
cwd.as_ref(), in_fd, out_fd, err_fd); cwd.as_ref(), in_fd, out_fd, err_fd);
unsafe { unsafe {
for pipe in in_pipe.iter() { libc::close(pipe.input); } for pipe in in_pipe.iter() { let _ = libc::close(pipe.input); }
for pipe in out_pipe.iter() { libc::close(pipe.out); } for pipe in out_pipe.iter() { let _ = libc::close(pipe.out); }
for pipe in err_pipe.iter() { libc::close(pipe.out); } for pipe in err_pipe.iter() { let _ = libc::close(pipe.out); }
} }
match res { match res {
@ -163,8 +163,8 @@ impl rtio::RtioProcess for Process {
#[cfg(not(windows))] #[cfg(not(windows))]
unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> { unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> {
libc::funcs::posix88::signal::kill(pid, signal as c_int); let r = libc::funcs::posix88::signal::kill(pid, signal as c_int);
Ok(()) super::mkerr_libc(r)
} }
} }
} }
@ -445,24 +445,24 @@ fn spawn_process_os(prog: &str, args: &[~str],
rustrt::rust_unset_sigprocmask(); rustrt::rust_unset_sigprocmask();
if in_fd == -1 { if in_fd == -1 {
libc::close(libc::STDIN_FILENO); let _ = libc::close(libc::STDIN_FILENO);
} else if retry(|| dup2(in_fd, 0)) == -1 { } else if retry(|| dup2(in_fd, 0)) == -1 {
fail!("failure in dup2(in_fd, 0): {}", os::last_os_error()); fail!("failure in dup2(in_fd, 0): {}", os::last_os_error());
} }
if out_fd == -1 { if out_fd == -1 {
libc::close(libc::STDOUT_FILENO); let _ = libc::close(libc::STDOUT_FILENO);
} else if retry(|| dup2(out_fd, 1)) == -1 { } else if retry(|| dup2(out_fd, 1)) == -1 {
fail!("failure in dup2(out_fd, 1): {}", os::last_os_error()); fail!("failure in dup2(out_fd, 1): {}", os::last_os_error());
} }
if err_fd == -1 { if err_fd == -1 {
libc::close(libc::STDERR_FILENO); let _ = libc::close(libc::STDERR_FILENO);
} else if retry(|| dup2(err_fd, 2)) == -1 { } else if retry(|| dup2(err_fd, 2)) == -1 {
fail!("failure in dup3(err_fd, 2): {}", os::last_os_error()); fail!("failure in dup3(err_fd, 2): {}", os::last_os_error());
} }
// close all other fds // close all other fds
for fd in range(3, getdtablesize()).rev() { for fd in range(3, getdtablesize()).rev() {
if fd != output.fd() { if fd != output.fd() {
close(fd as c_int); let _ = close(fd as c_int);
} }
} }
@ -478,7 +478,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
} }
}); });
with_argv(prog, args, |argv| { with_argv(prog, args, |argv| {
execvp(*argv, argv); let _ = execvp(*argv, argv);
let errno = os::errno(); let errno = os::errno();
let bytes = [ let bytes = [
(errno << 24) as u8, (errno << 24) as u8,

View File

@ -187,7 +187,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
// drain the file descriptor // drain the file descriptor
let mut buf = [0]; let mut buf = [0];
fd.inner_read(buf).unwrap(); assert_eq!(fd.inner_read(buf).unwrap(), 1);
} }
-1 if os::errno() == libc::EINTR as int => {} -1 if os::errno() == libc::EINTR as int => {}
@ -216,7 +216,8 @@ impl Timer {
} }
pub fn sleep(ms: u64) { pub fn sleep(ms: u64) {
unsafe { libc::usleep((ms * 1000) as libc::c_uint); } // FIXME: this can fail because of EINTR, what do do?
let _ = unsafe { libc::usleep((ms * 1000) as libc::c_uint) };
} }
fn inner(&mut self) -> ~Inner { fn inner(&mut self) -> ~Inner {

View File

@ -21,6 +21,7 @@
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png", #[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://static.rust-lang.org/doc/master")]; html_root_url = "http://static.rust-lang.org/doc/master")];
#[deny(unused_result, unused_must_use)];
// NB this crate explicitly does *not* allow glob imports, please seriously // NB this crate explicitly does *not* allow glob imports, please seriously
// consider whether they're needed before adding that feature here (the // consider whether they're needed before adding that feature here (the
@ -61,9 +62,10 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
rt::init(argc, argv); rt::init(argc, argv);
let mut exit_code = None; let mut exit_code = None;
let mut main = Some(main); let mut main = Some(main);
task::new((my_stack_bottom, my_stack_top)).run(|| { let t = task::new((my_stack_bottom, my_stack_top)).run(|| {
exit_code = Some(run(main.take_unwrap())); exit_code = Some(run(main.take_unwrap()));
}); });
drop(t);
unsafe { rt::cleanup(); } unsafe { rt::cleanup(); }
// If the exit code wasn't set, then the task block must have failed. // If the exit code wasn't set, then the task block must have failed.
return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE); return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);

View File

@ -103,7 +103,8 @@ pub fn spawn_opts(opts: TaskOpts, f: proc()) {
let mut f = Some(f); let mut f = Some(f);
let mut task = task; let mut task = task;
task.put_runtime(ops as ~rt::Runtime); task.put_runtime(ops as ~rt::Runtime);
task.run(|| { f.take_unwrap()() }); let t = task.run(|| { f.take_unwrap()() });
drop(t);
bookkeeping::decrement(); bookkeeping::decrement();
}) })
} }