Skip to content

Commit 2c27f58

Browse files
committed
Make sigval an union
1 parent 2f931d9 commit 2c27f58

File tree

11 files changed

+31
-300
lines changed

11 files changed

+31
-300
lines changed

libc-test/build.rs

Lines changed: 7 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,6 @@ fn test_apple(target: &str) {
293293
return true;
294294
}
295295
match ty {
296-
// FIXME: actually a union
297-
"sigval" => true,
298-
299296
// FIXME: The size is changed in recent macOSes.
300297
"malloc_zone_t" => true,
301298
// it is a moving target, changing through versions
@@ -391,14 +388,6 @@ fn test_apple(target: &str) {
391388
}
392389
});
393390

394-
cfg.skip_field_type(move |struct_, field| {
395-
match (struct_, field) {
396-
// FIXME: actually a union
397-
("sigevent", "sigev_value") => true,
398-
_ => false,
399-
}
400-
});
401-
402391
cfg.volatile_item(|i| {
403392
use ctest::VolatileItemKind::*;
404393
match i {
@@ -538,27 +527,6 @@ fn test_openbsd(target: &str) {
538527
"sys/param.h",
539528
}
540529

541-
cfg.skip_struct(move |ty| {
542-
if ty.starts_with("__c_anonymous_") {
543-
return true;
544-
}
545-
match ty {
546-
// FIXME: actually a union
547-
"sigval" => true,
548-
549-
_ => false,
550-
}
551-
});
552-
553-
cfg.skip_const(move |name| {
554-
match name {
555-
// Removed in OpenBSD 7.7 (unused since 1991)
556-
"ATF_COM" | "ATF_PERM" | "ATF_PUBL" | "ATF_USETRAILERS" => true,
557-
558-
_ => false,
559-
}
560-
});
561-
562530
cfg.skip_fn(move |name| {
563531
match name {
564532
// futex() has volatile arguments, but that doesn't exist in Rust.
@@ -953,8 +921,6 @@ fn test_solarish(target: &str) {
953921
return true;
954922
}
955923
match ty {
956-
// union, not a struct
957-
"sigval" => true,
958924
// a bunch of solaris-only fields
959925
"utmpx" if is_illumos => true,
960926
_ => false,
@@ -974,8 +940,6 @@ fn test_solarish(target: &str) {
974940
"sigaction" if field == "sa_sigaction" => true,
975941
// Missing in illumos
976942
"sigevent" if field == "ss_sp" => true,
977-
// Avoid sigval union issues
978-
"sigevent" if field == "sigev_value" => true,
979943
// const issues
980944
"sigevent" if field == "sigev_notify_attributes" => true,
981945

@@ -1198,8 +1162,6 @@ fn test_netbsd(target: &str) {
11981162

11991163
cfg.skip_struct(move |ty| {
12001164
match ty {
1201-
// This is actually a union, not a struct
1202-
"sigval" => true,
12031165
// These are tested as part of the linux_fcntl tests since there are
12041166
// header conflicts when including them with all the other structs.
12051167
"termios2" => true,
@@ -1250,8 +1212,6 @@ fn test_netbsd(target: &str) {
12501212
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
12511213
// sighandler_t type is super weird
12521214
(struct_ == "sigaction" && field == "sa_sigaction") ||
1253-
// sigval is actually a union, but we pretend it's a struct
1254-
(struct_ == "sigevent" && field == "sigev_value") ||
12551215
// aio_buf is "volatile void*" and Rust doesn't understand volatile
12561216
(struct_ == "aiocb" && field == "aio_buf")
12571217
});
@@ -1380,9 +1340,6 @@ fn test_dragonflybsd(target: &str) {
13801340

13811341
t if t.ends_with("_t") => t.to_string(),
13821342

1383-
// sigval is a struct in Rust, but a union in C:
1384-
"sigval" => format!("union sigval"),
1385-
13861343
// put `struct` in front of all structs:.
13871344
t if is_struct => format!("struct {}", t),
13881345

@@ -1476,8 +1433,6 @@ fn test_dragonflybsd(target: &str) {
14761433
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
14771434
// sighandler_t type is super weird
14781435
(struct_ == "sigaction" && field == "sa_sigaction") ||
1479-
// sigval is actually a union, but we pretend it's a struct
1480-
(struct_ == "sigevent" && field == "sigev_value") ||
14811436
// aio_buf is "volatile void*" and Rust doesn't understand volatile
14821437
(struct_ == "aiocb" && field == "aio_buf")
14831438
});
@@ -1768,9 +1723,6 @@ fn test_android(target: &str) {
17681723

17691724
t if t.ends_with("_t") => t.to_string(),
17701725

1771-
// sigval is a struct in Rust, but a union in C:
1772-
"sigval" => format!("union sigval"),
1773-
17741726
// put `struct` in front of all structs:.
17751727
t if is_struct => format!("struct {}", t),
17761728

@@ -2061,8 +2013,6 @@ fn test_android(target: &str) {
20612013
cfg.skip_field_type(move |struct_, field| {
20622014
// This is a weird union, don't check the type.
20632015
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
2064-
// sigval is actually a union, but we pretend it's a struct
2065-
(struct_ == "sigevent" && field == "sigev_value") ||
20662016
// this one is an anonymous union
20672017
(struct_ == "ff_effect" && field == "u") ||
20682018
// FIXME: `sa_sigaction` has type `sighandler_t` but that type is
@@ -2268,9 +2218,6 @@ fn test_freebsd(target: &str) {
22682218

22692219
t if t.ends_with("_t") => t.to_string(),
22702220

2271-
// sigval is a struct in Rust, but a union in C:
2272-
"sigval" => format!("union sigval"),
2273-
22742221
// put `struct` in front of all structs:.
22752222
t if is_struct => format!("struct {}", t),
22762223

@@ -2890,13 +2837,13 @@ fn test_emscripten(target: &str) {
28902837

28912838
cfg.skip_struct(move |ty| {
28922839
match ty {
2893-
// This is actually a union, not a struct
2894-
"sigval" => true,
2840+
// FIXME: It was removed in
2841+
// emscripten-core/emscripten@953e414
2842+
"pthread_mutexattr_t" => true,
28952843

28962844
// FIXME: Investigate why the test fails.
28972845
// Skip for now to unblock CI.
28982846
"pthread_condattr_t" => true,
2899-
"pthread_mutexattr_t" => true,
29002847

29012848
// No epoll support
29022849
// https://github.com/emscripten-core/emscripten/issues/5033
@@ -2969,8 +2916,9 @@ fn test_emscripten(target: &str) {
29692916
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
29702917
// sighandler_t type is super weird
29712918
(struct_ == "sigaction" && field == "sa_sigaction") ||
2972-
// sigval is actually a union, but we pretend it's a struct
2973-
(struct_ == "sigevent" && field == "sigev_value")
2919+
// aio_buf is "volatile void*" and Rust doesn't understand volatile
2920+
// FIXME: is this necessary?
2921+
(struct_ == "aiocb" && field == "aio_buf")
29742922
});
29752923

29762924
cfg.skip_field(move |struct_, field| {
@@ -3164,9 +3112,6 @@ fn test_neutrino(target: &str) {
31643112
match ty {
31653113
"Elf64_Phdr" | "Elf32_Phdr" => true,
31663114

3167-
// FIXME: This is actually a union, not a struct
3168-
"sigval" => true,
3169-
31703115
// union
31713116
"_channel_connect_attr" => true,
31723117

@@ -3218,8 +3163,6 @@ fn test_neutrino(target: &str) {
32183163
});
32193164

32203165
cfg.skip_field_type(move |struct_, field| {
3221-
// sigval is actually a union, but we pretend it's a struct
3222-
struct_ == "sigevent" && field == "sigev_value" ||
32233166
// Anonymous structures
32243167
struct_ == "_idle_hook" && field == "time"
32253168
});
@@ -3228,8 +3171,6 @@ fn test_neutrino(target: &str) {
32283171
(struct_ == "__sched_param" && field == "reserved") ||
32293172
(struct_ == "sched_param" && field == "reserved") ||
32303173
(struct_ == "sigevent" && field == "__padding1") || // ensure alignment
3231-
(struct_ == "sigevent" && field == "__padding2") || // union
3232-
(struct_ == "sigevent" && field == "__sigev_un2") || // union
32333174
// sighandler_t type is super weird
32343175
(struct_ == "sigaction" && field == "sa_sigaction") ||
32353176
// does not exist
@@ -3338,10 +3279,8 @@ fn test_vxworks(target: &str) {
33383279

33393280
// FIXME
33403281
cfg.skip_fn(move |name| match name {
3341-
// sigval
3342-
"sigqueue" | "_sigqueue"
33433282
// sighandler_t
3344-
| "signal"
3283+
"signal"
33453284
// not used in static linking by default
33463285
| "dlerror" => true,
33473286
_ => false,
@@ -3747,9 +3686,6 @@ fn test_linux(target: &str) {
37473686
// which is absent in glibc, has to be defined.
37483687
"__timeval" => true,
37493688

3750-
// FIXME: This is actually a union, not a struct
3751-
"sigval" => true,
3752-
37533689
// This type is tested in the `linux_termios.rs` file since there
37543690
// are header conflicts when including them with all the other
37553691
// structs.
@@ -4415,8 +4351,6 @@ fn test_linux(target: &str) {
44154351
(struct_ == "sigaction" && field == "sa_sigaction") ||
44164352
// __timeval type is a patch which doesn't exist in glibc
44174353
(struct_ == "utmpx" && field == "ut_tv") ||
4418-
// sigval is actually a union, but we pretend it's a struct
4419-
(struct_ == "sigevent" && field == "sigev_value") ||
44204354
// this one is an anonymous union
44214355
(struct_ == "ff_effect" && field == "u") ||
44224356
// `__exit_status` type is a patch which is absent in musl
@@ -4860,8 +4794,6 @@ fn test_haiku(target: &str) {
48604794
return true;
48614795
}
48624796
match ty {
4863-
// FIXME: actually a union
4864-
"sigval" => true,
48654797
// FIXME: locale_t does not exist on Haiku
48664798
"locale_t" => true,
48674799
// FIXME: rusage has a different layout on Haiku
@@ -4968,10 +4900,8 @@ fn test_haiku(target: &str) {
49684900
("stat", "st_crtime_nsec") => true,
49694901

49704902
// these are actually unions, but we cannot represent it well
4971-
("siginfo_t", "sigval") => true,
49724903
("sem_t", "named_sem_id") => true,
49734904
("sigaction", "sa_sigaction") => true,
4974-
("sigevent", "sigev_value") => true,
49754905
("fpu_state", "_fpreg") => true,
49764906
("cpu_topology_node_info", "data") => true,
49774907
// these fields have a simplified data definition in libc
@@ -5022,8 +4952,6 @@ fn test_haiku(target: &str) {
50224952
ty.to_string()
50234953
}
50244954

5025-
// is actually a union
5026-
"sigval" => format!("union sigval"),
50274955
t if is_union => format!("union {}", t),
50284956
t if t.ends_with("_t") => t.to_string(),
50294957
t if is_struct => format!("struct {}", t),

src/fuchsia/mod.rs

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,6 @@ s! {
253253
pub l_linger: ::c_int,
254254
}
255255

256-
pub struct sigval {
257-
// Actually a union of an int and a void*
258-
pub sival_ptr: *mut ::c_void,
259-
}
260-
261256
// <sys/time.h>
262257
pub struct itimerval {
263258
pub it_interval: ::timeval,
@@ -1046,6 +1041,11 @@ s_no_extra_traits! {
10461041
pub struct pthread_cond_t {
10471042
size: [u8; ::__SIZEOF_PTHREAD_COND_T],
10481043
}
1044+
1045+
pub union sigval {
1046+
pub sival_int: ::int,
1047+
pub sival_ptr: *mut ::c_void,
1048+
}
10491049
}
10501050

10511051
cfg_if! {
@@ -1340,16 +1340,6 @@ cfg_if! {
13401340
}
13411341
}
13421342

1343-
impl PartialEq for sigevent {
1344-
fn eq(&self, other: &sigevent) -> bool {
1345-
self.sigev_value == other.sigev_value
1346-
&& self.sigev_signo == other.sigev_signo
1347-
&& self.sigev_notify == other.sigev_notify
1348-
&& self.sigev_notify_function == other.sigev_notify_function
1349-
&& self.sigev_notify_attributes == other.sigev_notify_attributes
1350-
}
1351-
}
1352-
impl Eq for sigevent {}
13531343
impl ::fmt::Debug for sigevent {
13541344
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
13551345
f.debug_struct("sigevent")
@@ -1361,70 +1351,10 @@ cfg_if! {
13611351
.finish()
13621352
}
13631353
}
1364-
impl ::hash::Hash for sigevent {
1365-
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1366-
self.sigev_value.hash(state);
1367-
self.sigev_signo.hash(state);
1368-
self.sigev_notify.hash(state);
1369-
self.sigev_notify_function.hash(state);
1370-
self.sigev_notify_attributes.hash(state);
1371-
}
1372-
}
13731354

1374-
impl PartialEq for pthread_cond_t {
1375-
fn eq(&self, other: &pthread_cond_t) -> bool {
1376-
self.size.iter().zip(other.size.iter()).all(|(a, b)| a == b)
1377-
}
1378-
}
1379-
impl Eq for pthread_cond_t {}
1380-
impl ::fmt::Debug for pthread_cond_t {
1355+
impl ::fmt::Debug for sigval {
13811356
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1382-
f.debug_struct("pthread_cond_t")
1383-
// FIXME: .field("size", &self.size)
1384-
.finish()
1385-
}
1386-
}
1387-
impl ::hash::Hash for pthread_cond_t {
1388-
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1389-
self.size.hash(state);
1390-
}
1391-
}
1392-
1393-
impl PartialEq for pthread_mutex_t {
1394-
fn eq(&self, other: &pthread_mutex_t) -> bool {
1395-
self.size.iter().zip(other.size.iter()).all(|(a, b)| a == b)
1396-
}
1397-
}
1398-
impl Eq for pthread_mutex_t {}
1399-
impl ::fmt::Debug for pthread_mutex_t {
1400-
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1401-
f.debug_struct("pthread_mutex_t")
1402-
// FIXME: .field("size", &self.size)
1403-
.finish()
1404-
}
1405-
}
1406-
impl ::hash::Hash for pthread_mutex_t {
1407-
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1408-
self.size.hash(state);
1409-
}
1410-
}
1411-
1412-
impl PartialEq for pthread_rwlock_t {
1413-
fn eq(&self, other: &pthread_rwlock_t) -> bool {
1414-
self.size.iter().zip(other.size.iter()).all(|(a, b)| a == b)
1415-
}
1416-
}
1417-
impl Eq for pthread_rwlock_t {}
1418-
impl ::fmt::Debug for pthread_rwlock_t {
1419-
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1420-
f.debug_struct("pthread_rwlock_t")
1421-
// FIXME: .field("size", &self.size)
1422-
.finish()
1423-
}
1424-
}
1425-
impl ::hash::Hash for pthread_rwlock_t {
1426-
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1427-
self.size.hash(state);
1357+
f.debug_struct("sigval").finish_non_exhaustive()
14281358
}
14291359
}
14301360
}

0 commit comments

Comments
 (0)