Skip to content

Commit db7918b

Browse files
committed
Make sigval an union
1 parent f07c693 commit db7918b

File tree

3 files changed

+56
-73
lines changed

3 files changed

+56
-73
lines changed

libc-test/build.rs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,6 @@ fn test_apple(target: &str) {
180180
[x86_64]: "crt_externs.h",
181181
}
182182

183-
cfg.skip_struct(move |ty| {
184-
match ty {
185-
// FIXME: actually a union
186-
"sigval" => true,
187-
188-
_ => false,
189-
}
190-
});
191-
192183
cfg.skip_const(move |name| {
193184
match name {
194185
// These OSX constants are removed in Sierra.
@@ -229,14 +220,6 @@ fn test_apple(target: &str) {
229220
}
230221
});
231222

232-
cfg.skip_field_type(move |struct_, field| {
233-
match (struct_, field) {
234-
// FIXME: actually a union
235-
("sigevent", "sigev_value") => true,
236-
_ => false,
237-
}
238-
});
239-
240223
cfg.volatile_item(|i| {
241224
use ctest::VolatileItemKind::*;
242225
match i {
@@ -361,15 +344,6 @@ fn test_openbsd(target: &str) {
361344
"sys/shm.h",
362345
}
363346

364-
cfg.skip_struct(move |ty| {
365-
match ty {
366-
// FIXME: actually a union
367-
"sigval" => true,
368-
369-
_ => false,
370-
}
371-
});
372-
373347
cfg.skip_const(move |name| {
374348
match name {
375349
// Removed in OpenBSD 6.0
@@ -739,8 +713,6 @@ fn test_solarish(target: &str) {
739713
return true;
740714
}
741715
match ty {
742-
// union, not a struct
743-
"sigval" => true,
744716
// a bunch of solaris-only fields
745717
"utmpx" if is_illumos => true,
746718
_ => false,
@@ -755,8 +727,6 @@ fn test_solarish(target: &str) {
755727
"sigaction" if field == "sa_sigaction" => true,
756728
// Missing in illumos
757729
"sigevent" if field == "ss_sp" => true,
758-
// Avoid sigval union issues
759-
"sigevent" if field == "sigev_value" => true,
760730
// const issues
761731
"sigevent" if field == "sigev_notify_attributes" => true,
762732

@@ -938,8 +908,6 @@ fn test_netbsd(target: &str) {
938908

939909
cfg.skip_struct(move |ty| {
940910
match ty {
941-
// This is actually a union, not a struct
942-
"sigval" => true,
943911
// These are tested as part of the linux_fcntl tests since there are
944912
// header conflicts when including them with all the other structs.
945913
"termios2" => true,
@@ -1009,8 +977,6 @@ fn test_netbsd(target: &str) {
1009977
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
1010978
// sighandler_t type is super weird
1011979
(struct_ == "sigaction" && field == "sa_sigaction") ||
1012-
// sigval is actually a union, but we pretend it's a struct
1013-
(struct_ == "sigevent" && field == "sigev_value") ||
1014980
// aio_buf is "volatile void*" and Rust doesn't understand volatile
1015981
(struct_ == "aiocb" && field == "aio_buf")
1016982
});
@@ -1149,9 +1115,6 @@ fn test_dragonflybsd(target: &str) {
11491115

11501116
cfg.skip_struct(move |ty| {
11511117
match ty {
1152-
// This is actually a union, not a struct
1153-
"sigval" => true,
1154-
11551118
// FIXME: These are tested as part of the linux_fcntl tests since
11561119
// there are header conflicts when including them with all the other
11571120
// structs.
@@ -1215,8 +1178,6 @@ fn test_dragonflybsd(target: &str) {
12151178
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
12161179
// sighandler_t type is super weird
12171180
(struct_ == "sigaction" && field == "sa_sigaction") ||
1218-
// sigval is actually a union, but we pretend it's a struct
1219-
(struct_ == "sigevent" && field == "sigev_value") ||
12201181
// aio_buf is "volatile void*" and Rust doesn't understand volatile
12211182
(struct_ == "aiocb" && field == "aio_buf")
12221183
});
@@ -1453,9 +1414,6 @@ fn test_android(target: &str) {
14531414

14541415
t if t.ends_with("_t") => t.to_string(),
14551416

1456-
// sigval is a struct in Rust, but a union in C:
1457-
"sigval" => format!("union sigval"),
1458-
14591417
// put `struct` in front of all structs:.
14601418
t if is_struct => format!("struct {}", t),
14611419

@@ -1550,9 +1508,7 @@ fn test_android(target: &str) {
15501508

15511509
cfg.skip_field_type(move |struct_, field| {
15521510
// This is a weird union, don't check the type.
1553-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
1554-
// sigval is actually a union, but we pretend it's a struct
1555-
(struct_ == "sigevent" && field == "sigev_value")
1511+
struct_ == "ifaddrs" && field == "ifa_ifu"
15561512
});
15571513

15581514
cfg.skip_field(move |struct_, field| {
@@ -1692,9 +1648,6 @@ fn test_freebsd(target: &str) {
16921648

16931649
t if t.ends_with("_t") => t.to_string(),
16941650

1695-
// sigval is a struct in Rust, but a union in C:
1696-
"sigval" => format!("union sigval"),
1697-
16981651
// put `struct` in front of all structs:.
16991652
t if is_struct => format!("struct {}", t),
17001653

@@ -2034,10 +1987,6 @@ fn test_emscripten(target: &str) {
20341987

20351988
cfg.skip_struct(move |ty| {
20361989
match ty {
2037-
// This is actually a union, not a struct
2038-
// FIXME: is this necessary?
2039-
"sigval" => true,
2040-
20411990
// FIXME: It was removed in
20421991
// emscripten-core/emscripten@953e414
20431992
"pthread_mutexattr_t" => true,
@@ -2086,9 +2035,6 @@ fn test_emscripten(target: &str) {
20862035
// sighandler_t type is super weird
20872036
// FIXME: is this necessary?
20882037
(struct_ == "sigaction" && field == "sa_sigaction") ||
2089-
// sigval is actually a union, but we pretend it's a struct
2090-
// FIXME: is this necessary?
2091-
(struct_ == "sigevent" && field == "sigev_value") ||
20922038
// aio_buf is "volatile void*" and Rust doesn't understand volatile
20932039
// FIXME: is this necessary?
20942040
(struct_ == "aiocb" && field == "aio_buf")
@@ -2217,10 +2163,8 @@ fn test_vxworks(target: &str) {
22172163

22182164
// FIXME
22192165
cfg.skip_fn(move |name| match name {
2220-
// sigval
2221-
"sigqueue" | "_sigqueue"
22222166
// sighandler_t
2223-
| "signal"
2167+
"signal"
22242168
// not used in static linking by default
22252169
| "dlerror" => true,
22262170
_ => false,
@@ -2506,9 +2450,6 @@ fn test_linux(target: &str) {
25062450
// which is absent in glibc, has to be defined.
25072451
"__timeval" => true,
25082452

2509-
// FIXME: This is actually a union, not a struct
2510-
"sigval" => true,
2511-
25122453
// This type is tested in the `linux_termios.rs` file since there
25132454
// are header conflicts when including them with all the other
25142455
// structs.
@@ -2700,8 +2641,6 @@ fn test_linux(target: &str) {
27002641
(struct_ == "sigaction" && field == "sa_sigaction") ||
27012642
// __timeval type is a patch which doesn't exist in glibc
27022643
(struct_ == "utmpx" && field == "ut_tv") ||
2703-
// sigval is actually a union, but we pretend it's a struct
2704-
(struct_ == "sigevent" && field == "sigev_value") ||
27052644
// this one is an anonymous union
27062645
(struct_ == "ff_effect" && field == "u") ||
27072646
// `__exit_status` type is a patch which is absent in musl

src/fuchsia/mod.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ s! {
251251
pub l_linger: ::c_int,
252252
}
253253

254-
pub struct sigval {
255-
// Actually a union of an int and a void*
256-
pub sival_ptr: *mut ::c_void
257-
}
258-
259254
// <sys/time.h>
260255
pub struct itimerval {
261256
pub it_interval: ::timeval,
@@ -974,6 +969,11 @@ s_no_extra_traits! {
974969
pub sigev_notify_attributes: *mut pthread_attr_t,
975970
pub __pad: [::c_char; 56 - 3 * 8 /* 8 == sizeof(long) */],
976971
}
972+
973+
pub union sigval {
974+
pub sival_int: ::int,
975+
pub sival_ptr: *mut ::c_void,
976+
}
977977
}
978978

979979
cfg_if! {
@@ -1301,6 +1301,25 @@ cfg_if! {
13011301
self.sigev_notify_attributes.hash(state);
13021302
}
13031303
}
1304+
1305+
impl PartialEq for sigval {
1306+
fn eq(&self, other: &sigval) -> bool {
1307+
unsafe { self.sival_ptr as usize == other.sival_ptr as usize }
1308+
}
1309+
}
1310+
impl Eq for sigval {}
1311+
impl ::fmt::Debug for sigval {
1312+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1313+
f.debug_struct("sigval")
1314+
.field("sival_ptr", unsafe { &(self.sival_ptr as usize) })
1315+
.finish()
1316+
}
1317+
}
1318+
impl ::hash::Hash for sigval {
1319+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1320+
unsafe { (self.sival_ptr as usize).hash(state) };
1321+
}
1322+
}
13041323
}
13051324
}
13061325

src/unix/mod.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,6 @@ s! {
162162
pub l_linger: ::c_int,
163163
}
164164

165-
pub struct sigval {
166-
// Actually a union of an int and a void*
167-
pub sival_ptr: *mut ::c_void
168-
}
169-
170165
// <sys/time.h>
171166
pub struct itimerval {
172167
pub it_interval: ::timeval,
@@ -195,6 +190,36 @@ s! {
195190
}
196191
}
197192

193+
s_no_extra_traits! {
194+
pub union sigval {
195+
pub sival_int: ::c_int,
196+
pub sival_ptr: *mut ::c_void,
197+
}
198+
}
199+
200+
cfg_if! {
201+
if #[cfg(feature = "extra_traits")] {
202+
impl PartialEq for sigval {
203+
fn eq(&self, other: &sigval) -> bool {
204+
unsafe { self.sival_ptr as usize == other.sival_ptr as usize }
205+
}
206+
}
207+
impl Eq for sigval {}
208+
impl ::fmt::Debug for sigval {
209+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
210+
f.debug_struct("sigval")
211+
.field("sival_ptr", unsafe { &(self.sival_ptr as usize) })
212+
.finish()
213+
}
214+
}
215+
impl ::hash::Hash for sigval {
216+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
217+
unsafe { (self.sival_ptr as usize).hash(state) };
218+
}
219+
}
220+
}
221+
}
222+
198223
pub const INT_MIN: c_int = -2147483648;
199224
pub const INT_MAX: c_int = 2147483647;
200225

0 commit comments

Comments
 (0)