mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-07 13:25:45 +00:00
native: Require all results are used and fix fallout
This commit is contained in:
parent
41cde566bb
commit
ae581a0103
@ -23,7 +23,7 @@ static mut TASK_COUNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
|
||||
static mut TASK_LOCK: Mutex = MUTEX_INIT;
|
||||
|
||||
pub fn increment() {
|
||||
unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst); }
|
||||
let _ = unsafe { TASK_COUNT.fetch_add(1, atomics::SeqCst) };
|
||||
}
|
||||
|
||||
pub fn decrement() {
|
||||
|
@ -422,7 +422,7 @@ impl rtio::RtioFileStream for CFile {
|
||||
|
||||
impl Drop for CFile {
|
||||
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));
|
||||
entry_ptr = readdir(dir_ptr);
|
||||
}
|
||||
closedir(dir_ptr);
|
||||
assert_eq!(closedir(dir_ptr), 0);
|
||||
Ok(paths)
|
||||
} else {
|
||||
Err(super::last_error())
|
||||
@ -932,7 +932,7 @@ mod tests {
|
||||
let mut reader = FileDesc::new(input, true);
|
||||
let mut writer = FileDesc::new(out, true);
|
||||
|
||||
writer.inner_write(bytes!("test"));
|
||||
writer.inner_write(bytes!("test")).unwrap();
|
||||
let mut buf = [0u8, ..4];
|
||||
match reader.inner_read(buf) {
|
||||
Ok(4) => {
|
||||
@ -957,9 +957,9 @@ mod tests {
|
||||
assert!(!f.is_null());
|
||||
let mut file = CFile::new(f);
|
||||
|
||||
file.write(bytes!("test"));
|
||||
file.write(bytes!("test")).unwrap();
|
||||
let mut buf = [0u8, ..4];
|
||||
file.seek(0, io::SeekSet);
|
||||
let _ = file.seek(0, io::SeekSet).unwrap();
|
||||
match file.read(buf) {
|
||||
Ok(4) => {
|
||||
assert_eq!(buf[0], 't' as u8);
|
||||
|
@ -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(unix)] unsafe fn close(sock: sock_t) { libc::close(sock); }
|
||||
#[cfg(windows)] unsafe fn close(sock: sock_t) { let _ = libc::closesocket(sock); }
|
||||
#[cfg(unix)] unsafe fn close(sock: sock_t) { let _ = libc::close(sock); }
|
||||
|
||||
fn sockname(fd: sock_t,
|
||||
f: extern "system" unsafe fn(sock_t, *mut libc::sockaddr,
|
||||
|
@ -102,9 +102,9 @@ impl Process {
|
||||
cwd.as_ref(), in_fd, out_fd, err_fd);
|
||||
|
||||
unsafe {
|
||||
for pipe in in_pipe.iter() { libc::close(pipe.input); }
|
||||
for pipe in out_pipe.iter() { libc::close(pipe.out); }
|
||||
for pipe in err_pipe.iter() { libc::close(pipe.out); }
|
||||
for pipe in in_pipe.iter() { let _ = libc::close(pipe.input); }
|
||||
for pipe in out_pipe.iter() { let _ = libc::close(pipe.out); }
|
||||
for pipe in err_pipe.iter() { let _ = libc::close(pipe.out); }
|
||||
}
|
||||
|
||||
match res {
|
||||
@ -163,8 +163,8 @@ impl rtio::RtioProcess for Process {
|
||||
|
||||
#[cfg(not(windows))]
|
||||
unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> {
|
||||
libc::funcs::posix88::signal::kill(pid, signal as c_int);
|
||||
Ok(())
|
||||
let r = libc::funcs::posix88::signal::kill(pid, signal as c_int);
|
||||
super::mkerr_libc(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -445,24 +445,24 @@ fn spawn_process_os(prog: &str, args: &[~str],
|
||||
rustrt::rust_unset_sigprocmask();
|
||||
|
||||
if in_fd == -1 {
|
||||
libc::close(libc::STDIN_FILENO);
|
||||
let _ = libc::close(libc::STDIN_FILENO);
|
||||
} else if retry(|| dup2(in_fd, 0)) == -1 {
|
||||
fail!("failure in dup2(in_fd, 0): {}", os::last_os_error());
|
||||
}
|
||||
if out_fd == -1 {
|
||||
libc::close(libc::STDOUT_FILENO);
|
||||
let _ = libc::close(libc::STDOUT_FILENO);
|
||||
} else if retry(|| dup2(out_fd, 1)) == -1 {
|
||||
fail!("failure in dup2(out_fd, 1): {}", os::last_os_error());
|
||||
}
|
||||
if err_fd == -1 {
|
||||
libc::close(libc::STDERR_FILENO);
|
||||
let _ = libc::close(libc::STDERR_FILENO);
|
||||
} else if retry(|| dup2(err_fd, 2)) == -1 {
|
||||
fail!("failure in dup3(err_fd, 2): {}", os::last_os_error());
|
||||
}
|
||||
// close all other fds
|
||||
for fd in range(3, getdtablesize()).rev() {
|
||||
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| {
|
||||
execvp(*argv, argv);
|
||||
let _ = execvp(*argv, argv);
|
||||
let errno = os::errno();
|
||||
let bytes = [
|
||||
(errno << 24) as u8,
|
||||
|
@ -187,7 +187,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
|
||||
|
||||
// drain the file descriptor
|
||||
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 => {}
|
||||
@ -216,7 +216,8 @@ impl Timer {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -21,6 +21,7 @@
|
||||
#[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_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
|
||||
// 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);
|
||||
let mut exit_code = None;
|
||||
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()));
|
||||
});
|
||||
drop(t);
|
||||
unsafe { rt::cleanup(); }
|
||||
// If the exit code wasn't set, then the task block must have failed.
|
||||
return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);
|
||||
|
@ -103,7 +103,8 @@ pub fn spawn_opts(opts: TaskOpts, f: proc()) {
|
||||
let mut f = Some(f);
|
||||
let mut task = task;
|
||||
task.put_runtime(ops as ~rt::Runtime);
|
||||
task.run(|| { f.take_unwrap()() });
|
||||
let t = task.run(|| { f.take_unwrap()() });
|
||||
drop(t);
|
||||
bookkeeping::decrement();
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user