Skip to content

Commit b4f42d5

Browse files
committed
use union for unions
1 parent 78a16cb commit b4f42d5

File tree

1 file changed

+76
-6
lines changed

1 file changed

+76
-6
lines changed

src/vxworks/mod.rs

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,9 @@ s! {
252252
}
253253

254254
// signal.h
255+
255256
pub struct sigaction {
256-
pub sa_u : ::size_t, // actually union of two function pointers
257+
pub sa_u : ::sa_u_t,
257258
pub sa_mask : ::sigset_t,
258259
pub sa_flags : ::c_int,
259260
}
@@ -269,7 +270,7 @@ s! {
269270
pub struct siginfo_t {
270271
pub si_signo : ::c_int,
271272
pub si_code : ::c_int,
272-
pub si_value : ::size_t, // actually union of int and void *
273+
pub si_value : ::sigval,
273274
pub si_errno : ::c_int,
274275
pub si_status: ::c_int,
275276
pub si_addr: *mut ::c_void,
@@ -414,6 +415,16 @@ s_no_extra_traits! {
414415
pub __ss_pad2 : [::c_char; _SS_PAD2SIZE],
415416
}
416417

418+
pub union sa_u_t {
419+
pub sa_handler : Option<unsafe extern "C" fn(::c_int) -> !>,
420+
pub sa_sigaction: Option<unsafe extern "C" fn(::c_int, *mut ::siginfo_t,
421+
*mut ::c_void) -> !>,
422+
}
423+
424+
pub union sigval {
425+
pub sival_int : ::c_int,
426+
pub sival_ptr : *mut ::c_void,
427+
}
417428
}
418429

419430
cfg_if! {
@@ -463,6 +474,67 @@ cfg_if! {
463474
.finish()
464475
}
465476
}
477+
478+
impl PartialEq for sa_u_t {
479+
fn eq(&self, other: &sa_u_t) -> bool {
480+
unsafe {
481+
let h1 = match self.sa_handler {
482+
Some(handler) => handler as usize,
483+
None => 0 as usize,
484+
};
485+
let h2 = match other.sa_handler {
486+
Some(handler) => handler as usize,
487+
None => 0 as usize,
488+
};
489+
h1 == h2
490+
}
491+
}
492+
}
493+
impl Eq for sa_u_t {}
494+
impl ::fmt::Debug for sa_u_t {
495+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
496+
unsafe {
497+
let h = match self.sa_handler {
498+
Some(handler) => handler as usize,
499+
None => 0 as usize,
500+
};
501+
502+
f.debug_struct("sa_u_t")
503+
.field("sa_handler", &h)
504+
.finish()
505+
}
506+
}
507+
}
508+
impl ::hash::Hash for sa_u_t {
509+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
510+
unsafe {
511+
let h = match self.sa_handler {
512+
Some(handler) => handler as usize,
513+
None => 0 as usize,
514+
};
515+
h.hash(state)
516+
}
517+
}
518+
}
519+
520+
impl PartialEq for sigval {
521+
fn eq(&self, other: &sigval) -> bool {
522+
unsafe { self.sival_ptr as usize == other.sival_ptr as usize }
523+
}
524+
}
525+
impl Eq for sigval {}
526+
impl ::fmt::Debug for sigval {
527+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
528+
f.debug_struct("sigval")
529+
.field("sival_ptr", unsafe { &(self.sival_ptr as usize) })
530+
.finish()
531+
}
532+
}
533+
impl ::hash::Hash for sigval {
534+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
535+
unsafe { (self.sival_ptr as usize).hash(state) };
536+
}
537+
}
466538
}
467539
}
468540

@@ -1976,16 +2048,14 @@ extern "C" {
19762048
pub fn sigqueue(
19772049
__pid: pid_t,
19782050
__signo: ::c_int,
1979-
__value: ::size_t, // Actual type is const union sigval value,
1980-
// which is a union of int and void *
2051+
__value: ::sigval,
19812052
) -> ::c_int;
19822053

19832054
// signal.h for user
19842055
pub fn _sigqueue(
19852056
rtpId: ::RTP_ID,
19862057
signo: ::c_int,
1987-
pValue: *mut ::size_t, // Actual type is const union * sigval value,
1988-
// which is a union of int and void *
2058+
pValue: *const ::sigval,
19892059
sigCode: ::c_int,
19902060
) -> ::c_int;
19912061

0 commit comments

Comments
 (0)