From ec4d2a97374136df7526db0e975ebb014b8e124b Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 11 Jul 2022 22:34:44 -0700 Subject: [PATCH] Remove array size hacks for Rust < 1.47 Rust >= 1.47 supports traits for arrays of arbitrary size, so remove the various hacks using nested arrays when the native platform definition uses a single array. --- libc-test/build.rs | 8 -------- src/unix/bsd/apple/mod.rs | 4 +--- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 5 ++--- src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs | 2 +- src/unix/bsd/freebsdlike/freebsd/mod.rs | 2 +- src/unix/bsd/freebsdlike/mod.rs | 2 +- src/unix/bsd/netbsdlike/netbsd/mod.rs | 2 +- src/unix/linux_like/android/b64/aarch64/mod.rs | 4 +--- src/unix/linux_like/android/mod.rs | 2 +- src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs | 4 +--- src/unix/linux_like/linux/musl/b64/aarch64/mod.rs | 2 +- 14 files changed, 14 insertions(+), 29 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 02ea4023d0408..c5edb435baecc 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -322,8 +322,6 @@ fn test_apple(target: &str) { // FIXME: the array size has been changed since macOS 10.15 ([8] -> [7]). ("statfs", "f_reserved") => true, ("__darwin_arm_neon_state64", "__v") => true, - // MAXPATHLEN is too big for auto-derive traits on arrays. - ("vnode_info_path", "vip_path") => true, _ => false, } }); @@ -2242,8 +2240,6 @@ fn test_freebsd(target: &str) { ("umutex", "m_owner") => true, // c_has_waiters field is a volatile int32_t ("ucond", "c_has_waiters") => true, - // is PATH_MAX long but tests can't accept multi array as equivalent. - ("kinfo_vmentry", "kve_path") => true, // a_un field is a union ("Elf32_Auxinfo", "a_un") => true, @@ -2272,10 +2268,6 @@ fn test_freebsd(target: &str) { // Anonymous type. ("filestat", "next") => true, - // We ignore this field because we needed to use a hack in order to make rust 1.19 - // happy... - ("kinfo_proc", "ki_sparestrings") => true, - // `__sem_base` is a private struct field ("semid_ds", "__sem_base") => true, diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index efb6657e04fc0..dfa0f05335ded 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -818,9 +818,7 @@ s! { pub struct vnode_info_path { pub vip_vi: vnode_info, - // Normally it's `vip_path: [::c_char; MAXPATHLEN]` but because libc supports an old rustc - // version, we go around this limitation like this. - pub vip_path: [[::c_char; 32]; 32], + pub vip_path: [::c_char; ::MAXPATHLEN as usize], } pub struct proc_vnodepathinfo { diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index df7719b4b9c69..b4ee100cd646d 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -517,7 +517,7 @@ s_no_extra_traits! { pub mc_ownedfp: ::c_uint, __reserved: ::c_uint, __unused: [::c_uint; 8], - pub mc_fpregs: [[::c_uint; 8]; 32], + pub mc_fpregs: [::c_uint; 256], } pub struct ucontext_t { @@ -786,8 +786,7 @@ cfg_if! { self.mc_len == other.mc_len && self.mc_fpformat == other.mc_fpformat && self.mc_ownedfp == other.mc_ownedfp && - self.mc_fpregs.iter().zip(other.mc_fpregs.iter()). - all(|(a, b)| a == b) + self.mc_fpregs == other.mc_fpregs } } impl Eq for mcontext_t {} diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs index 1af555fa3655c..c192db962d1c4 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs @@ -166,7 +166,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq + pub ki_sparestrings: [::c_char; 46], /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Which cpu we are on. diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs index 848db33993556..f862dd36e595f 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs @@ -173,7 +173,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq + pub ki_sparestrings: [::c_char; 46], /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Controlling tty dev. diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs index a929f9d290e63..ef3179c27c7d4 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs @@ -180,7 +180,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq + pub ki_sparestrings: [::c_char; 46], /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Controlling tty dev. diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs index c655d555d9005..475420b80e616 100644 --- a/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs @@ -180,7 +180,7 @@ s! { /// More thread name. pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1], /// Spare string space. - pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq + pub ki_sparestrings: [::c_char; 46], /// Spare room for growth. pub ki_spareints: [::c_int; ::KI_NSPARE_INT], /// Controlling tty dev. diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index ca98e437ff4f2..82a70e195b3ff 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -442,7 +442,7 @@ s! { _kve_is_spare: [::c_int; 8], #[cfg(freebsd11)] _kve_is_spare: [::c_int; 12], - pub kve_path: [[::c_char; 32]; 32], + pub kve_path: [::c_char; ::PATH_MAX as usize], } pub struct __c_anonymous_filestat { diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 5c3726b9fc98e..10dc9ee7ad236 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -284,7 +284,7 @@ s! { pub struct accept_filter_arg { pub af_name: [::c_char; 16], - af_arg: [[::c_char; 10]; 24], + af_arg: [::c_char; 240], } pub struct ptrace_io_desc { diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 66b35aedf7dc5..d8363690502f7 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -635,7 +635,7 @@ s! { pub kve_vn_rdev: u64, pub kve_vn_type: u32, pub kve_vn_mode: u32, - pub kve_path: [[::c_char; 32]; 32], + pub kve_path: [::c_char; ::PATH_MAX as usize], } pub struct __c_anonymous_posix_spawn_fae_open { diff --git a/src/unix/linux_like/android/b64/aarch64/mod.rs b/src/unix/linux_like/android/b64/aarch64/mod.rs index 60acc7739083f..67dcf1beb39a9 100644 --- a/src/unix/linux_like/android/b64/aarch64/mod.rs +++ b/src/unix/linux_like/android/b64/aarch64/mod.rs @@ -71,9 +71,7 @@ s! { pub sp: ::c_ulonglong, pub pc: ::c_ulonglong, pub pstate: ::c_ulonglong, - // nested arrays to get the right size/length while being able to - // auto-derive traits like Debug - __reserved: [[u64; 32]; 16], + __reserved: [u64; 512], } pub struct user_fpsimd_struct { diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index d612c8980c6e6..489d9b4469b31 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -432,7 +432,7 @@ s_no_extra_traits! { pub struct prop_info { __name: [::c_char; 32], __serial: ::c_uint, - __value: [[::c_char; 4]; 23], + __value: [::c_char; 92], } } diff --git a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs index 7a9fbebc5d85b..ec0bb079d31c1 100644 --- a/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs @@ -218,9 +218,7 @@ s! { pub sp: ::c_ulonglong, pub pc: ::c_ulonglong, pub pstate: ::c_ulonglong, - // nested arrays to get the right size/length while being able to - // auto-derive traits like Debug - __reserved: [[u64; 32]; 16], + __reserved: [u64; 512], } pub struct user_fpsimd_struct { diff --git a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs index c8546228e3836..2cad1fb342a34 100644 --- a/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs +++ b/src/unix/linux_like/linux/musl/b64/aarch64/mod.rs @@ -83,7 +83,7 @@ s! { pub sp: ::c_ulong, pub pc: ::c_ulong, pub pstate: ::c_ulong, - __reserved: [[u64; 32]; 16], + __reserved: [u64; 512], } #[repr(align(8))]