Skip to content

Commit 7d235af

Browse files
committed
Ignore padding for mq_attr
The `pad` or `__reserved` fields are not always 0 on some platforms, so when used in the `PartialEq` implementation being used, fails some comparisons. This commit manually implements the extra traits to correct this behavior.
1 parent 1059e0b commit 7d235af

File tree

5 files changed

+220
-76
lines changed

5 files changed

+220
-76
lines changed

src/fuchsia/mod.rs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -573,32 +573,6 @@ s! {
573573
__val: [::c_int; 2],
574574
}
575575

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-
602576
pub struct cpu_set_t {
603577
#[cfg(all(target_pointer_width = "32",
604578
not(target_arch = "x86_64")))]
@@ -971,6 +945,32 @@ s_no_extra_traits! {
971945
pub d_type: ::c_uchar,
972946
pub d_name: [::c_char; 256],
973947
}
948+
949+
// x32 compatibility
950+
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
951+
pub struct mq_attr {
952+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
953+
pub mq_flags: i64,
954+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
955+
pub mq_maxmsg: i64,
956+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
957+
pub mq_msgsize: i64,
958+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
959+
pub mq_curmsgs: i64,
960+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
961+
pad: [i64; 4],
962+
963+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
964+
pub mq_flags: ::c_long,
965+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
966+
pub mq_maxmsg: ::c_long,
967+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
968+
pub mq_msgsize: ::c_long,
969+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
970+
pub mq_curmsgs: ::c_long,
971+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
972+
pad: [::c_long; 4],
973+
}
974974
}
975975

976976
cfg_if! {
@@ -1211,6 +1211,34 @@ 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+
}
12141242
}
12151243
}
12161244

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

src/unix/uclibc/mod.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,6 @@ s! {
281281
__val: [::c_int; 2],
282282
}
283283

284-
pub struct mq_attr {
285-
pub mq_flags: ::c_long,
286-
pub mq_maxmsg: ::c_long,
287-
pub mq_msgsize: ::c_long,
288-
pub mq_curmsgs: ::c_long,
289-
pad: [::c_long; 4]
290-
}
291-
292284
pub struct cpu_set_t {
293285
#[cfg(target_pointer_width = "32")]
294286
bits: [u32; 32],
@@ -368,6 +360,46 @@ s_no_extra_traits! {
368360
pub d_type: ::c_uchar,
369361
pub d_name: [::c_char; 256],
370362
}
363+
364+
pub struct mq_attr {
365+
pub mq_flags: ::c_long,
366+
pub mq_maxmsg: ::c_long,
367+
pub mq_msgsize: ::c_long,
368+
pub mq_curmsgs: ::c_long,
369+
pad: [::c_long; 4]
370+
}
371+
}
372+
373+
cfg_if! {
374+
if #[cfg(feature = "extra_traits")] {
375+
impl PartialEq for mq_attr {
376+
fn eq(&self, other: &mq_attr) -> bool {
377+
self.mq_flags == other.mq_flags &&
378+
self.mq_maxmsg == other.mq_maxmsg &&
379+
self.mq_msgsize == other.mq_msgsize &&
380+
self.mq_curmsgs == other.mq_curmsgs
381+
}
382+
}
383+
impl Eq for mq_attr {}
384+
impl ::fmt::Debug for mq_attr {
385+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
386+
f.debug_struct("mq_attr")
387+
.field("mq_flags", &self.mq_flags)
388+
.field("mq_maxmsg", &self.mq_maxmsg)
389+
.field("mq_msgsize", &self.mq_msgsize)
390+
.field("mq_curmsgs", &self.mq_curmsgs)
391+
.finish()
392+
}
393+
}
394+
impl ::hash::Hash for mq_attr {
395+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
396+
self.mq_flags.hash(state);
397+
self.mq_maxmsg.hash(state);
398+
self.mq_msgsize.hash(state);
399+
self.mq_curmsgs.hash(state);
400+
}
401+
}
402+
}
371403
}
372404

373405
// intentionally not public, only used for fd_set

0 commit comments

Comments
 (0)