Skip to content

Commit f093344

Browse files
authored
Merge pull request #4094 from tgross35/sync-more-main
Sync more files with `libc-0.2` to reduce the diff
2 parents 86b04cb + 9ac4a6b commit f093344

File tree

16 files changed

+125
-68
lines changed

16 files changed

+125
-68
lines changed

src/fixed_width_ints.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,29 @@ cfg_if! {
5959
/// C __uint128_t (alternate name for [__uint128][])
6060
pub type __uint128_t = u128;
6161

62-
macro_rules! static_assert_eq {
63-
($a:expr, $b:expr) => {
64-
const _: [(); $a] = [(); $b];
65-
};
66-
}
67-
6862
// NOTE: if you add more platforms to here, you may need to cfg
6963
// these consts. They should always match the platform's values
7064
// for `sizeof(__int128)` and `_Alignof(__int128)`.
7165
const _SIZE_128: usize = 16;
7266
const _ALIGN_128: usize = 16;
7367

74-
// Since Rust doesn't officially guarantee that these types
75-
// have compatible ABIs, we const assert that these values have the
76-
// known size/align of the target platform's libc. If rustc ever
77-
// tries to regress things, it will cause a compilation error.
68+
// FIXME(ctest): ctest doesn't handle `_` as an identifier so these tests are temporarily
69+
// disabled.
70+
// macro_rules! static_assert_eq {
71+
// ($a:expr, $b:expr) => {
72+
// const _: [(); $a] = [(); $b];
73+
// };
74+
// }
7875
//
79-
// This isn't a bullet-proof solution because e.g. it doesn't
80-
// catch the fact that llvm and gcc disagree on how x64 __int128
81-
// is actually *passed* on the stack (clang underaligns it for
82-
// the same reason that rustc *never* properly aligns it).
83-
// FIXME: temporarily disabled because of a ctest2 bug.
76+
// // Since Rust doesn't officially guarantee that these types
77+
// // have compatible ABIs, we const assert that these values have the
78+
// // known size/align of the target platform's libc. If rustc ever
79+
// // tries to regress things, it will cause a compilation error.
80+
// //
81+
// // This isn't a bullet-proof solution because e.g. it doesn't
82+
// // catch the fact that llvm and gcc disagree on how x64 __int128
83+
// // is actually *passed* on the stack (clang underaligns it for
84+
// // the same reason that rustc *never* properly aligns it).
8485
// static_assert_eq!(core::mem::size_of::<__int128>(), _SIZE_128);
8586
// static_assert_eq!(core::mem::align_of::<__int128>(), _ALIGN_128);
8687

@@ -93,9 +94,9 @@ cfg_if! {
9394
// static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
9495
// static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
9596
} else if #[cfg(all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos")))] {
96-
/// /// C `__int128_t`
97+
/// C `__int128_t`
9798
pub type __int128_t = i128;
98-
/// /// C `__uint128_t`
99+
/// C `__uint128_t`
99100
pub type __uint128_t = u128;
100101
}
101102
}

src/macros.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,36 @@ macro_rules! e {
167167
)*);
168168
}
169169

170+
// This is a pretty horrible hack to allow us to conditionally mark
171+
// some functions as 'const', without requiring users of this macro
172+
// to care about the "const-extern-fn" feature.
173+
//
174+
// When 'const-extern-fn' is enabled, we emit the captured 'const' keyword
175+
// in the expanded function.
176+
//
177+
// When 'const-extern-fn' is disabled, we always emit a plain 'pub unsafe extern fn'.
178+
// Note that the expression matched by the macro is exactly the same - this allows
179+
// users of this macro to work whether or not 'const-extern-fn' is enabled
180+
//
181+
// Unfortunately, we need to duplicate most of this macro between the 'cfg_if' blocks.
182+
// This is because 'const unsafe extern fn' won't even parse on older compilers,
183+
// so we need to avoid emitting it at all of 'const-extern-fn'.
184+
//
185+
// Specifically, moving the 'cfg_if' into the macro body will *not* work.
186+
// Doing so would cause the '#[cfg(feature = "const-extern-fn")]' to be emitted
187+
// into user code. The 'cfg' gate will not stop Rust from trying to parse the
188+
// 'pub const unsafe extern fn', so users would get a compiler error even when
189+
// the 'const-extern-fn' feature is disabled
190+
//
191+
// Note that users of this macro need to place 'const' in a weird position
192+
// (after the closing ')' for the arguments, but before the return type).
193+
// This was the only way I could satisfy the following two requirements:
194+
// 1. Avoid ambiguity errors from 'macro_rules!' (which happen when writing '$foo:ident fn'
195+
// 2. Allow users of this macro to mix 'pub fn foo' and 'pub const fn bar' within the same
196+
// 'f!' block
197+
198+
// FIXME(ctest): ctest can't handle `const extern` functions, we should be able to remove this
199+
// cfg completely.
170200
cfg_if! {
171201
if #[cfg(feature = "const-extern-fn")] {
172202
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
@@ -243,8 +273,7 @@ cfg_if! {
243273
)*) => ($(
244274
#[inline]
245275
$(#[$attr])*
246-
pub extern fn $i($($arg: $argty),*
247-
) -> $ret {
276+
pub extern fn $i($($arg: $argty),*) -> $ret {
248277
$($body);*
249278
}
250279
)*)

src/unix/bsd/apple/b64/aarch64/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ s! {
66
__private: [::uintptr_t; 18], // FIXME: needs arm64 auth pointers support
77
}
88

9-
pub struct ucontext_t {
9+
pub struct ucontext_t {
1010
pub uc_onstack: ::c_int,
1111
pub uc_sigmask: ::sigset_t,
1212
pub uc_stack: ::stack_t,

src/unix/bsd/apple/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ s! {
11751175
pub ifs6_pfx_expiry_cnt: ::u_quad_t,
11761176
pub ifs6_defrtr_expiry_cnt: ::u_quad_t,
11771177
}
1178+
11781179
pub struct icmp6_ifstat {
11791180
pub ifs6_in_msg: ::u_quad_t,
11801181
pub ifs6_in_error: ::u_quad_t,

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

+2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ cfg_if! {
5151
}
5252

5353
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1;
54+
5455
pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
5556
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
57+
5658
pub const MAP_32BIT: ::c_int = 0x00080000;
5759
pub const MINSIGSTKSZ: ::size_t = 4096; // 1024 * 4
5860
pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459;

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

+12-13
Original file line numberDiff line numberDiff line change
@@ -1723,13 +1723,12 @@ cfg_if! {
17231723
&& self.cr_uid == other.cr_uid
17241724
&& self.cr_ngroups == other.cr_ngroups
17251725
&& self.cr_groups == other.cr_groups
1726-
&& self.cr_pid__c_anonymous_union
1727-
== other.cr_pid__c_anonymous_union
1726+
&& self.cr_pid__c_anonymous_union == other.cr_pid__c_anonymous_union
17281727
}
17291728
}
17301729
impl Eq for xucred {}
17311730
impl ::fmt::Debug for xucred {
1732-
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1731+
fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result {
17331732
f.debug_struct("xucred")
17341733
.field("cr_version", &self.cr_version)
17351734
.field("cr_uid", &self.cr_uid)
@@ -4904,16 +4903,16 @@ pub const TFD_CLOEXEC: ::c_int = O_CLOEXEC;
49044903
pub const TFD_TIMER_ABSTIME: ::c_int = 0x01;
49054904
pub const TFD_TIMER_CANCEL_ON_SET: ::c_int = 0x02;
49064905

4906+
// sys/unistd.h
4907+
4908+
pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;
4909+
49074910
pub const KCMP_FILE: ::c_int = 100;
49084911
pub const KCMP_FILEOBJ: ::c_int = 101;
49094912
pub const KCMP_FILES: ::c_int = 102;
49104913
pub const KCMP_SIGHAND: ::c_int = 103;
49114914
pub const KCMP_VM: ::c_int = 104;
49124915

4913-
// sys/unistd.h
4914-
4915-
pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;
4916-
49174916
pub const fn MAP_ALIGNED(a: ::c_int) -> ::c_int {
49184917
a << 24
49194918
}
@@ -5632,19 +5631,19 @@ extern "C" {
56325631
pub fn closefrom(lowfd: ::c_int);
56335632
pub fn close_range(lowfd: ::c_uint, highfd: ::c_uint, flags: ::c_int) -> ::c_int;
56345633

5634+
pub fn execvpe(
5635+
file: *const ::c_char,
5636+
argv: *const *const ::c_char,
5637+
envp: *const *const ::c_char,
5638+
) -> ::c_int;
5639+
56355640
pub fn kcmp(
56365641
pid1: ::pid_t,
56375642
pid2: ::pid_t,
56385643
type_: ::c_int,
56395644
idx1: ::c_ulong,
56405645
idx2: ::c_ulong,
56415646
) -> ::c_int;
5642-
5643-
pub fn execvpe(
5644-
file: *const ::c_char,
5645-
argv: *const *const ::c_char,
5646-
envp: *const *const ::c_char,
5647-
) -> ::c_int;
56485647
}
56495648

56505649
#[link(name = "memstat")]

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

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ cfg_if! {
7070
}
7171

7272
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1;
73+
7374
pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
7475
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
7576
pub const MAP_32BIT: ::c_int = 0x00080000;

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

+2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ cfg_if! {
7070
}
7171

7272
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1;
73+
7374
pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
7475
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
76+
7577
pub const MAP_32BIT: ::c_int = 0x00080000;
7678
pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4
7779
pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ s_no_extra_traits! {
3636
}
3737
}
3838

39-
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1;
40-
4139
cfg_if! {
4240
if #[cfg(feature = "extra_traits")] {
4341
impl PartialEq for gpregs {
@@ -142,6 +140,8 @@ cfg_if! {
142140
}
143141
}
144142

143+
pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1;
144+
145145
pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
146146
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
147147
pub const MAP_32BIT: ::c_int = 0x00080000;

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1045,11 +1045,10 @@ cfg_if! {
10451045
}
10461046
}
10471047

1048-
impl Eq for statfs { }
1048+
impl Eq for statfs {}
10491049

10501050
impl ::fmt::Debug for statfs {
1051-
fn fmt(&self, f: &mut ::fmt::Formatter)
1052-
-> ::fmt::Result {
1051+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
10531052
f.debug_struct("statfs")
10541053
.field("f_flags", &self.f_flags)
10551054
.field("f_bsize", &self.f_bsize)

src/unix/haiku/native.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ extern "C" {
13281328
pathString: *mut ::c_char,
13291329
length: i32,
13301330
) -> status_t;
1331+
13311332
pub fn get_cpuid(info: *mut cpuid_info, eaxRegister: u32, cpuNum: u32) -> status_t;
13321333
}
13331334

src/unix/linux_like/android/b32/arm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ s_no_extra_traits! {
4848
pub uc_mcontext: mcontext_t,
4949
pub uc_sigmask__c_anonymous_union: __c_anonymous_uc_sigmask,
5050
/* The kernel adds extra padding after uc_sigmask to match
51-
* glibc sigset_t on ARM. */
51+
* glibc sigset_t on ARM. */
5252
__padding: [c_char; 120],
5353
__align: [::c_longlong; 0],
5454
uc_regspace: [::c_ulong; 128],

src/unix/linux_like/android/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4153,6 +4153,8 @@ extern "C" {
41534153
pub fn fflush_unlocked(stream: *mut ::FILE) -> ::c_int;
41544154
pub fn fgets_unlocked(buf: *mut ::c_char, size: ::c_int, stream: *mut ::FILE) -> *mut ::c_char;
41554155

4156+
pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int;
4157+
41564158
pub fn memfd_create(name: *const ::c_char, flags: ::c_uint) -> ::c_int;
41574159
pub fn renameat2(
41584160
olddirfd: ::c_int,
@@ -4168,8 +4170,6 @@ extern "C" {
41684170
mask: ::c_uint,
41694171
statxbuf: *mut statx,
41704172
) -> ::c_int;
4171-
4172-
pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int;
41734173
}
41744174

41754175
cfg_if! {

0 commit comments

Comments
 (0)