Skip to content

Commit

Permalink
Auto merge of #99624 - vincenzopalazzo:macros/unix_error, r=Amanieu
Browse files Browse the repository at this point in the history
promote debug_assert to assert when possible and useful

This PR fixed a very old issue #94705 to clarify and improve the POSIX error checking, and some of the checks are skipped because can have no benefit, but I'm sure that this can open some interesting discussion.

Fixes #94705

cc: `@tavianator`
cc: `@cuviper`
  • Loading branch information
bors committed Aug 12, 2022
2 parents cc65e1a + d91dff3 commit 569788e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,11 @@ impl Iterator for ReadDir {
impl Drop for Dir {
fn drop(&mut self) {
let r = unsafe { libc::closedir(self.0) };
debug_assert_eq!(r, 0);
assert!(
r == 0 || crate::io::Error::last_os_error().kind() == crate::io::ErrorKind::Interrupted,
"unexpected error during closedir: {:?}",
crate::io::Error::last_os_error()
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/unix/locks/pthread_condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl Condvar {
let mut sys_now = libc::timeval { tv_sec: 0, tv_usec: 0 };
let stable_now = Instant::now();
let r = libc::gettimeofday(&mut sys_now, ptr::null_mut());
debug_assert_eq!(r, 0);
assert_eq!(r, 0, "unexpected error: {:?}", crate::io::Error::last_os_error());

let nsec = dur.subsec_nanos() as libc::c_long + (sys_now.tv_usec * 1000) as libc::c_long;
let extra = (nsec / 1_000_000_000) as libc::time_t;
Expand Down

0 comments on commit 569788e

Please sign in to comment.