Skip to content

Commit

Permalink
Auto merge of #1371 - Susurrus:mq_attr, r=gnzlbg
Browse files Browse the repository at this point in the history
Manually implement extra traits for `mq_attr` and `sockaddr_nl`

Avoid including padding fields in extra trait implementations as these fields aren't guaranteed to be 0 or some other sensible value.

Closes #1302
  • Loading branch information
bors committed May 27, 2019
2 parents 4e9c49e + 0b34501 commit 8e2e498
Show file tree
Hide file tree
Showing 6 changed files with 316 additions and 97 deletions.
119 changes: 86 additions & 33 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,6 @@ s! {
pub ai_next: *mut addrinfo,
}

pub struct sockaddr_nl {
pub nl_family: ::sa_family_t,
nl_pad: ::c_ushort,
pub nl_pid: u32,
pub nl_groups: u32
}

pub struct sockaddr_ll {
pub sll_family: ::c_ushort,
pub sll_protocol: ::c_ushort,
Expand Down Expand Up @@ -573,32 +566,6 @@ s! {
__val: [::c_int; 2],
}

// x32 compatibility
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
pub struct mq_attr {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_flags: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_maxmsg: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_msgsize: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_curmsgs: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pad: [i64; 4],

#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_flags: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_maxmsg: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_msgsize: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_curmsgs: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pad: [::c_long; 4],
}

pub struct cpu_set_t {
#[cfg(all(target_pointer_width = "32",
not(target_arch = "x86_64")))]
Expand Down Expand Up @@ -971,6 +938,39 @@ s_no_extra_traits! {
pub d_type: ::c_uchar,
pub d_name: [::c_char; 256],
}

// x32 compatibility
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
pub struct mq_attr {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_flags: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_maxmsg: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_msgsize: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_curmsgs: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pad: [i64; 4],

#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_flags: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_maxmsg: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_msgsize: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_curmsgs: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pad: [::c_long; 4],
}

pub struct sockaddr_nl {
pub nl_family: ::sa_family_t,
nl_pad: ::c_ushort,
pub nl_pid: u32,
pub nl_groups: u32
}
}

cfg_if! {
Expand Down Expand Up @@ -1211,6 +1211,59 @@ cfg_if! {
self.d_name.hash(state);
}
}

impl PartialEq for mq_attr {
fn eq(&self, other: &mq_attr) -> bool {
self.mq_flags == other.mq_flags &&
self.mq_maxmsg == other.mq_maxmsg &&
self.mq_msgsize == other.mq_msgsize &&
self.mq_curmsgs == other.mq_curmsgs
}
}
impl Eq for mq_attr {}
impl ::fmt::Debug for mq_attr {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("mq_attr")
.field("mq_flags", &self.mq_flags)
.field("mq_maxmsg", &self.mq_maxmsg)
.field("mq_msgsize", &self.mq_msgsize)
.field("mq_curmsgs", &self.mq_curmsgs)
.finish()
}
}
impl ::hash::Hash for mq_attr {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.mq_flags.hash(state);
self.mq_maxmsg.hash(state);
self.mq_msgsize.hash(state);
self.mq_curmsgs.hash(state);
}
}

impl PartialEq for sockaddr_nl {
fn eq(&self, other: &sockaddr_nl) -> bool {
self.nl_family == other.nl_family &&
self.nl_pid == other.nl_pid &&
self.nl_groups == other.nl_groups
}
}
impl Eq for sockaddr_nl {}
impl ::fmt::Debug for sockaddr_nl {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sockaddr_nl")
.field("nl_family", &self.nl_family)
.field("nl_pid", &self.nl_pid)
.field("nl_groups", &self.nl_groups)
.finish()
}
}
impl ::hash::Hash for sockaddr_nl {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.nl_family.hash(state);
self.nl_pid.hash(state);
self.nl_groups.hash(state);
}
}
}
}

Expand Down
44 changes: 36 additions & 8 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ s! {
pub ip6: *mut ::in6_addr,
}

pub struct mq_attr {
pub mq_flags: ::c_long,
pub mq_maxmsg: ::c_long,
pub mq_msgsize: ::c_long,
pub mq_curmsgs: ::c_long,
__reserved: [::c_long; 4]
}

pub struct sigevent {
pub sigev_notify: ::c_int,
pub sigev_signo: ::c_int,
Expand Down Expand Up @@ -151,6 +143,14 @@ s_no_extra_traits! {
pub sdl_slen: ::c_uchar,
pub sdl_data: [::c_char; 46],
}

pub struct mq_attr {
pub mq_flags: ::c_long,
pub mq_maxmsg: ::c_long,
pub mq_msgsize: ::c_long,
pub mq_curmsgs: ::c_long,
__reserved: [::c_long; 4]
}
}

cfg_if! {
Expand Down Expand Up @@ -246,6 +246,34 @@ cfg_if! {
self.sdl_data.hash(state);
}
}

impl PartialEq for mq_attr {
fn eq(&self, other: &mq_attr) -> bool {
self.mq_flags == other.mq_flags &&
self.mq_maxmsg == other.mq_maxmsg &&
self.mq_msgsize == other.mq_msgsize &&
self.mq_curmsgs == other.mq_curmsgs
}
}
impl Eq for mq_attr {}
impl ::fmt::Debug for mq_attr {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("mq_attr")
.field("mq_flags", &self.mq_flags)
.field("mq_maxmsg", &self.mq_maxmsg)
.field("mq_msgsize", &self.mq_msgsize)
.field("mq_curmsgs", &self.mq_curmsgs)
.finish()
}
}
impl ::hash::Hash for mq_attr {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.mq_flags.hash(state);
self.mq_maxmsg.hash(state);
self.mq_msgsize.hash(state);
self.mq_curmsgs.hash(state);
}
}
}
}

Expand Down
44 changes: 36 additions & 8 deletions src/unix/notbsd/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,6 @@ s! {
__val: [::c_int; 2],
}

pub struct mq_attr {
pub mq_flags: ::c_long,
pub mq_maxmsg: ::c_long,
pub mq_msgsize: ::c_long,
pub mq_curmsgs: ::c_long,
pad: [::c_long; 4]
}

pub struct cpu_set_t {
bits: [u32; 32],
}
Expand Down Expand Up @@ -436,6 +428,14 @@ s_no_extra_traits! {
pub mem_unit: ::c_uint,
pub __reserved: [::c_char; 256],
}

pub struct mq_attr {
pub mq_flags: ::c_long,
pub mq_maxmsg: ::c_long,
pub mq_msgsize: ::c_long,
pub mq_curmsgs: ::c_long,
pad: [::c_long; 4]
}
}

cfg_if! {
Expand Down Expand Up @@ -571,6 +571,34 @@ cfg_if! {
self.__reserved.hash(state);
}
}

impl PartialEq for mq_attr {
fn eq(&self, other: &mq_attr) -> bool {
self.mq_flags == other.mq_flags &&
self.mq_maxmsg == other.mq_maxmsg &&
self.mq_msgsize == other.mq_msgsize &&
self.mq_curmsgs == other.mq_curmsgs
}
}
impl Eq for mq_attr {}
impl ::fmt::Debug for mq_attr {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("mq_attr")
.field("mq_flags", &self.mq_flags)
.field("mq_maxmsg", &self.mq_maxmsg)
.field("mq_msgsize", &self.mq_msgsize)
.field("mq_curmsgs", &self.mq_curmsgs)
.finish()
}
}
impl ::hash::Hash for mq_attr {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.mq_flags.hash(state);
self.mq_maxmsg.hash(state);
self.mq_msgsize.hash(state);
self.mq_curmsgs.hash(state);
}
}
}
}

Expand Down
80 changes: 54 additions & 26 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,6 @@ s! {
__val: [::c_int; 2],
}

// x32 compatibility
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
pub struct mq_attr {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_flags: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_maxmsg: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_msgsize: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_curmsgs: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pad: [i64; 4],

#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_flags: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_maxmsg: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_msgsize: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_curmsgs: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pad: [::c_long; 4],
}

pub struct packet_mreq {
pub mr_ifindex: ::c_int,
pub mr_type: ::c_ushort,
Expand Down Expand Up @@ -532,6 +506,32 @@ s_no_extra_traits!{
pub ivlen: u32,
pub iv: [::c_uchar; 0],
}

// x32 compatibility
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
pub struct mq_attr {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_flags: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_maxmsg: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_msgsize: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_curmsgs: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pad: [i64; 4],

#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_flags: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_maxmsg: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_msgsize: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_curmsgs: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pad: [::c_long; 4],
}
}

cfg_if! {
Expand Down Expand Up @@ -752,6 +752,34 @@ cfg_if! {
self.as_slice().hash(state);
}
}

impl PartialEq for mq_attr {
fn eq(&self, other: &mq_attr) -> bool {
self.mq_flags == other.mq_flags &&
self.mq_maxmsg == other.mq_maxmsg &&
self.mq_msgsize == other.mq_msgsize &&
self.mq_curmsgs == other.mq_curmsgs
}
}
impl Eq for mq_attr {}
impl ::fmt::Debug for mq_attr {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("mq_attr")
.field("mq_flags", &self.mq_flags)
.field("mq_maxmsg", &self.mq_maxmsg)
.field("mq_msgsize", &self.mq_msgsize)
.field("mq_curmsgs", &self.mq_curmsgs)
.finish()
}
}
impl ::hash::Hash for mq_attr {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.mq_flags.hash(state);
self.mq_maxmsg.hash(state);
self.mq_msgsize.hash(state);
self.mq_curmsgs.hash(state);
}
}
}
}

Expand Down
Loading

0 comments on commit 8e2e498

Please sign in to comment.