Skip to content

Commit 434d034

Browse files
committed
Make sigval an union
1 parent 8e6f36c commit 434d034

File tree

3 files changed

+44
-97
lines changed

3 files changed

+44
-97
lines changed

libc-test/build.rs

Lines changed: 4 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,6 @@ fn test_apple(target: &str) {
331331
return true;
332332
}
333333
match ty {
334-
// FIXME(union): actually a union
335-
"sigval" => true,
336-
337334
// FIXME(macos): The size is changed in recent macOSes.
338335
"malloc_zone_t" => true,
339336
// it is a moving target, changing through versions
@@ -429,14 +426,6 @@ fn test_apple(target: &str) {
429426
}
430427
});
431428

432-
cfg.skip_field_type(move |struct_, field| {
433-
match (struct_, field) {
434-
// FIXME(union): actually a union
435-
("sigevent", "sigev_value") => true,
436-
_ => false,
437-
}
438-
});
439-
440429
cfg.volatile_item(|i| {
441430
use ctest::VolatileItemKind::*;
442431
match i {
@@ -576,23 +565,8 @@ fn test_openbsd(target: &str) {
576565
"sys/param.h",
577566
}
578567

579-
cfg.skip_struct(move |ty| {
580-
if ty.starts_with("__c_anonymous_") {
581-
return true;
582-
}
583-
match ty {
584-
// FIXME(union): actually a union
585-
"sigval" => true,
586-
587-
_ => false,
588-
}
589-
});
590-
591568
cfg.skip_const(move |name| {
592569
match name {
593-
// Removed in OpenBSD 7.7
594-
"ATF_COM" | "ATF_PERM" | "ATF_PUBL" | "ATF_USETRAILERS" => true,
595-
596570
// Removed in OpenBSD 7.8
597571
"CTL_FS" | "SO_NETPROC" => true,
598572

@@ -720,9 +694,6 @@ fn test_cygwin(target: &str) {
720694

721695
t if t.ends_with("_t") => t.to_string(),
722696

723-
// sigval is a struct in Rust, but a union in C:
724-
"sigval" => "union sigval".to_string(),
725-
726697
// put `struct` in front of all structs:.
727698
t if is_struct => format!("struct {t}"),
728699

@@ -1174,8 +1145,6 @@ fn test_solarish(target: &str) {
11741145
return true;
11751146
}
11761147
match ty {
1177-
// union, not a struct
1178-
"sigval" => true,
11791148
// a bunch of solaris-only fields
11801149
"utmpx" if is_illumos => true,
11811150
_ => false,
@@ -1195,8 +1164,6 @@ fn test_solarish(target: &str) {
11951164
"sigaction" if field == "sa_sigaction" => true,
11961165
// Missing in illumos
11971166
"sigevent" if field == "ss_sp" => true,
1198-
// Avoid sigval union issues
1199-
"sigevent" if field == "sigev_value" => true,
12001167
// const issues
12011168
"sigevent" if field == "sigev_notify_attributes" => true,
12021169

@@ -1423,8 +1390,6 @@ fn test_netbsd(target: &str) {
14231390

14241391
cfg.skip_struct(move |ty| {
14251392
match ty {
1426-
// This is actually a union, not a struct
1427-
"sigval" => true,
14281393
// These are tested as part of the linux_fcntl tests since there are
14291394
// header conflicts when including them with all the other structs.
14301395
"termios2" => true,
@@ -1476,8 +1441,6 @@ fn test_netbsd(target: &str) {
14761441
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
14771442
// sighandler_t type is super weird
14781443
(struct_ == "sigaction" && field == "sa_sigaction") ||
1479-
// sigval is actually a union, but we pretend it's a struct
1480-
(struct_ == "sigevent" && field == "sigev_value") ||
14811444
// aio_buf is "volatile void*" and Rust doesn't understand volatile
14821445
(struct_ == "aiocb" && field == "aio_buf")
14831446
});
@@ -1606,9 +1569,6 @@ fn test_dragonflybsd(target: &str) {
16061569

16071570
t if t.ends_with("_t") => t.to_string(),
16081571

1609-
// sigval is a struct in Rust, but a union in C:
1610-
"sigval" => "union sigval".to_string(),
1611-
16121572
// put `struct` in front of all structs:.
16131573
t if is_struct => format!("struct {t}"),
16141574

@@ -1701,8 +1661,6 @@ fn test_dragonflybsd(target: &str) {
17011661
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
17021662
// sighandler_t type is super weird
17031663
(struct_ == "sigaction" && field == "sa_sigaction") ||
1704-
// sigval is actually a union, but we pretend it's a struct
1705-
(struct_ == "sigevent" && field == "sigev_value") ||
17061664
// aio_buf is "volatile void*" and Rust doesn't understand volatile
17071665
(struct_ == "aiocb" && field == "aio_buf")
17081666
});
@@ -1993,9 +1951,6 @@ fn test_android(target: &str) {
19931951

19941952
t if t.ends_with("_t") => t.to_string(),
19951953

1996-
// sigval is a struct in Rust, but a union in C:
1997-
"sigval" => "union sigval".to_string(),
1998-
19991954
"Ioctl" => "int".to_string(),
20001955

20011956
// put `struct` in front of all structs:.
@@ -2300,8 +2255,6 @@ fn test_android(target: &str) {
23002255
cfg.skip_field_type(move |struct_, field| {
23012256
// This is a weird union, don't check the type.
23022257
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
2303-
// sigval is actually a union, but we pretend it's a struct
2304-
(struct_ == "sigevent" && field == "sigev_value") ||
23052258
// this one is an anonymous union
23062259
(struct_ == "ff_effect" && field == "u") ||
23072260
// FIXME(android): `sa_sigaction` has type `sighandler_t` but that type is
@@ -2504,9 +2457,6 @@ fn test_freebsd(target: &str) {
25042457

25052458
t if t.ends_with("_t") => t.to_string(),
25062459

2507-
// sigval is a struct in Rust, but a union in C:
2508-
"sigval" => "union sigval".to_string(),
2509-
25102460
// put `struct` in front of all structs:.
25112461
t if is_struct => format!("struct {t}"),
25122462

@@ -3140,7 +3090,8 @@ fn test_emscripten(target: &str) {
31403090
return true;
31413091
}
31423092
match ty {
3143-
// This is actually a union, not a struct
3093+
// FIXME(emscripten): Investigate why the test fails.
3094+
// Skip for now to unblock CI.
31443095
"sigval" => true,
31453096

31463097
// FIXME(emscripten): Investigate why the test fails.
@@ -3221,9 +3172,7 @@ fn test_emscripten(target: &str) {
32213172
// This is a weird union, don't check the type.
32223173
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
32233174
// sighandler_t type is super weird
3224-
(struct_ == "sigaction" && field == "sa_sigaction") ||
3225-
// sigval is actually a union, but we pretend it's a struct
3226-
(struct_ == "sigevent" && field == "sigev_value")
3175+
(struct_ == "sigaction" && field == "sa_sigaction")
32273176
});
32283177

32293178
cfg.skip_field(move |struct_, field| {
@@ -3436,9 +3385,6 @@ fn test_neutrino(target: &str) {
34363385
match ty {
34373386
"Elf64_Phdr" | "Elf32_Phdr" => true,
34383387

3439-
// FIXME(union): This is actually a union, not a struct
3440-
"sigval" => true,
3441-
34423388
// union
34433389
"_channel_connect_attr" => true,
34443390

@@ -3493,8 +3439,6 @@ fn test_neutrino(target: &str) {
34933439
});
34943440

34953441
cfg.skip_field_type(move |struct_, field| {
3496-
// sigval is actually a union, but we pretend it's a struct
3497-
struct_ == "sigevent" && field == "sigev_value" ||
34983442
// Anonymous structures
34993443
struct_ == "_idle_hook" && field == "time"
35003444
});
@@ -3505,8 +3449,6 @@ fn test_neutrino(target: &str) {
35053449
("__sched_param", "reserved")
35063450
| ("sched_param", "reserved")
35073451
| ("sigevent", "__padding1") // ensure alignment
3508-
| ("sigevent", "__padding2") // union
3509-
| ("sigevent", "__sigev_un2") // union
35103452
| ("sigaction", "sa_sigaction") // sighandler_t type is super weird
35113453
| ("syspage_entry", "__reserved") // does not exist
35123454
)
@@ -3611,10 +3553,8 @@ fn test_vxworks(target: &str) {
36113553

36123554
// FIXME(vxworks)
36133555
cfg.skip_fn(move |name| match name {
3614-
// sigval
3615-
"sigqueue" | "_sigqueue"
36163556
// sighandler_t
3617-
| "signal"
3557+
"signal"
36183558
// not used in static linking by default
36193559
| "dlerror" => true,
36203560
_ => false,
@@ -4051,9 +3991,6 @@ fn test_linux(target: &str) {
40513991
// which is absent in glibc, has to be defined.
40523992
"__timeval" => true,
40533993

4054-
// FIXME(union): This is actually a union, not a struct
4055-
"sigval" => true,
4056-
40573994
// This type is tested in the `linux_termios.rs` file since there
40583995
// are header conflicts when including them with all the other
40593996
// structs.
@@ -4740,12 +4677,6 @@ fn test_linux(target: &str) {
47404677
// Needs musl 1.2.3 or later.
47414678
"pthread_getname_np" if old_musl => true,
47424679

4743-
// pthread_sigqueue uses sigval, which was initially declared
4744-
// as a struct but should be defined as a union. However due
4745-
// to the issues described here: https://github.com/rust-lang/libc/issues/2816
4746-
// it can't be changed from struct.
4747-
"pthread_sigqueue" => true,
4748-
47494680
// There are two versions of basename(3) on Linux with glibc, see
47504681
//
47514682
// https://man7.org/linux/man-pages/man3/basename.3.html
@@ -4779,8 +4710,6 @@ fn test_linux(target: &str) {
47794710
(struct_ == "sigaction" && field == "sa_sigaction") ||
47804711
// __timeval type is a patch which doesn't exist in glibc
47814712
(struct_ == "utmpx" && field == "ut_tv") ||
4782-
// sigval is actually a union, but we pretend it's a struct
4783-
(struct_ == "sigevent" && field == "sigev_value") ||
47844713
// this one is an anonymous union
47854714
(struct_ == "ff_effect" && field == "u") ||
47864715
// `__exit_status` type is a patch which is absent in musl
@@ -5261,8 +5190,6 @@ fn test_haiku(target: &str) {
52615190
return true;
52625191
}
52635192
match ty {
5264-
// FIXME(union): actually a union
5265-
"sigval" => true,
52665193
// FIXME(haiku): locale_t does not exist on Haiku
52675194
"locale_t" => true,
52685195
// FIXME(haiku): rusage has a different layout on Haiku
@@ -5369,10 +5296,8 @@ fn test_haiku(target: &str) {
53695296
("stat", "st_crtime_nsec") => true,
53705297

53715298
// these are actually unions, but we cannot represent it well
5372-
("siginfo_t", "sigval") => true,
53735299
("sem_t", "named_sem_id") => true,
53745300
("sigaction", "sa_sigaction") => true,
5375-
("sigevent", "sigev_value") => true,
53765301
("fpu_state", "_fpreg") => true,
53775302
("cpu_topology_node_info", "data") => true,
53785303
// these fields have a simplified data definition in libc
@@ -5423,8 +5348,6 @@ fn test_haiku(target: &str) {
54235348
ty.to_string()
54245349
}
54255350

5426-
// is actually a union
5427-
"sigval" => "union sigval".to_string(),
54285351
t if is_union => format!("union {t}"),
54295352
t if t.ends_with("_t") => t.to_string(),
54305353
t if is_struct => format!("struct {t}"),
@@ -5563,9 +5486,6 @@ fn test_aix(target: &str) {
55635486
"FILE" => ty.to_string(),
55645487
"ACTION" => ty.to_string(),
55655488

5566-
// 'sigval' is a struct in Rust, but a union in C.
5567-
"sigval" => format!("union sigval"),
5568-
55695489
t if t.ends_with("_t") => t.to_string(),
55705490
t if is_struct => format!("struct {}", t),
55715491
t if is_union => format!("union {}", t),
@@ -5586,9 +5506,6 @@ fn test_aix(target: &str) {
55865506

55875507
cfg.skip_struct(move |ty| {
55885508
match ty {
5589-
// FIXME(union): actually a union.
5590-
"sigval" => true,
5591-
55925509
// '__poll_ctl_ext_u' and '__pollfd_ext_u' are for unnamed unions.
55935510
"__poll_ctl_ext_u" => true,
55945511
"__pollfd_ext_u" => true,

src/fuchsia/mod.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ s! {
240240
pub l_linger: c_int,
241241
}
242242

243-
pub struct sigval {
244-
// Actually a union of an int and a void*
245-
pub sival_ptr: *mut c_void,
246-
}
247-
248243
// <sys/time.h>
249244
pub struct itimerval {
250245
pub it_interval: crate::timeval,
@@ -1043,6 +1038,11 @@ s_no_extra_traits! {
10431038
pub struct pthread_cond_t {
10441039
size: [u8; crate::__SIZEOF_PTHREAD_COND_T],
10451040
}
1041+
1042+
pub union sigval {
1043+
pub sival_int: c_int,
1044+
pub sival_ptr: *mut c_void,
1045+
}
10461046
}
10471047

10481048
cfg_if! {
@@ -1305,6 +1305,18 @@ cfg_if! {
13051305
self.size.hash(state);
13061306
}
13071307
}
1308+
1309+
impl PartialEq for sigval {
1310+
fn eq(&self, other: &sigval) -> bool {
1311+
unimplemented!("traits")
1312+
}
1313+
}
1314+
impl Eq for sigval {}
1315+
impl hash::Hash for sigval {
1316+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
1317+
unimplemented!("traits")
1318+
}
1319+
}
13081320
}
13091321
}
13101322

src/unix/mod.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ s! {
174174
pub l_linger: c_int,
175175
}
176176

177-
pub struct sigval {
178-
// Actually a union of an int and a void*
179-
pub sival_ptr: *mut c_void,
180-
}
181-
182177
// <sys/time.h>
183178
pub struct itimerval {
184179
pub it_interval: crate::timeval,
@@ -218,6 +213,29 @@ s! {
218213
}
219214
}
220215

216+
s_no_extra_traits! {
217+
pub union sigval {
218+
pub sival_int: c_int,
219+
pub sival_ptr: *mut c_void,
220+
}
221+
}
222+
223+
cfg_if! {
224+
if #[cfg(feature = "extra_traits")] {
225+
impl PartialEq for sigval {
226+
fn eq(&self, _other: &sigval) -> bool {
227+
unimplemented!("traits")
228+
}
229+
}
230+
impl Eq for sigval {}
231+
impl hash::Hash for sigval {
232+
fn hash<H: hash::Hasher>(&self, _state: &mut H) {
233+
unimplemented!("traits")
234+
}
235+
}
236+
}
237+
}
238+
221239
pub const INT_MIN: c_int = -2147483648;
222240
pub const INT_MAX: c_int = 2147483647;
223241

0 commit comments

Comments
 (0)