Skip to content

Commit 7c26591

Browse files
committed
Switch to manual trait impls for sigevent
sigevent structs on most platforms have padding or unused fields. Rather than display those in the Debug impl by deriving it, manually implement all extra_traits instead ignoring those fields.
1 parent 6985986 commit 7c26591

File tree

9 files changed

+369
-93
lines changed

9 files changed

+369
-93
lines changed

src/fuchsia/mod.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,6 @@ s! {
432432
pub int_n_sign_posn: ::c_char,
433433
}
434434

435-
pub struct sigevent {
436-
pub sigev_value: ::sigval,
437-
pub sigev_signo: ::c_int,
438-
pub sigev_notify: ::c_int,
439-
pub sigev_notify_function: fn(::sigval),
440-
pub sigev_notify_attributes: *mut pthread_attr_t,
441-
pub __pad: [::c_char; 56 - 3 * 8 /* 8 == sizeof(long) */],
442-
}
443-
444435
pub struct rlimit64 {
445436
pub rlim_cur: rlim64_t,
446437
pub rlim_max: rlim64_t,
@@ -962,6 +953,15 @@ s_no_extra_traits! {
962953
pub nl_pid: u32,
963954
pub nl_groups: u32
964955
}
956+
957+
pub struct sigevent {
958+
pub sigev_value: ::sigval,
959+
pub sigev_signo: ::c_int,
960+
pub sigev_notify: ::c_int,
961+
pub sigev_notify_function: fn(::sigval),
962+
pub sigev_notify_attributes: *mut pthread_attr_t,
963+
pub __pad: [::c_char; 56 - 3 * 8 /* 8 == sizeof(long) */],
964+
}
965965
}
966966

967967
cfg_if! {
@@ -1255,6 +1255,39 @@ cfg_if! {
12551255
self.nl_groups.hash(state);
12561256
}
12571257
}
1258+
1259+
impl PartialEq for sigevent {
1260+
fn eq(&self, other: &sigevent) -> bool {
1261+
self.sigev_value == other.sigev_value
1262+
&& self.sigev_signo == other.sigev_signo
1263+
&& self.sigev_notify == other.sigev_notify
1264+
&& self.sigev_notify_function == other.sigev_notify_function
1265+
&& self.sigev_notify_attributes
1266+
== other.sigev_notify_attributes
1267+
}
1268+
}
1269+
impl Eq for sigevent {}
1270+
impl ::fmt::Debug for sigevent {
1271+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1272+
f.debug_struct("sigevent")
1273+
.field("sigev_value", &self.sigev_value)
1274+
.field("sigev_signo", &self.sigev_signo)
1275+
.field("sigev_notify", &self.sigev_notify)
1276+
.field("sigev_notify_function", &self.sigev_notify_function)
1277+
.field("sigev_notify_attributes",
1278+
&self.sigev_notify_attributes)
1279+
.finish()
1280+
}
1281+
}
1282+
impl ::hash::Hash for sigevent {
1283+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1284+
self.sigev_value.hash(state);
1285+
self.sigev_signo.hash(state);
1286+
self.sigev_notify.hash(state);
1287+
self.sigev_notify_function.hash(state);
1288+
self.sigev_notify_attributes.hash(state);
1289+
}
1290+
}
12581291
}
12591292
}
12601293

src/unix/bsd/apple/mod.rs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,6 @@ s! {
287287
pub int_n_sign_posn: ::c_char,
288288
}
289289

290-
pub struct sigevent {
291-
pub sigev_notify: ::c_int,
292-
pub sigev_signo: ::c_int,
293-
pub sigev_value: ::sigval,
294-
__unused1: *mut ::c_void, //actually a function pointer
295-
pub sigev_notify_attributes: *mut ::pthread_attr_t
296-
}
297-
298290
pub struct proc_taskinfo {
299291
pub pti_virtual_size: u64,
300292
pub pti_resident_size: u64,
@@ -612,6 +604,14 @@ s_no_extra_traits!{
612604
pub ut_host: [::c_char; _UTX_HOSTSIZE],
613605
ut_pad: [u32; 16],
614606
}
607+
608+
pub struct sigevent {
609+
pub sigev_notify: ::c_int,
610+
pub sigev_signo: ::c_int,
611+
pub sigev_value: ::sigval,
612+
__unused1: *mut ::c_void, //actually a function pointer
613+
pub sigev_notify_attributes: *mut ::pthread_attr_t
614+
}
615615
}
616616

617617
cfg_if! {
@@ -1159,6 +1159,39 @@ cfg_if! {
11591159
self.ut_pad.hash(state);
11601160
}
11611161
}
1162+
1163+
impl PartialEq for sigevent {
1164+
fn eq(&self, other: &sigevent) -> bool {
1165+
self.sigev_notify == other.sigev_notify
1166+
&& self.sigev_signo == other.sigev_signo
1167+
&& self.sigev_value == other.sigev_value
1168+
&& self.sigev_notify_attributes
1169+
== other.sigev_notify_attributes
1170+
}
1171+
}
1172+
1173+
impl Eq for sigevent {}
1174+
1175+
impl ::fmt::Debug for sigevent {
1176+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1177+
f.debug_struct("sigevent")
1178+
.field("sigev_notify", &self.sigev_notify)
1179+
.field("sigev_signo", &self.sigev_signo)
1180+
.field("sigev_value", &self.sigev_value)
1181+
.field("sigev_notify_attributes",
1182+
&self.sigev_notify_attributes)
1183+
.finish()
1184+
}
1185+
}
1186+
1187+
impl ::hash::Hash for sigevent {
1188+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1189+
self.sigev_notify.hash(state);
1190+
self.sigev_signo.hash(state);
1191+
self.sigev_value.hash(state);
1192+
self.sigev_notify_attributes.hash(state);
1193+
}
1194+
}
11621195
}
11631196
}
11641197

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

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,6 @@ s! {
7070
pub mq_curmsgs: ::c_long,
7171
}
7272

73-
pub struct sigevent {
74-
pub sigev_notify: ::c_int,
75-
// The union is 8-byte in size, so it is aligned at a 8-byte offset.
76-
#[cfg(target_pointer_width = "64")]
77-
__unused1: ::c_int,
78-
pub sigev_signo: ::c_int, //actually a union
79-
// pad the union
80-
#[cfg(target_pointer_width = "64")]
81-
__unused2: ::c_int,
82-
pub sigev_value: ::sigval,
83-
__unused3: *mut ::c_void //actually a function pointer
84-
}
85-
8673
pub struct statvfs {
8774
pub f_bsize: ::c_ulong,
8875
pub f_frsize: ::c_ulong,
@@ -234,6 +221,20 @@ s_no_extra_traits! {
234221
pub f_asyncreads: ::c_long,
235222
pub f_mntfromname: [::c_char; 90],
236223
}
224+
225+
pub struct sigevent {
226+
pub sigev_notify: ::c_int,
227+
// The union is 8-byte in size, so it is aligned at a 8-byte offset.
228+
#[cfg(target_pointer_width = "64")]
229+
__unused1: ::c_int,
230+
pub sigev_signo: ::c_int, //actually a union
231+
// pad the union
232+
#[cfg(target_pointer_width = "64")]
233+
__unused2: ::c_int,
234+
pub sigev_value: ::sigval,
235+
__unused3: *mut ::c_void //actually a function pointer
236+
}
237+
237238
}
238239

239240
cfg_if! {
@@ -408,6 +409,31 @@ cfg_if! {
408409
self.f_mntfromname.hash(state);
409410
}
410411
}
412+
413+
impl PartialEq for sigevent {
414+
fn eq(&self, other: &sigevent) -> bool {
415+
self.sigev_notify == other.sigev_notify
416+
&& self.sigev_signo == other.sigev_signo
417+
&& self.sigev_value == other.sigev_value
418+
}
419+
}
420+
impl Eq for sigevent {}
421+
impl ::fmt::Debug for sigevent {
422+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
423+
f.debug_struct("sigevent")
424+
.field("sigev_notify", &self.sigev_notify)
425+
.field("sigev_signo", &self.sigev_signo)
426+
.field("sigev_value", &self.sigev_value)
427+
.finish()
428+
}
429+
}
430+
impl ::hash::Hash for sigevent {
431+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
432+
self.sigev_notify.hash(state);
433+
self.sigev_signo.hash(state);
434+
self.sigev_value.hash(state);
435+
}
436+
}
411437
}
412438
}
413439

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

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

49-
pub struct sigevent {
50-
pub sigev_notify: ::c_int,
51-
pub sigev_signo: ::c_int,
52-
pub sigev_value: ::sigval,
53-
//The rest of the structure is actually a union. We expose only
54-
//sigev_notify_thread_id because it's the most useful union member.
55-
pub sigev_notify_thread_id: ::lwpid_t,
56-
#[cfg(target_pointer_width = "64")]
57-
__unused1: ::c_int,
58-
__unused2: [::c_long; 7]
59-
}
60-
6149
pub struct statvfs {
6250
pub f_bavail: ::fsblkcnt_t,
6351
pub f_bfree: ::fsblkcnt_t,
@@ -151,6 +139,18 @@ s_no_extra_traits! {
151139
pub mq_curmsgs: ::c_long,
152140
__reserved: [::c_long; 4]
153141
}
142+
143+
pub struct sigevent {
144+
pub sigev_notify: ::c_int,
145+
pub sigev_signo: ::c_int,
146+
pub sigev_value: ::sigval,
147+
//The rest of the structure is actually a union. We expose only
148+
//sigev_notify_thread_id because it's the most useful union member.
149+
pub sigev_notify_thread_id: ::lwpid_t,
150+
#[cfg(target_pointer_width = "64")]
151+
__unused1: ::c_int,
152+
__unused2: [::c_long; 7]
153+
}
154154
}
155155

156156
cfg_if! {
@@ -274,6 +274,36 @@ cfg_if! {
274274
self.mq_curmsgs.hash(state);
275275
}
276276
}
277+
278+
impl PartialEq for sigevent {
279+
fn eq(&self, other: &sigevent) -> bool {
280+
self.sigev_notify == other.sigev_notify
281+
&& self.sigev_signo == other.sigev_signo
282+
&& self.sigev_value == other.sigev_value
283+
&& self.sigev_notify_thread_id
284+
== other.sigev_notify_thread_id
285+
}
286+
}
287+
impl Eq for sigevent {}
288+
impl ::fmt::Debug for sigevent {
289+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
290+
f.debug_struct("sigevent")
291+
.field("sigev_notify", &self.sigev_notify)
292+
.field("sigev_signo", &self.sigev_signo)
293+
.field("sigev_value", &self.sigev_value)
294+
.field("sigev_notify_thread_id",
295+
&self.sigev_notify_thread_id)
296+
.finish()
297+
}
298+
}
299+
impl ::hash::Hash for sigevent {
300+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
301+
self.sigev_notify.hash(state);
302+
self.sigev_signo.hash(state);
303+
self.sigev_value.hash(state);
304+
self.sigev_notify_thread_id.hash(state);
305+
}
306+
}
277307
}
278308
}
279309

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ s! {
4646
pub mq_curmsgs: ::c_long,
4747
}
4848

49-
pub struct sigevent {
50-
pub sigev_notify: ::c_int,
51-
pub sigev_signo: ::c_int,
52-
pub sigev_value: ::sigval,
53-
__unused1: *mut ::c_void, //actually a function pointer
54-
pub sigev_notify_attributes: *mut ::c_void
55-
}
56-
5749
pub struct sigset_t {
5850
__bits: [u32; 4],
5951
}
@@ -356,6 +348,14 @@ s_no_extra_traits! {
356348
__ss_pad2: i64,
357349
__ss_pad3: [u8; 112],
358350
}
351+
352+
pub struct sigevent {
353+
pub sigev_notify: ::c_int,
354+
pub sigev_signo: ::c_int,
355+
pub sigev_value: ::sigval,
356+
__unused1: *mut ::c_void, //actually a function pointer
357+
pub sigev_notify_attributes: *mut ::c_void
358+
}
359359
}
360360

361361
cfg_if! {
@@ -658,6 +658,36 @@ cfg_if! {
658658
self.__ss_pad3.hash(state);
659659
}
660660
}
661+
662+
impl PartialEq for sigevent {
663+
fn eq(&self, other: &sigevent) -> bool {
664+
self.sigev_notify == other.sigev_notify
665+
&& self.sigev_signo == other.sigev_signo
666+
&& self.sigev_value == other.sigev_value
667+
&& self.sigev_notify_attributes
668+
== other.sigev_notify_attributes
669+
}
670+
}
671+
impl Eq for sigevent {}
672+
impl ::fmt::Debug for sigevent {
673+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
674+
f.debug_struct("sigevent")
675+
.field("sigev_notify", &self.sigev_notify)
676+
.field("sigev_signo", &self.sigev_signo)
677+
.field("sigev_value", &self.sigev_value)
678+
.field("sigev_notify_attributes",
679+
&self.sigev_notify_attributes)
680+
.finish()
681+
}
682+
}
683+
impl ::hash::Hash for sigevent {
684+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
685+
self.sigev_notify.hash(state);
686+
self.sigev_signo.hash(state);
687+
self.sigev_value.hash(state);
688+
self.sigev_notify_attributes.hash(state);
689+
}
690+
}
661691
}
662692
}
663693

0 commit comments

Comments
 (0)