Skip to content

Commit fd2f724

Browse files
joshtripletttgross35
authored andcommitted
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.
1 parent de29a3f commit fd2f724

File tree

14 files changed

+15
-29
lines changed

14 files changed

+15
-29
lines changed

libc-test/build.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ fn test_apple(target: &str) {
398398
// FIXME: the array size has been changed since macOS 10.15 ([8] -> [7]).
399399
("statfs", "f_reserved") => true,
400400
("__darwin_arm_neon_state64", "__v") => true,
401-
// MAXPATHLEN is too big for auto-derive traits on arrays.
402-
("vnode_info_path", "vip_path") => true,
401+
403402
("ifreq", "ifr_ifru") => true,
404403
("ifkpi", "ifk_data") => true,
405404
("ifconf", "ifc_ifcu") => true,
@@ -2744,8 +2743,6 @@ fn test_freebsd(target: &str) {
27442743
("umutex", "m_owner") => true,
27452744
// c_has_waiters field is a volatile int32_t
27462745
("ucond", "c_has_waiters") => true,
2747-
// is PATH_MAX long but tests can't accept multi array as equivalent.
2748-
("kinfo_vmentry", "kve_path") => true,
27492746

27502747
// a_un field is a union
27512748
("Elf32_Auxinfo", "a_un") => true,
@@ -2774,10 +2771,6 @@ fn test_freebsd(target: &str) {
27742771
// Anonymous type.
27752772
("filestat", "next") => true,
27762773

2777-
// We ignore this field because we needed to use a hack in order to make rust 1.19
2778-
// happy...
2779-
("kinfo_proc", "ki_sparestrings") => true,
2780-
27812774
// `__sem_base` is a private struct field
27822775
("semid_ds", "__sem_base") => true,
27832776

src/unix/bsd/apple/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -946,9 +946,7 @@ s! {
946946

947947
pub struct vnode_info_path {
948948
pub vip_vi: vnode_info,
949-
// Normally it's `vip_path: [::c_char; MAXPATHLEN]` but because libc supports an old rustc
950-
// version, we go around this limitation like this.
951-
pub vip_path: [[::c_char; 32]; 32],
949+
pub vip_path: [::c_char; ::MAXPATHLEN as usize],
952950
}
953951

954952
pub struct proc_vnodepathinfo {

src/unix/bsd/freebsdlike/dragonfly/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ s_no_extra_traits! {
517517
pub mc_ownedfp: ::c_uint,
518518
__reserved: ::c_uint,
519519
__unused: [::c_uint; 8],
520-
pub mc_fpregs: [[::c_uint; 8]; 32],
520+
pub mc_fpregs: [::c_uint; 256],
521521
}
522522

523523
pub struct ucontext_t {
@@ -786,8 +786,7 @@ cfg_if! {
786786
self.mc_len == other.mc_len &&
787787
self.mc_fpformat == other.mc_fpformat &&
788788
self.mc_ownedfp == other.mc_ownedfp &&
789-
self.mc_fpregs.iter().zip(other.mc_fpregs.iter()).
790-
all(|(a, b)| a == b)
789+
self.mc_fpregs == other.mc_fpregs
791790
}
792791
}
793792
impl Eq for mcontext_t {}

src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ s! {
166166
/// More thread name.
167167
pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
168168
/// Spare string space.
169-
pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
169+
pub ki_sparestrings: [::c_char; 46],
170170
/// Spare room for growth.
171171
pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
172172
/// Which cpu we are on.

src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ s! {
173173
/// More thread name.
174174
pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
175175
/// Spare string space.
176-
pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
176+
pub ki_sparestrings: [::c_char; 46],
177177
/// Spare room for growth.
178178
pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
179179
/// Controlling tty dev.

src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ s! {
183183
/// More thread name.
184184
pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
185185
/// Spare string space.
186-
pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
186+
pub ki_sparestrings: [::c_char; 46],
187187
/// Spare room for growth.
188188
pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
189189
/// Controlling tty dev.

src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ s! {
183183
/// More thread name.
184184
pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
185185
/// Spare string space.
186-
pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
186+
pub ki_sparestrings: [::c_char; 46],
187187
/// Spare room for growth.
188188
pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
189189
/// Controlling tty dev.

src/unix/bsd/freebsdlike/freebsd/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ s! {
458458
_kve_is_spare: [::c_int; 8],
459459
#[cfg(freebsd11)]
460460
_kve_is_spare: [::c_int; 12],
461-
pub kve_path: [[::c_char; 32]; 32],
461+
pub kve_path: [::c_char; ::PATH_MAX as usize],
462462
}
463463

464464
pub struct __c_anonymous_filestat {

src/unix/bsd/freebsdlike/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ s! {
284284

285285
pub struct accept_filter_arg {
286286
pub af_name: [::c_char; 16],
287-
af_arg: [[::c_char; 10]; 24],
287+
af_arg: [::c_char; 240],
288288
}
289289

290290
pub struct ptrace_io_desc {

src/unix/bsd/netbsdlike/netbsd/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ s! {
663663
pub kve_vn_rdev: u64,
664664
pub kve_vn_type: u32,
665665
pub kve_vn_mode: u32,
666-
pub kve_path: [[::c_char; 32]; 32],
666+
pub kve_path: [::c_char; ::PATH_MAX as usize],
667667
}
668668

669669
pub struct __c_anonymous_posix_spawn_fae_open {

src/unix/linux_like/android/b64/aarch64/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ s! {
7171
pub sp: ::c_ulonglong,
7272
pub pc: ::c_ulonglong,
7373
pub pstate: ::c_ulonglong,
74-
// nested arrays to get the right size/length while being able to
75-
// auto-derive traits like Debug
76-
__reserved: [[u64; 32]; 16],
74+
__reserved: [u64; 512],
7775
}
7876

7977
pub struct user_fpsimd_struct {

src/unix/linux_like/android/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ s_no_extra_traits! {
609609
pub struct prop_info {
610610
__name: [::c_char; 32],
611611
__serial: ::c_uint,
612-
__value: [[::c_char; 4]; 23],
612+
__value: [::c_char; 92],
613613
}
614614

615615
pub union __c_anonymous_ifr_ifru {

src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ s! {
212212
pub sp: ::c_ulonglong,
213213
pub pc: ::c_ulonglong,
214214
pub pstate: ::c_ulonglong,
215-
// nested arrays to get the right size/length while being able to
216-
// auto-derive traits like Debug
217-
__reserved: [[u64; 32]; 16],
215+
__reserved: [u64; 512],
218216
}
219217

220218
pub struct user_fpsimd_struct {

src/unix/linux_like/linux/musl/b64/aarch64/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ s! {
8484
pub sp: ::c_ulong,
8585
pub pc: ::c_ulong,
8686
pub pstate: ::c_ulong,
87-
__reserved: [[u64; 32]; 16],
87+
__reserved: [u64; 512],
8888
}
8989

9090
#[repr(align(8))]

0 commit comments

Comments
 (0)