Skip to content

Commit e1bb80e

Browse files
bors[bot]pusateri
andcommitted
Merge #993
993: Don't reference packed structs. r=asomers a=pusateri Fixes #992. Don't merge this yet. I have more testing to do. I just am pushing it up for others. Co-authored-by: Tom Pusateri <[email protected]>
2 parents f404d9d + d139551 commit e1bb80e

File tree

7 files changed

+45
-12
lines changed

7 files changed

+45
-12
lines changed

src/sys/socket/addr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ impl Eq for Ipv4Addr {
497497

498498
impl hash::Hash for Ipv4Addr {
499499
fn hash<H: hash::Hasher>(&self, s: &mut H) {
500-
self.0.s_addr.hash(s)
500+
let saddr = self.0.s_addr;
501+
saddr.hash(s)
501502
}
502503
}
503504

src/sys/socket/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,13 @@ impl Eq for IpMembershipRequest {}
258258

259259
impl fmt::Debug for IpMembershipRequest {
260260
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
261+
let mref = &self.0.imr_multiaddr;
262+
let maddr = mref.s_addr;
263+
let iref = &self.0.imr_interface;
264+
let ifaddr = iref.s_addr;
261265
f.debug_struct("IpMembershipRequest")
262-
.field("imr_multiaddr", &self.0.imr_multiaddr.s_addr)
263-
.field("imr_interface", &self.0.imr_interface.s_addr)
266+
.field("imr_multiaddr", &maddr)
267+
.field("imr_interface", &ifaddr)
264268
.finish()
265269
}
266270
}

test/sys/test_socket.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ pub fn test_inetv4_addr_to_sock_addr() {
1616
InetAddr::V4(addr) => {
1717
let ip: u32 = 0x7f00_0001;
1818
let port: u16 = 3000;
19+
let saddr = addr.sin_addr.s_addr;
1920

20-
assert_eq!(addr.sin_addr.s_addr, ip.to_be());
21+
assert_eq!(saddr, ip.to_be());
2122
assert_eq!(addr.sin_port, port.to_be());
2223
}
2324
_ => panic!("nope"),

test/test_mq.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::str;
55

66
use nix::errno::Errno::*;
77
use nix::Error::Sys;
8-
use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive, mq_getattr, mq_setattr, mq_unlink, mq_set_nonblock, mq_remove_nonblock};
8+
use nix::mqueue::{mq_open, mq_close, mq_send, mq_receive};
99
use nix::mqueue::{MqAttr, MQ_OFlag};
1010
use nix::sys::stat::Mode;
1111

@@ -40,7 +40,9 @@ fn test_mq_send_and_receive() {
4040

4141

4242
#[test]
43+
#[cfg(not(any(target_os = "netbsd")))]
4344
fn test_mq_getattr() {
45+
use nix::mqueue::mq_getattr;
4446
const MSG_SIZE: c_long = 32;
4547
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
4648
let mq_name = &CString::new(b"/attr_test_get_attr".as_ref()).unwrap();
@@ -60,8 +62,10 @@ fn test_mq_getattr() {
6062

6163
// FIXME: Fix failures for mips in QEMU
6264
#[test]
65+
#[cfg(not(any(target_os = "netbsd")))]
6366
#[cfg_attr(any(target_arch = "mips", target_arch = "mips64"), ignore)]
6467
fn test_mq_setattr() {
68+
use nix::mqueue::{mq_getattr, mq_setattr};
6569
const MSG_SIZE: c_long = 32;
6670
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
6771
let mq_name = &CString::new(b"/attr_test_get_attr".as_ref()).unwrap();
@@ -95,8 +99,10 @@ fn test_mq_setattr() {
9599

96100
// FIXME: Fix failures for mips in QEMU
97101
#[test]
102+
#[cfg(not(any(target_os = "netbsd")))]
98103
#[cfg_attr(any(target_arch = "mips", target_arch = "mips64"), ignore)]
99104
fn test_mq_set_nonblocking() {
105+
use nix::mqueue::{mq_getattr, mq_set_nonblock, mq_remove_nonblock};
100106
const MSG_SIZE: c_long = 32;
101107
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
102108
let mq_name = &CString::new(b"/attr_test_get_attr".as_ref()).unwrap();
@@ -118,7 +124,9 @@ fn test_mq_set_nonblocking() {
118124
}
119125

120126
#[test]
127+
#[cfg(not(any(target_os = "netbsd")))]
121128
fn test_mq_unlink() {
129+
use nix::mqueue::mq_unlink;
122130
const MSG_SIZE: c_long = 32;
123131
let initial_attr = MqAttr::new(0, 10, MSG_SIZE, 0);
124132
let mq_name_opened = &CString::new(b"/mq_unlink_test".as_ref()).unwrap();

test/test_poll.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use nix::poll::{EventFlags, poll, PollFd};
2-
use nix::sys::signal::SigSet;
3-
use nix::sys::time::{TimeSpec, TimeValLike};
42
use nix::unistd::{write, pipe, close};
53

64
#[test]
@@ -49,6 +47,9 @@ fn test_poll_debug() {
4947
#[test]
5048
fn test_ppoll() {
5149
use nix::poll::ppoll;
50+
use nix::sys::signal::SigSet;
51+
use nix::sys::time::{TimeSpec, TimeValLike};
52+
5253
let timeout = TimeSpec::milliseconds(1);
5354
let (r, w) = pipe().unwrap();
5455
let mut fds = [PollFd::new(r, EventFlags::POLLIN)];

test/test_stat.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,35 @@ use std::os::unix::fs::symlink;
33
use std::os::unix::prelude::AsRawFd;
44
use std::time::{Duration, UNIX_EPOCH};
55

6+
#[cfg(not(any(target_os = "netbsd")))]
67
use libc::{S_IFMT, S_IFLNK};
78

89
use nix::fcntl;
9-
use nix::sys::stat::{self, fchmod, fchmodat, fstat, futimens, lstat, lutimes, stat, utimes, utimensat};
10-
use nix::sys::stat::{FileStat, Mode, FchmodatFlags, UtimensatFlags};
10+
use nix::sys::stat::{self, fchmod, fchmodat, futimens, lutimes, stat, utimes, utimensat};
11+
use nix::sys::stat::{Mode, FchmodatFlags, UtimensatFlags};
12+
13+
#[cfg(not(any(target_os = "netbsd")))]
14+
use nix::sys::stat::FileStat;
15+
1116
use nix::sys::time::{TimeSpec, TimeVal, TimeValLike};
1217
use nix::unistd::chdir;
18+
19+
#[cfg(not(any(target_os = "netbsd")))]
1320
use nix::Result;
1421
use tempfile;
1522

1623
#[allow(unused_comparisons)]
1724
// uid and gid are signed on Windows, but not on other platforms. This function
1825
// allows warning free compiles on all platforms, and can be removed when
1926
// expression-level #[allow] is available.
27+
#[cfg(not(any(target_os = "netbsd")))]
2028
fn valid_uid_gid(stat: FileStat) -> bool {
2129
// uid could be 0 for the `root` user. This quite possible when
2230
// the tests are being run on a rooted Android device.
2331
stat.st_uid >= 0 && stat.st_gid >= 0
2432
}
2533

34+
#[cfg(not(any(target_os = "netbsd")))]
2635
fn assert_stat_results(stat_result: Result<FileStat>) {
2736
let stats = stat_result.expect("stat call failed");
2837
assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
@@ -35,6 +44,7 @@ fn assert_stat_results(stat_result: Result<FileStat>) {
3544
assert!(stats.st_blocks <= 16); // Up to 16 blocks can be allocated for a blank file
3645
}
3746

47+
#[cfg(not(any(target_os = "netbsd")))]
3848
fn assert_lstat_results(stat_result: Result<FileStat>) {
3949
let stats = stat_result.expect("stat call failed");
4050
assert!(stats.st_dev > 0); // must be positive integer, exact number machine dependent
@@ -57,7 +67,10 @@ fn assert_lstat_results(stat_result: Result<FileStat>) {
5767
}
5868

5969
#[test]
70+
#[cfg(not(any(target_os = "netbsd")))]
6071
fn test_stat_and_fstat() {
72+
use nix::sys::stat::fstat;
73+
6174
let tempdir = tempfile::tempdir().unwrap();
6275
let filename = tempdir.path().join("foo.txt");
6376
let file = File::create(&filename).unwrap();
@@ -70,6 +83,7 @@ fn test_stat_and_fstat() {
7083
}
7184

7285
#[test]
86+
#[cfg(not(any(target_os = "netbsd")))]
7387
fn test_fstatat() {
7488
let tempdir = tempfile::tempdir().unwrap();
7589
let filename = tempdir.path().join("foo.txt");
@@ -85,7 +99,10 @@ fn test_fstatat() {
8599
}
86100

87101
#[test]
102+
#[cfg(not(any(target_os = "netbsd")))]
88103
fn test_stat_fstat_lstat() {
104+
use nix::sys::stat::{fstat, lstat};
105+
89106
let tempdir = tempfile::tempdir().unwrap();
90107
let filename = tempdir.path().join("bar.txt");
91108
let linkname = tempdir.path().join("barlink");

test/test_unistd.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use tempfile::{self, tempfile};
1313
use libc::{self, _exit, off_t};
1414

1515
#[test]
16+
#[cfg(not(any(target_os = "netbsd")))]
1617
fn test_fork_and_waitpid() {
1718
let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test");
1819

@@ -230,15 +231,15 @@ cfg_if!{
230231
execve_test_factory!(test_fexecve, fexecve, File::open("/system/bin/sh").unwrap().into_raw_fd());
231232
} else if #[cfg(any(target_os = "freebsd",
232233
target_os = "linux",
233-
target_os = "netbsd",
234234
target_os = "openbsd"))] {
235235
execve_test_factory!(test_execve, execve, &CString::new("/bin/sh").unwrap());
236236
execve_test_factory!(test_fexecve, fexecve, File::open("/bin/sh").unwrap().into_raw_fd());
237237
} else if #[cfg(any(target_os = "dragonfly",
238238
target_os = "ios",
239-
target_os = "macos"))] {
239+
target_os = "macos",
240+
target_os = "netbsd"))] {
240241
execve_test_factory!(test_execve, execve, &CString::new("/bin/sh").unwrap());
241-
// No fexecve() on macos/ios and DragonFly.
242+
// No fexecve() on DragonFly, ios, macos, and NetBSD.
242243
}
243244
}
244245

0 commit comments

Comments
 (0)