diff options
author | Noa <33094578+coolreader18@users.noreply.github.com> | 2021-11-01 19:58:12 -0500 |
---|---|---|
committer | Noa <33094578+coolreader18@users.noreply.github.com> | 2021-11-01 19:58:12 -0500 |
commit | cd57a938cfab04c38c38bb2d5d8be49238c3d43f (patch) | |
tree | d21431d5ad8cb2115cdda341daae5a3bcd58a35b /src | |
parent | bbbb5d8b0d683a699fd33ff2e7b7e2a670002985 (diff) | |
download | rust-libc-cd57a938cfab04c38c38bb2d5d8be49238c3d43f.tar.gz |
Use ptr::addr_of when available
Diffstat (limited to 'src')
-rw-r--r-- | src/macros.rs | 16 | ||||
-rw-r--r-- | src/wasi.rs | 10 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/macros.rs b/src/macros.rs index 1871cfafda..d52c4ad81e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -341,3 +341,19 @@ macro_rules! deprecated_mach { )* } } + +#[allow(unused_macros)] +#[cfg(not(libc_ptr_addr_of))] +macro_rules! ptr_addr_of { + ($place:expr) => { + &$place + }; +} + +#[allow(unused_macros)] +#[cfg(libc_ptr_addr_of)] +macro_rules! ptr_addr_of { + ($place:expr) => { + ::core::ptr::addr_of!($place) + }; +} diff --git a/src/wasi.rs b/src/wasi.rs index a41ec47696..7d49450d09 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -352,10 +352,12 @@ pub const _SC_PAGE_SIZE: ::c_int = _SC_PAGESIZE; pub const _SC_IOV_MAX: c_int = 60; pub const _SC_SYMLOOP_MAX: c_int = 173; -pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(&_CLOCK_MONOTONIC) }; -pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = unsafe { clockid_t(&_CLOCK_PROCESS_CPUTIME_ID) }; -pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(&_CLOCK_REALTIME) }; -pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = unsafe { clockid_t(&_CLOCK_THREAD_CPUTIME_ID) }; +pub static CLOCK_MONOTONIC: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_MONOTONIC)) }; +pub static CLOCK_PROCESS_CPUTIME_ID: clockid_t = + unsafe { clockid_t(ptr_addr_of!(_CLOCK_PROCESS_CPUTIME_ID)) }; +pub static CLOCK_REALTIME: clockid_t = unsafe { clockid_t(ptr_addr_of!(_CLOCK_REALTIME)) }; +pub static CLOCK_THREAD_CPUTIME_ID: clockid_t = + unsafe { clockid_t(ptr_addr_of!(_CLOCK_THREAD_CPUTIME_ID)) }; #[cfg_attr( feature = "rustc-dep-of-std", |