Skip to content

Commit 8e2e498

Browse files
committed
Auto merge of #1371 - Susurrus:mq_attr, r=gnzlbg
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
2 parents 4e9c49e + 0b34501 commit 8e2e498

File tree

6 files changed

+316
-97
lines changed

6 files changed

+316
-97
lines changed

src/fuchsia/mod.rs

Lines changed: 86 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,6 @@ s! {
366366
pub ai_next: *mut addrinfo,
367367
}
368368

369-
pub struct sockaddr_nl {
370-
pub nl_family: ::sa_family_t,
371-
nl_pad: ::c_ushort,
372-
pub nl_pid: u32,
373-
pub nl_groups: u32
374-
}
375-
376369
pub struct sockaddr_ll {
377370
pub sll_family: ::c_ushort,
378371
pub sll_protocol: ::c_ushort,
@@ -573,32 +566,6 @@ s! {
573566
__val: [::c_int; 2],
574567
}
575568

576-
// x32 compatibility
577-
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
578-
pub struct mq_attr {
579-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
580-
pub mq_flags: i64,
581-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
582-
pub mq_maxmsg: i64,
583-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
584-
pub mq_msgsize: i64,
585-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
586-
pub mq_curmsgs: i64,
587-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
588-
pad: [i64; 4],
589-
590-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
591-
pub mq_flags: ::c_long,
592-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
593-
pub mq_maxmsg: ::c_long,
594-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
595-
pub mq_msgsize: ::c_long,
596-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
597-
pub mq_curmsgs: ::c_long,
598-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
599-
pad: [::c_long; 4],
600-
}
601-
602569
pub struct cpu_set_t {
603570
#[cfg(all(target_pointer_width = "32",
604571
not(target_arch = "x86_64")))]
@@ -971,6 +938,39 @@ s_no_extra_traits! {
971938
pub d_type: ::c_uchar,
972939
pub d_name: [::c_char; 256],
973940
}
941+
942+
// x32 compatibility
943+
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
944+
pub struct mq_attr {
945+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
946+
pub mq_flags: i64,
947+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
948+
pub mq_maxmsg: i64,
949+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
950+
pub mq_msgsize: i64,
951+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
952+
pub mq_curmsgs: i64,
953+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
954+
pad: [i64; 4],
955+
956+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
957+
pub mq_flags: ::c_long,
958+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
959+
pub mq_maxmsg: ::c_long,
960+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
961+
pub mq_msgsize: ::c_long,
962+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
963+
pub mq_curmsgs: ::c_long,
964+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
965+
pad: [::c_long; 4],
966+
}
967+
968+
pub struct sockaddr_nl {
969+
pub nl_family: ::sa_family_t,
970+
nl_pad: ::c_ushort,
971+
pub nl_pid: u32,
972+
pub nl_groups: u32
973+
}
974974
}
975975

976976
cfg_if! {
@@ -1211,6 +1211,59 @@ cfg_if! {
12111211
self.d_name.hash(state);
12121212
}
12131213
}
1214+
1215+
impl PartialEq for mq_attr {
1216+
fn eq(&self, other: &mq_attr) -> bool {
1217+
self.mq_flags == other.mq_flags &&
1218+
self.mq_maxmsg == other.mq_maxmsg &&
1219+
self.mq_msgsize == other.mq_msgsize &&
1220+
self.mq_curmsgs == other.mq_curmsgs
1221+
}
1222+
}
1223+
impl Eq for mq_attr {}
1224+
impl ::fmt::Debug for mq_attr {
1225+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1226+
f.debug_struct("mq_attr")
1227+
.field("mq_flags", &self.mq_flags)
1228+
.field("mq_maxmsg", &self.mq_maxmsg)
1229+
.field("mq_msgsize", &self.mq_msgsize)
1230+
.field("mq_curmsgs", &self.mq_curmsgs)
1231+
.finish()
1232+
}
1233+
}
1234+
impl ::hash::Hash for mq_attr {
1235+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1236+
self.mq_flags.hash(state);
1237+
self.mq_maxmsg.hash(state);
1238+
self.mq_msgsize.hash(state);
1239+
self.mq_curmsgs.hash(state);
1240+
}
1241+
}
1242+
1243+
impl PartialEq for sockaddr_nl {
1244+
fn eq(&self, other: &sockaddr_nl) -> bool {
1245+
self.nl_family == other.nl_family &&
1246+
self.nl_pid == other.nl_pid &&
1247+
self.nl_groups == other.nl_groups
1248+
}
1249+
}
1250+
impl Eq for sockaddr_nl {}
1251+
impl ::fmt::Debug for sockaddr_nl {
1252+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1253+
f.debug_struct("sockaddr_nl")
1254+
.field("nl_family", &self.nl_family)
1255+
.field("nl_pid", &self.nl_pid)
1256+
.field("nl_groups", &self.nl_groups)
1257+
.finish()
1258+
}
1259+
}
1260+
impl ::hash::Hash for sockaddr_nl {
1261+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1262+
self.nl_family.hash(state);
1263+
self.nl_pid.hash(state);
1264+
self.nl_groups.hash(state);
1265+
}
1266+
}
12141267
}
12151268
}
12161269

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ s! {
4646
pub ip6: *mut ::in6_addr,
4747
}
4848

49-
pub struct mq_attr {
50-
pub mq_flags: ::c_long,
51-
pub mq_maxmsg: ::c_long,
52-
pub mq_msgsize: ::c_long,
53-
pub mq_curmsgs: ::c_long,
54-
__reserved: [::c_long; 4]
55-
}
56-
5749
pub struct sigevent {
5850
pub sigev_notify: ::c_int,
5951
pub sigev_signo: ::c_int,
@@ -151,6 +143,14 @@ s_no_extra_traits! {
151143
pub sdl_slen: ::c_uchar,
152144
pub sdl_data: [::c_char; 46],
153145
}
146+
147+
pub struct mq_attr {
148+
pub mq_flags: ::c_long,
149+
pub mq_maxmsg: ::c_long,
150+
pub mq_msgsize: ::c_long,
151+
pub mq_curmsgs: ::c_long,
152+
__reserved: [::c_long; 4]
153+
}
154154
}
155155

156156
cfg_if! {
@@ -246,6 +246,34 @@ cfg_if! {
246246
self.sdl_data.hash(state);
247247
}
248248
}
249+
250+
impl PartialEq for mq_attr {
251+
fn eq(&self, other: &mq_attr) -> bool {
252+
self.mq_flags == other.mq_flags &&
253+
self.mq_maxmsg == other.mq_maxmsg &&
254+
self.mq_msgsize == other.mq_msgsize &&
255+
self.mq_curmsgs == other.mq_curmsgs
256+
}
257+
}
258+
impl Eq for mq_attr {}
259+
impl ::fmt::Debug for mq_attr {
260+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
261+
f.debug_struct("mq_attr")
262+
.field("mq_flags", &self.mq_flags)
263+
.field("mq_maxmsg", &self.mq_maxmsg)
264+
.field("mq_msgsize", &self.mq_msgsize)
265+
.field("mq_curmsgs", &self.mq_curmsgs)
266+
.finish()
267+
}
268+
}
269+
impl ::hash::Hash for mq_attr {
270+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
271+
self.mq_flags.hash(state);
272+
self.mq_maxmsg.hash(state);
273+
self.mq_msgsize.hash(state);
274+
self.mq_curmsgs.hash(state);
275+
}
276+
}
249277
}
250278
}
251279

src/unix/notbsd/emscripten/mod.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,6 @@ s! {
139139
__val: [::c_int; 2],
140140
}
141141

142-
pub struct mq_attr {
143-
pub mq_flags: ::c_long,
144-
pub mq_maxmsg: ::c_long,
145-
pub mq_msgsize: ::c_long,
146-
pub mq_curmsgs: ::c_long,
147-
pad: [::c_long; 4]
148-
}
149-
150142
pub struct cpu_set_t {
151143
bits: [u32; 32],
152144
}
@@ -436,6 +428,14 @@ s_no_extra_traits! {
436428
pub mem_unit: ::c_uint,
437429
pub __reserved: [::c_char; 256],
438430
}
431+
432+
pub struct mq_attr {
433+
pub mq_flags: ::c_long,
434+
pub mq_maxmsg: ::c_long,
435+
pub mq_msgsize: ::c_long,
436+
pub mq_curmsgs: ::c_long,
437+
pad: [::c_long; 4]
438+
}
439439
}
440440

441441
cfg_if! {
@@ -571,6 +571,34 @@ cfg_if! {
571571
self.__reserved.hash(state);
572572
}
573573
}
574+
575+
impl PartialEq for mq_attr {
576+
fn eq(&self, other: &mq_attr) -> bool {
577+
self.mq_flags == other.mq_flags &&
578+
self.mq_maxmsg == other.mq_maxmsg &&
579+
self.mq_msgsize == other.mq_msgsize &&
580+
self.mq_curmsgs == other.mq_curmsgs
581+
}
582+
}
583+
impl Eq for mq_attr {}
584+
impl ::fmt::Debug for mq_attr {
585+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
586+
f.debug_struct("mq_attr")
587+
.field("mq_flags", &self.mq_flags)
588+
.field("mq_maxmsg", &self.mq_maxmsg)
589+
.field("mq_msgsize", &self.mq_msgsize)
590+
.field("mq_curmsgs", &self.mq_curmsgs)
591+
.finish()
592+
}
593+
}
594+
impl ::hash::Hash for mq_attr {
595+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
596+
self.mq_flags.hash(state);
597+
self.mq_maxmsg.hash(state);
598+
self.mq_msgsize.hash(state);
599+
self.mq_curmsgs.hash(state);
600+
}
601+
}
574602
}
575603
}
576604

src/unix/notbsd/linux/mod.rs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,6 @@ s! {
131131
__val: [::c_int; 2],
132132
}
133133

134-
// x32 compatibility
135-
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
136-
pub struct mq_attr {
137-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
138-
pub mq_flags: i64,
139-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
140-
pub mq_maxmsg: i64,
141-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
142-
pub mq_msgsize: i64,
143-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
144-
pub mq_curmsgs: i64,
145-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
146-
pad: [i64; 4],
147-
148-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
149-
pub mq_flags: ::c_long,
150-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
151-
pub mq_maxmsg: ::c_long,
152-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
153-
pub mq_msgsize: ::c_long,
154-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
155-
pub mq_curmsgs: ::c_long,
156-
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
157-
pad: [::c_long; 4],
158-
}
159-
160134
pub struct packet_mreq {
161135
pub mr_ifindex: ::c_int,
162136
pub mr_type: ::c_ushort,
@@ -532,6 +506,32 @@ s_no_extra_traits!{
532506
pub ivlen: u32,
533507
pub iv: [::c_uchar; 0],
534508
}
509+
510+
// x32 compatibility
511+
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
512+
pub struct mq_attr {
513+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
514+
pub mq_flags: i64,
515+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
516+
pub mq_maxmsg: i64,
517+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
518+
pub mq_msgsize: i64,
519+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
520+
pub mq_curmsgs: i64,
521+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
522+
pad: [i64; 4],
523+
524+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
525+
pub mq_flags: ::c_long,
526+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
527+
pub mq_maxmsg: ::c_long,
528+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
529+
pub mq_msgsize: ::c_long,
530+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
531+
pub mq_curmsgs: ::c_long,
532+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
533+
pad: [::c_long; 4],
534+
}
535535
}
536536

537537
cfg_if! {
@@ -752,6 +752,34 @@ cfg_if! {
752752
self.as_slice().hash(state);
753753
}
754754
}
755+
756+
impl PartialEq for mq_attr {
757+
fn eq(&self, other: &mq_attr) -> bool {
758+
self.mq_flags == other.mq_flags &&
759+
self.mq_maxmsg == other.mq_maxmsg &&
760+
self.mq_msgsize == other.mq_msgsize &&
761+
self.mq_curmsgs == other.mq_curmsgs
762+
}
763+
}
764+
impl Eq for mq_attr {}
765+
impl ::fmt::Debug for mq_attr {
766+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
767+
f.debug_struct("mq_attr")
768+
.field("mq_flags", &self.mq_flags)
769+
.field("mq_maxmsg", &self.mq_maxmsg)
770+
.field("mq_msgsize", &self.mq_msgsize)
771+
.field("mq_curmsgs", &self.mq_curmsgs)
772+
.finish()
773+
}
774+
}
775+
impl ::hash::Hash for mq_attr {
776+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
777+
self.mq_flags.hash(state);
778+
self.mq_maxmsg.hash(state);
779+
self.mq_msgsize.hash(state);
780+
self.mq_curmsgs.hash(state);
781+
}
782+
}
755783
}
756784
}
757785

0 commit comments

Comments
 (0)