Skip to content

Commit 49f7b41

Browse files
authored
Merge pull request #15 from Wind-River/union
use union for unions
2 parents 78a16cb + d751f23 commit 49f7b41

File tree

1 file changed

+64
-6
lines changed

1 file changed

+64
-6
lines changed

src/vxworks/mod.rs

Lines changed: 64 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 : extern "C" fn(::c_int) -> !,
420+
pub sa_sigaction: 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,46 @@ 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 { self.sa_handler == other.sa_handler }
481+
}
482+
}
483+
impl Eq for sa_u_t {}
484+
impl ::fmt::Debug for sa_u_t {
485+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
486+
f.debug_struct("sa_u_t")
487+
.field("sa_handler", unsafe { &self.sa_handler })
488+
.field("sa_sigaction", unsafe { &self.sa_sigaction })
489+
.finish()
490+
}
491+
}
492+
impl ::hash::Hash for sa_u_t {
493+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
494+
unsafe { self.sa_handler.hash(state) };
495+
}
496+
}
497+
498+
impl PartialEq for sigval {
499+
fn eq(&self, other: &sigval) -> bool {
500+
unsafe { self.sival_ptr == other.sival_ptr }
501+
}
502+
}
503+
impl Eq for sigval {}
504+
impl ::fmt::Debug for sigval {
505+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
506+
f.debug_struct("sigval")
507+
.field("sival_int", unsafe { &self.sival_int})
508+
.field("sival_ptr", unsafe { &self.sival_ptr })
509+
.finish()
510+
}
511+
}
512+
impl ::hash::Hash for sigval {
513+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
514+
unsafe { self.sival_ptr.hash(state) };
515+
}
516+
}
466517
}
467518
}
468519

@@ -1976,16 +2027,14 @@ extern "C" {
19762027
pub fn sigqueue(
19772028
__pid: pid_t,
19782029
__signo: ::c_int,
1979-
__value: ::size_t, // Actual type is const union sigval value,
1980-
// which is a union of int and void *
2030+
__value: ::sigval,
19812031
) -> ::c_int;
19822032

19832033
// signal.h for user
19842034
pub fn _sigqueue(
19852035
rtpId: ::RTP_ID,
19862036
signo: ::c_int,
1987-
pValue: *mut ::size_t, // Actual type is const union * sigval value,
1988-
// which is a union of int and void *
2037+
pValue: *const ::sigval,
19892038
sigCode: ::c_int,
19902039
) -> ::c_int;
19912040

@@ -2001,6 +2050,15 @@ extern "C" {
20012050

20022051
// rtpLibCommon.h
20032052
pub fn rtpInfoGet(rtpId: ::RTP_ID, rtpStruct: *mut ::RTP_DESC) -> ::c_int;
2053+
pub fn rtpSpawn(
2054+
pubrtpFileName: *const ::c_char,
2055+
argv: *const *const ::c_char,
2056+
envp: *const *const ::c_char,
2057+
priority: ::c_int,
2058+
uStackSize: ::size_t,
2059+
options: ::c_int,
2060+
taskOptions: ::c_int,
2061+
) -> RTP_ID;
20042062

20052063
// ioLib.h
20062064
pub fn _realpath(

0 commit comments

Comments
 (0)