diff options
author | Baoshan Pang <baoshan.pang@windriver.com> | 2019-09-23 10:59:16 -0700 |
---|---|---|
committer | Baoshan Pang <baoshan.pang@windriver.com> | 2019-09-23 17:06:17 -0700 |
commit | b4f42d540114b88e2ac36ecf48e48a1bba062281 (patch) | |
tree | 65623a76de48814c9e28b5468b6e3f43e68a5e4e | |
parent | 78a16cbaab8cbd27e1c5e09b23a38b8ee8cba084 (diff) | |
download | rust-libc-b4f42d540114b88e2ac36ecf48e48a1bba062281.tar.gz |
use union for unions
-rwxr-xr-x | src/vxworks/mod.rs | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index 3f9930b0ba..9307f36131 100755 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -252,8 +252,9 @@ s! { } // signal.h + pub struct sigaction { - pub sa_u : ::size_t, // actually union of two function pointers + pub sa_u : ::sa_u_t, pub sa_mask : ::sigset_t, pub sa_flags : ::c_int, } @@ -269,7 +270,7 @@ s! { pub struct siginfo_t { pub si_signo : ::c_int, pub si_code : ::c_int, - pub si_value : ::size_t, // actually union of int and void * + pub si_value : ::sigval, pub si_errno : ::c_int, pub si_status: ::c_int, pub si_addr: *mut ::c_void, @@ -414,6 +415,16 @@ s_no_extra_traits! { pub __ss_pad2 : [::c_char; _SS_PAD2SIZE], } + pub union sa_u_t { + pub sa_handler : Option<unsafe extern "C" fn(::c_int) -> !>, + pub sa_sigaction: Option<unsafe extern "C" fn(::c_int, *mut ::siginfo_t, + *mut ::c_void) -> !>, + } + + pub union sigval { + pub sival_int : ::c_int, + pub sival_ptr : *mut ::c_void, + } } cfg_if! { @@ -463,6 +474,67 @@ cfg_if! { .finish() } } + + impl PartialEq for sa_u_t { + fn eq(&self, other: &sa_u_t) -> bool { + unsafe { + let h1 = match self.sa_handler { + Some(handler) => handler as usize, + None => 0 as usize, + }; + let h2 = match other.sa_handler { + Some(handler) => handler as usize, + None => 0 as usize, + }; + h1 == h2 + } + } + } + impl Eq for sa_u_t {} + impl ::fmt::Debug for sa_u_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + unsafe { + let h = match self.sa_handler { + Some(handler) => handler as usize, + None => 0 as usize, + }; + + f.debug_struct("sa_u_t") + .field("sa_handler", &h) + .finish() + } + } + } + impl ::hash::Hash for sa_u_t { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + unsafe { + let h = match self.sa_handler { + Some(handler) => handler as usize, + None => 0 as usize, + }; + h.hash(state) + } + } + } + + impl PartialEq for sigval { + fn eq(&self, other: &sigval) -> bool { + unsafe { self.sival_ptr as usize == other.sival_ptr as usize } + } + } + impl Eq for sigval {} + impl ::fmt::Debug for sigval { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sigval") + .field("sival_ptr", unsafe { &(self.sival_ptr as usize) }) + .finish() + } + } + impl ::hash::Hash for sigval { + fn hash<H: ::hash::Hasher>(&self, state: &mut H) { + unsafe { (self.sival_ptr as usize).hash(state) }; + } + } } } @@ -1976,16 +2048,14 @@ extern "C" { pub fn sigqueue( __pid: pid_t, __signo: ::c_int, - __value: ::size_t, // Actual type is const union sigval value, - // which is a union of int and void * + __value: ::sigval, ) -> ::c_int; // signal.h for user pub fn _sigqueue( rtpId: ::RTP_ID, signo: ::c_int, - pValue: *mut ::size_t, // Actual type is const union * sigval value, - // which is a union of int and void * + pValue: *const ::sigval, sigCode: ::c_int, ) -> ::c_int; |