Skip to content

Commit c5c79b2

Browse files
committed
Make sigval an union
1 parent b035574 commit c5c79b2

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
@@ -182,15 +182,6 @@ fn test_apple(target: &str) {
182182
[x86_64]: "crt_externs.h",
183183
}
184184

185-
cfg.skip_struct(move |ty| {
186-
match ty {
187-
// FIXME: actually a union
188-
"sigval" => true,
189-
190-
_ => false,
191-
}
192-
});
193-
194185
cfg.skip_const(move |name| {
195186
match name {
196187
// These OSX constants are removed in Sierra.
@@ -231,14 +222,6 @@ fn test_apple(target: &str) {
231222
}
232223
});
233224

234-
cfg.skip_field_type(move |struct_, field| {
235-
match (struct_, field) {
236-
// FIXME: actually a union
237-
("sigevent", "sigev_value") => true,
238-
_ => false,
239-
}
240-
});
241-
242225
cfg.volatile_item(|i| {
243226
use ctest::VolatileItemKind::*;
244227
match i {
@@ -363,15 +346,6 @@ fn test_openbsd(target: &str) {
363346
"sys/shm.h",
364347
}
365348

366-
cfg.skip_struct(move |ty| {
367-
match ty {
368-
// FIXME: actually a union
369-
"sigval" => true,
370-
371-
_ => false,
372-
}
373-
});
374-
375349
cfg.skip_const(move |name| {
376350
match name {
377351
// Removed in OpenBSD 6.0
@@ -741,8 +715,6 @@ fn test_solarish(target: &str) {
741715
return true;
742716
}
743717
match ty {
744-
// union, not a struct
745-
"sigval" => true,
746718
// a bunch of solaris-only fields
747719
"utmpx" if is_illumos => true,
748720
_ => false,
@@ -757,8 +729,6 @@ fn test_solarish(target: &str) {
757729
"sigaction" if field == "sa_sigaction" => true,
758730
// Missing in illumos
759731
"sigevent" if field == "ss_sp" => true,
760-
// Avoid sigval union issues
761-
"sigevent" if field == "sigev_value" => true,
762732
// const issues
763733
"sigevent" if field == "sigev_notify_attributes" => true,
764734

@@ -941,8 +911,6 @@ fn test_netbsd(target: &str) {
941911

942912
cfg.skip_struct(move |ty| {
943913
match ty {
944-
// This is actually a union, not a struct
945-
"sigval" => true,
946914
// These are tested as part of the linux_fcntl tests since there are
947915
// header conflicts when including them with all the other structs.
948916
"termios2" => true,
@@ -1012,8 +980,6 @@ fn test_netbsd(target: &str) {
1012980
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
1013981
// sighandler_t type is super weird
1014982
(struct_ == "sigaction" && field == "sa_sigaction") ||
1015-
// sigval is actually a union, but we pretend it's a struct
1016-
(struct_ == "sigevent" && field == "sigev_value") ||
1017983
// aio_buf is "volatile void*" and Rust doesn't understand volatile
1018984
(struct_ == "aiocb" && field == "aio_buf")
1019985
});
@@ -1153,9 +1119,6 @@ fn test_dragonflybsd(target: &str) {
11531119

11541120
cfg.skip_struct(move |ty| {
11551121
match ty {
1156-
// This is actually a union, not a struct
1157-
"sigval" => true,
1158-
11591122
// FIXME: These are tested as part of the linux_fcntl tests since
11601123
// there are header conflicts when including them with all the other
11611124
// structs.
@@ -1219,8 +1182,6 @@ fn test_dragonflybsd(target: &str) {
12191182
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
12201183
// sighandler_t type is super weird
12211184
(struct_ == "sigaction" && field == "sa_sigaction") ||
1222-
// sigval is actually a union, but we pretend it's a struct
1223-
(struct_ == "sigevent" && field == "sigev_value") ||
12241185
// aio_buf is "volatile void*" and Rust doesn't understand volatile
12251186
(struct_ == "aiocb" && field == "aio_buf")
12261187
});
@@ -1457,9 +1418,6 @@ fn test_android(target: &str) {
14571418

14581419
t if t.ends_with("_t") => t.to_string(),
14591420

1460-
// sigval is a struct in Rust, but a union in C:
1461-
"sigval" => format!("union sigval"),
1462-
14631421
// put `struct` in front of all structs:.
14641422
t if is_struct => format!("struct {}", t),
14651423

@@ -1554,9 +1512,7 @@ fn test_android(target: &str) {
15541512

15551513
cfg.skip_field_type(move |struct_, field| {
15561514
// This is a weird union, don't check the type.
1557-
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
1558-
// sigval is actually a union, but we pretend it's a struct
1559-
(struct_ == "sigevent" && field == "sigev_value")
1515+
struct_ == "ifaddrs" && field == "ifa_ifu"
15601516
});
15611517

15621518
cfg.skip_field(move |struct_, field| {
@@ -1697,9 +1653,6 @@ fn test_freebsd(target: &str) {
16971653

16981654
t if t.ends_with("_t") => t.to_string(),
16991655

1700-
// sigval is a struct in Rust, but a union in C:
1701-
"sigval" => format!("union sigval"),
1702-
17031656
// put `struct` in front of all structs:.
17041657
t if is_struct => format!("struct {}", t),
17051658

@@ -2039,10 +1992,6 @@ fn test_emscripten(target: &str) {
20391992

20401993
cfg.skip_struct(move |ty| {
20411994
match ty {
2042-
// This is actually a union, not a struct
2043-
// FIXME: is this necessary?
2044-
"sigval" => true,
2045-
20461995
// FIXME: It was removed in
20471996
// emscripten-core/emscripten@953e414
20481997
"pthread_mutexattr_t" => true,
@@ -2091,9 +2040,6 @@ fn test_emscripten(target: &str) {
20912040
// sighandler_t type is super weird
20922041
// FIXME: is this necessary?
20932042
(struct_ == "sigaction" && field == "sa_sigaction") ||
2094-
// sigval is actually a union, but we pretend it's a struct
2095-
// FIXME: is this necessary?
2096-
(struct_ == "sigevent" && field == "sigev_value") ||
20972043
// aio_buf is "volatile void*" and Rust doesn't understand volatile
20982044
// FIXME: is this necessary?
20992045
(struct_ == "aiocb" && field == "aio_buf")
@@ -2222,10 +2168,8 @@ fn test_vxworks(target: &str) {
22222168

22232169
// FIXME
22242170
cfg.skip_fn(move |name| match name {
2225-
// sigval
2226-
"sigqueue" | "_sigqueue"
22272171
// sighandler_t
2228-
| "signal"
2172+
"signal"
22292173
// not used in static linking by default
22302174
| "dlerror" => true,
22312175
_ => false,
@@ -2516,9 +2460,6 @@ fn test_linux(target: &str) {
25162460
// which is absent in glibc, has to be defined.
25172461
"__timeval" => true,
25182462

2519-
// FIXME: This is actually a union, not a struct
2520-
"sigval" => true,
2521-
25222463
// This type is tested in the `linux_termios.rs` file since there
25232464
// are header conflicts when including them with all the other
25242465
// structs.
@@ -2747,8 +2688,6 @@ fn test_linux(target: &str) {
27472688
(struct_ == "sigaction" && field == "sa_sigaction") ||
27482689
// __timeval type is a patch which doesn't exist in glibc
27492690
(struct_ == "utmpx" && field == "ut_tv") ||
2750-
// sigval is actually a union, but we pretend it's a struct
2751-
(struct_ == "sigevent" && field == "sigev_value") ||
27522691
// this one is an anonymous union
27532692
(struct_ == "ff_effect" && field == "u") ||
27542693
// `__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)