Skip to content

Commit cd57a93

Browse files
committed
Use ptr::addr_of when available
1 parent bbbb5d8 commit cd57a93

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ fn main() {
7272
println!("cargo:rustc-cfg=libc_cfg_target_vendor");
7373
}
7474

75+
if rustc_minor_ver >= 51 || rustc_dep_of_std {
76+
println!("cargo:rustc-cfg=libc_ptr_addr_of");
77+
}
78+
7579
// #[thread_local] is currently unstable
7680
if rustc_dep_of_std {
7781
println!("cargo:rustc-cfg=libc_thread_local");

src/macros.rs

+16
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,19 @@ macro_rules! deprecated_mach {
341341
)*
342342
}
343343
}
344+
345+
#[allow(unused_macros)]
346+
#[cfg(not(libc_ptr_addr_of))]
347+
macro_rules! ptr_addr_of {
348+
($place:expr) => {
349+
&$place
350+
};
351+
}
352+
353+
#[allow(unused_macros)]
354+
#[cfg(libc_ptr_addr_of)]
355+
macro_rules! ptr_addr_of {
356+
($place:expr) => {
357+
::core::ptr::addr_of!($place)
358+
};
359+
}

src/wasi.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,12 @@ pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE;
352352
pub const _SC_IOV_MAX: c_int = 60;
353353
pub const _SC_SYMLOOP_MAX: c_int = 173;
354354

355-
pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(&_CLOCK_MONOTONIC) };
356-
pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = unsafe { clockid_t(&_CLOCK_PROCESS_CPUTIME_ID) };
357-
pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(&_CLOCK_REALTIME) };
358-
pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = unsafe { clockid_t(&_CLOCK_THREAD_CPUTIME_ID) };
355+
pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_MONOTONIC)) };
356+
pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t =
357+
unsafe { clockid_t(ptr_addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) };
358+
pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_REALTIME)) };
359+
pub static CLOCK_THREAD_CPUTIME_ID: clockid_t =
360+
unsafe { clockid_t(ptr_addr_of!(_CLOCK_THREAD_CPUTIME_ID)) };
359361

360362
#[cfg_attr(
361363
feature = "rustc-dep-of-std",

0 commit comments

Comments
 (0)