Skip to content

Commit

Permalink
Merge #1332
Browse files Browse the repository at this point in the history
1332: Suppress temporary libc deprecations r=asomers a=tamird

See individual commits.

This PR is an alternative to #1329.

@asomers 

Co-authored-by: Tamir Duberstein <[email protected]>
  • Loading branch information
bors[bot] and tamird authored Nov 16, 2020
2 parents 5d2a8c2 + b373f2f commit cde6e3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,12 +847,13 @@ impl<'a> ControlMessage<'a> {
}
#[cfg(any(target_os = "android", target_os = "linux"))]
ControlMessage::AlgSetIv(iv) => {
#[allow(deprecated)] // https://github.com/rust-lang/libc/issues/1501
let af_alg_iv = libc::af_alg_iv {
ivlen: iv.len() as u32,
iv: [0u8; 0],
};

let size = mem::size_of::<libc::af_alg_iv>();
let size = mem::size_of_val(&af_alg_iv);

unsafe {
ptr::copy_nonoverlapping(
Expand Down Expand Up @@ -915,7 +916,7 @@ impl<'a> ControlMessage<'a> {
}
#[cfg(any(target_os = "android", target_os = "linux"))]
ControlMessage::AlgSetIv(iv) => {
mem::size_of::<libc::af_alg_iv>() + iv.len()
mem::size_of_val(&iv) + iv.len()
},
#[cfg(any(target_os = "android", target_os = "linux"))]
ControlMessage::AlgSetOp(op) => {
Expand Down
9 changes: 9 additions & 0 deletions src/sys/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{cmp, fmt, ops};
use std::time::Duration;
use std::convert::From;
use libc::{c_long, timespec, timeval};
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
pub use libc::{time_t, suseconds_t};

pub trait TimeValLike: Sized {
Expand Down Expand Up @@ -69,6 +70,7 @@ impl From<timespec> for TimeSpec {

impl From<Duration> for TimeSpec {
fn from(duration: Duration) -> Self {
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeSpec(timespec {
tv_sec: duration.as_secs() as time_t,
tv_nsec: duration.subsec_nanos() as c_long
Expand Down Expand Up @@ -117,6 +119,7 @@ impl TimeValLike for TimeSpec {
fn seconds(seconds: i64) -> TimeSpec {
assert!(seconds >= TS_MIN_SECONDS && seconds <= TS_MAX_SECONDS,
"TimeSpec out of bounds; seconds={}", seconds);
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeSpec(timespec {tv_sec: seconds as time_t, tv_nsec: 0 })
}

Expand All @@ -143,6 +146,7 @@ impl TimeValLike for TimeSpec {
let (secs, nanos) = div_mod_floor_64(nanoseconds, NANOS_PER_SEC);
assert!(secs >= TS_MIN_SECONDS && secs <= TS_MAX_SECONDS,
"TimeSpec out of bounds");
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeSpec(timespec {tv_sec: secs as time_t,
tv_nsec: nanos as c_long })
}
Expand Down Expand Up @@ -179,6 +183,7 @@ impl TimeSpec {
}
}

#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
pub fn tv_sec(&self) -> time_t {
self.0.tv_sec
}
Expand Down Expand Up @@ -315,6 +320,7 @@ impl TimeValLike for TimeVal {
fn seconds(seconds: i64) -> TimeVal {
assert!(seconds >= TV_MIN_SECONDS && seconds <= TV_MAX_SECONDS,
"TimeVal out of bounds; seconds={}", seconds);
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeVal(timeval {tv_sec: seconds as time_t, tv_usec: 0 })
}

Expand All @@ -332,6 +338,7 @@ impl TimeValLike for TimeVal {
let (secs, micros) = div_mod_floor_64(microseconds, MICROS_PER_SEC);
assert!(secs >= TV_MIN_SECONDS && secs <= TV_MAX_SECONDS,
"TimeVal out of bounds");
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeVal(timeval {tv_sec: secs as time_t,
tv_usec: micros as suseconds_t })
}
Expand All @@ -344,6 +351,7 @@ impl TimeValLike for TimeVal {
let (secs, micros) = div_mod_floor_64(microseconds, MICROS_PER_SEC);
assert!(secs >= TV_MIN_SECONDS && secs <= TV_MAX_SECONDS,
"TimeVal out of bounds");
#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
TimeVal(timeval {tv_sec: secs as time_t,
tv_usec: micros as suseconds_t })
}
Expand Down Expand Up @@ -380,6 +388,7 @@ impl TimeVal {
}
}

#[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
pub fn tv_sec(&self) -> time_t {
self.0.tv_sec
}
Expand Down

0 comments on commit cde6e3e

Please sign in to comment.