diff options
| author | Alan Somers <asomers@gmail.com> | 2016-04-06 02:22:18 +0000 |
|---|---|---|
| committer | Alan Somers <asomers@gmail.com> | 2016-04-06 02:22:18 +0000 |
| commit | 1e9ffb899195291c6682c244f2d485b6121a7dc4 (patch) | |
| tree | 39f12484dfe0fb508929497ba163824cdc1f9518 /src/libstd | |
| parent | 112463a3b1b1fc30c8f407e50e9ef692034ccb37 (diff) | |
| parent | 241a9d0ddf99fd40d273c615e9b1e8ce6052d94a (diff) | |
| download | rust-1e9ffb899195291c6682c244f2d485b6121a7dc4.tar.gz rust-1e9ffb899195291c6682c244f2d485b6121a7dc4.zip | |
Merge github.com:rust-lang/rust
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 36 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/weak.rs | 8 | ||||
| -rw-r--r-- | src/libstd/time/duration.rs | 5 |
4 files changed, 42 insertions, 9 deletions
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index c332d6035ee..f8b2d4dd232 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -85,12 +85,46 @@ pub fn init() { #[cfg(not(target_os = "nacl"))] unsafe fn reset_sigpipe() { - assert!(libc::signal(libc::SIGPIPE, libc::SIG_IGN) != !0); + assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0); } #[cfg(target_os = "nacl")] unsafe fn reset_sigpipe() {} } +// Currently the minimum supported Android version of the standard library is +// API level 18 (android-18). Back in those days [1] the `signal` function was +// just an inline wrapper around `bsd_signal`, but starting in API level +// android-20 the `signal` symbols was introduced [2]. Finally, in android-21 +// the API `bsd_signal` was removed [3]. +// +// Basically this means that if we want to be binary compatible with multiple +// Android releases (oldest being 18 and newest being 21) then we need to check +// for both symbols and not actually link against either. +// +// Note that if we're not on android we just link against the `android` symbol +// itself. +// +// [1]: https://chromium.googlesource.com/android_tools/+/20ee6d20/ndk/platforms +// /android-18/arch-arm/usr/include/signal.h +// [2]: https://chromium.googlesource.com/android_tools/+/fbd420/ndk_experimental +// /platforms/android-20/arch-arm +// /usr/include/signal.h +// [3]: https://chromium.googlesource.com/android_tools/+/20ee6d/ndk/platforms +// /android-21/arch-arm/usr/include/signal.h +#[cfg(target_os = "android")] +unsafe fn signal(signum: libc::c_int, + handler: libc::sighandler_t) -> libc::sighandler_t { + weak!(fn signal(libc::c_int, libc::sighandler_t) -> libc::sighandler_t); + weak!(fn bsd_signal(libc::c_int, libc::sighandler_t) -> libc::sighandler_t); + + let f = signal.get().or_else(|| bsd_signal.get()); + let f = f.expect("neither `signal` nor `bsd_signal` symbols found"); + f(signum, handler) +} + +#[cfg(not(target_os = "android"))] +pub use libc::signal; + pub fn decode_error_kind(errno: i32) -> ErrorKind { match errno as libc::c_int { libc::ECONNREFUSED => ErrorKind::ConnectionRefused, diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 6f56f3ade06..270c2096b2c 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -393,7 +393,7 @@ impl Command { t!(cvt(libc::sigemptyset(&mut set))); t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, ptr::null_mut()))); - let ret = libc::signal(libc::SIGPIPE, libc::SIG_DFL); + let ret = super::signal(libc::SIGPIPE, libc::SIG_DFL); if ret == libc::SIG_ERR { return io::Error::last_os_error() } diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs index e6f85c08d12..99ab8741159 100644 --- a/src/libstd/sys/unix/weak.rs +++ b/src/libstd/sys/unix/weak.rs @@ -75,11 +75,5 @@ unsafe fn fetch(name: &str) -> usize { Ok(cstr) => cstr, Err(..) => return 0, }; - let lib = libc::dlopen(0 as *const _, libc::RTLD_LAZY); - if lib.is_null() { - return 0 - } - let ret = libc::dlsym(lib, name.as_ptr()) as usize; - libc::dlclose(lib); - return ret + libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 945eb6a42e5..8a50f07e6d8 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -52,6 +52,7 @@ impl Duration { /// If the nanoseconds is greater than 1 billion (the number of nanoseconds /// in a second), then it will carry over into the seconds provided. #[stable(feature = "duration", since = "1.3.0")] + #[inline] pub fn new(secs: u64, nanos: u32) -> Duration { let secs = secs + (nanos / NANOS_PER_SEC) as u64; let nanos = nanos % NANOS_PER_SEC; @@ -60,12 +61,14 @@ impl Duration { /// Creates a new `Duration` from the specified number of seconds. #[stable(feature = "duration", since = "1.3.0")] + #[inline] pub fn from_secs(secs: u64) -> Duration { Duration { secs: secs, nanos: 0 } } /// Creates a new `Duration` from the specified number of milliseconds. #[stable(feature = "duration", since = "1.3.0")] + #[inline] pub fn from_millis(millis: u64) -> Duration { let secs = millis / MILLIS_PER_SEC; let nanos = ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI; @@ -77,6 +80,7 @@ impl Duration { /// The extra precision represented by this duration is ignored (e.g. extra /// nanoseconds are not represented in the returned value). #[stable(feature = "duration", since = "1.3.0")] + #[inline] pub fn as_secs(&self) -> u64 { self.secs } /// Returns the nanosecond precision represented by this duration. @@ -85,6 +89,7 @@ impl Duration { /// represented by nanoseconds. The returned number always represents a /// fractional portion of a second (e.g. it is less than one billion). #[stable(feature = "duration", since = "1.3.0")] + #[inline] pub fn subsec_nanos(&self) -> u32 { self.nanos } } |
