diff options
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/bookkeeping.rs | 2 | ||||
| -rw-r--r-- | src/libnative/io/file.rs | 29 | ||||
| -rw-r--r-- | src/libnative/io/net.rs | 4 | ||||
| -rw-r--r-- | src/libnative/io/process.rs | 45 | ||||
| -rw-r--r-- | src/libnative/io/timer_helper.rs | 4 | ||||
| -rw-r--r-- | src/libnative/io/timer_other.rs | 5 | ||||
| -rw-r--r-- | src/libnative/io/timer_timerfd.rs | 7 | ||||
| -rw-r--r-- | src/libnative/io/timer_win32.rs | 12 | ||||
| -rw-r--r-- | src/libnative/lib.rs | 4 | ||||
| -rw-r--r-- | src/libnative/task.rs | 3 |
10 files changed, 59 insertions, 56 deletions
diff --git a/src/libnative/bookkeeping.rs b/src/libnative/bookkeeping.rs index b07e4271ee4..868586b3691 100644 --- a/src/libnative/bookkeeping.rs +++ b/src/libnative/bookkeeping.rs @@ -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() { diff --git a/src/libnative/io/file.rs b/src/libnative/io/file.rs index acab7ce3a91..cc5b0770d4d 100644 --- a/src/libnative/io/file.rs +++ b/src/libnative/io/file.rs @@ -111,17 +111,14 @@ impl FileDesc { } impl io::Reader for FileDesc { - fn read(&mut self, buf: &mut [u8]) -> Option<uint> { - match self.inner_read(buf) { Ok(n) => Some(n), Err(..) => None } + fn read(&mut self, buf: &mut [u8]) -> io::IoResult<uint> { + self.inner_read(buf) } } impl io::Writer for FileDesc { - fn write(&mut self, buf: &[u8]) { - match self.inner_write(buf) { - Ok(()) => {} - Err(e) => { io::io_error::cond.raise(e); } - } + fn write(&mut self, buf: &[u8]) -> io::IoResult<()> { + self.inner_write(buf) } } @@ -425,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); } } } @@ -515,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()) @@ -564,7 +561,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> { } more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE); } - FindClose(find_handle); + assert!(FindClose(find_handle) != 0); free(wfd_ptr as *mut c_void); Ok(paths) } else { @@ -686,7 +683,9 @@ pub fn readlink(p: &CString) -> IoResult<Path> { ptr::mut_null()) }) }; - if handle == ptr::mut_null() { return Err(super::last_error()) } + if handle as int == libc::INVALID_HANDLE_VALUE as int { + return Err(super::last_error()) + } let ret = fill_utf16_buf_and_decode(|buf, sz| { unsafe { libc::GetFinalPathNameByHandleW(handle, buf as *u16, sz, @@ -697,7 +696,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> { Some(s) => Ok(Path::new(s)), None => Err(super::last_error()), }; - unsafe { libc::CloseHandle(handle) }; + assert!(unsafe { libc::CloseHandle(handle) } != 0); return ret; } @@ -935,7 +934,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) => { @@ -960,9 +959,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); diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index 2f4bec22755..ac68b1523d7 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -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, diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index 13dd4298777..2a061c5f9b2 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -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 { @@ -149,9 +149,8 @@ impl rtio::RtioProcess for Process { unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> { match signal { io::process::PleaseExitSignal | io::process::MustDieSignal => { - libc::funcs::extra::kernel32::TerminateProcess( - cast::transmute(pid), 1); - Ok(()) + let ret = libc::TerminateProcess(pid as libc::HANDLE, 1); + super::mkerr_winbool(ret) } _ => Err(io::IoError { kind: io::OtherIoError, @@ -163,8 +162,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) } } } @@ -255,9 +254,9 @@ fn spawn_process_os(prog: &str, args: &[~str], }) }); - CloseHandle(si.hStdInput); - CloseHandle(si.hStdOutput); - CloseHandle(si.hStdError); + assert!(CloseHandle(si.hStdInput) != 0); + assert!(CloseHandle(si.hStdOutput) != 0); + assert!(CloseHandle(si.hStdError) != 0); match create_err { Some(err) => return Err(err), @@ -269,7 +268,7 @@ fn spawn_process_os(prog: &str, args: &[~str], // able to close it later. We don't close the process handle however // because std::we want the process id to stay valid at least until the // calling code closes the process handle. - CloseHandle(pi.hThread); + assert!(CloseHandle(pi.hThread) != 0); Ok(SpawnProcessResult { pid: pi.dwProcessId as pid_t, @@ -445,24 +444,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 +477,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, @@ -576,9 +575,9 @@ fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T { #[cfg(windows)] fn free_handle(handle: *()) { - unsafe { - libc::funcs::extra::kernel32::CloseHandle(cast::transmute(handle)); - } + assert!(unsafe { + libc::CloseHandle(cast::transmute(handle)) != 0 + }) } #[cfg(unix)] @@ -629,15 +628,15 @@ fn waitpid(pid: pid_t) -> p::ProcessExit { loop { let mut status = 0; if GetExitCodeProcess(process, &mut status) == FALSE { - CloseHandle(process); + assert!(CloseHandle(process) != 0); fail!("failure in GetExitCodeProcess: {}", os::last_os_error()); } if status != STILL_ACTIVE { - CloseHandle(process); + assert!(CloseHandle(process) != 0); return p::ExitStatus(status as int); } if WaitForSingleObject(process, INFINITE) == WAIT_FAILED { - CloseHandle(process); + assert!(CloseHandle(process) != 0); fail!("failure in WaitForSingleObject: {}", os::last_os_error()); } } diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs index 74759b467d4..7311be46e8b 100644 --- a/src/libnative/io/timer_helper.rs +++ b/src/libnative/io/timer_helper.rs @@ -126,11 +126,11 @@ mod imp { } pub fn signal(handle: HANDLE) { - unsafe { SetEvent(handle); } + assert!(unsafe { SetEvent(handle) != 0 }); } pub fn close(handle: HANDLE) { - unsafe { CloseHandle(handle); } + assert!(unsafe { CloseHandle(handle) != 0 }); } extern "system" { diff --git a/src/libnative/io/timer_other.rs b/src/libnative/io/timer_other.rs index bc005f2fe8d..cda239329dc 100644 --- a/src/libnative/io/timer_other.rs +++ b/src/libnative/io/timer_other.rs @@ -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 { diff --git a/src/libnative/io/timer_timerfd.rs b/src/libnative/io/timer_timerfd.rs index ca20314997e..7c22e90bbff 100644 --- a/src/libnative/io/timer_timerfd.rs +++ b/src/libnative/io/timer_timerfd.rs @@ -96,7 +96,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) { if fd == input { let mut buf = [0, ..1]; // drain the input file descriptor of its input - FileDesc::new(fd, false).inner_read(buf).unwrap(); + let _ = FileDesc::new(fd, false).inner_read(buf).unwrap(); incoming = true; } else { let mut bits = [0, ..8]; @@ -104,7 +104,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) { // // FIXME: should this perform a send() this number of // times? - FileDesc::new(fd, false).inner_read(bits).unwrap(); + let _ = FileDesc::new(fd, false).inner_read(bits).unwrap(); let remove = { match map.find(&fd).expect("fd unregistered") { &(ref c, oneshot) => !c.try_send(()) || oneshot @@ -166,7 +166,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 remove(&mut self) { diff --git a/src/libnative/io/timer_win32.rs b/src/libnative/io/timer_win32.rs index e359d99eedf..6b472d2f46d 100644 --- a/src/libnative/io/timer_win32.rs +++ b/src/libnative/io/timer_win32.rs @@ -62,8 +62,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) { c.send(()); match objs.iter().position(|&o| o == obj) { Some(i) => { - objs.remove(i); - chans.remove(i - 1); + drop(objs.remove(i)); + drop(chans.remove(i - 1)); } None => {} } @@ -83,8 +83,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) { } }; if remove { - objs.remove(idx as uint); - chans.remove(idx as uint - 1); + drop(objs.remove(idx as uint)); + drop(chans.remove(idx as uint - 1)); } } } @@ -133,7 +133,7 @@ impl rtio::RtioTimer for Timer { ptr::mut_null(), 0) }, 1); - unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE); } + let _ = unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE) }; } fn oneshot(&mut self, msecs: u64) -> Port<()> { @@ -173,7 +173,7 @@ impl rtio::RtioTimer for Timer { impl Drop for Timer { fn drop(&mut self) { self.remove(); - unsafe { libc::CloseHandle(self.obj); } + assert!(unsafe { libc::CloseHandle(self.obj) != 0 }); } } diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index f69ad8fc1aa..1e4317af397 100644 --- a/src/libnative/lib.rs +++ b/src/libnative/lib.rs @@ -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); diff --git a/src/libnative/task.rs b/src/libnative/task.rs index 37425179701..0def5cb4053 100644 --- a/src/libnative/task.rs +++ b/src/libnative/task.rs @@ -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(); }) } |
