From c6435759b5039fa6483aa5a8775fc7a11db0154f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 19 Mar 2020 07:46:50 +0100 Subject: add basic support of OsStrExt for HermitCore this patch increases the compatibility to other operating systems --- src/libstd/os/mod.rs | 2 +- src/libstd/sys/hermit/ext/ffi.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/libstd/sys/hermit/ext/mod.rs | 14 ++++++++++++++ src/libstd/sys/hermit/mod.rs | 1 + 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/libstd/sys/hermit/ext/ffi.rs create mode 100644 src/libstd/sys/hermit/ext/mod.rs (limited to 'src/libstd') diff --git a/src/libstd/os/mod.rs b/src/libstd/os/mod.rs index 91e37ed833a..0fa4a1d2353 100644 --- a/src/libstd/os/mod.rs +++ b/src/libstd/os/mod.rs @@ -24,7 +24,7 @@ cfg_if::cfg_if! { // If we're not documenting libstd then we just expose the main modules // as we otherwise would. - #[cfg(any(target_os = "redox", unix, target_os = "vxworks"))] + #[cfg(any(target_os = "redox", unix, target_os = "vxworks", target_os = "hermit"))] #[stable(feature = "rust1", since = "1.0.0")] pub use crate::sys::ext as unix; diff --git a/src/libstd/sys/hermit/ext/ffi.rs b/src/libstd/sys/hermit/ext/ffi.rs new file mode 100644 index 00000000000..07b59a02556 --- /dev/null +++ b/src/libstd/sys/hermit/ext/ffi.rs @@ -0,0 +1,38 @@ +//! HermitCore-specific extension to the primitives in the `std::ffi` module +//! +//! # Examples +//! +//! ``` +//! use std::ffi::OsString; +//! use std::os::hermit::ffi::OsStringExt; +//! +//! let bytes = b"foo".to_vec(); +//! +//! // OsStringExt::from_vec +//! let os_string = OsString::from_vec(bytes); +//! assert_eq!(os_string.to_str(), Some("foo")); +//! +//! // OsStringExt::into_vec +//! let bytes = os_string.into_vec(); +//! assert_eq!(bytes, b"foo"); +//! ``` +//! +//! ``` +//! use std::ffi::OsStr; +//! use std::os::hermit::ffi::OsStrExt; +//! +//! let bytes = b"foo"; +//! +//! // OsStrExt::from_bytes +//! let os_str = OsStr::from_bytes(bytes); +//! assert_eq!(os_str.to_str(), Some("foo")); +//! +//! // OsStrExt::as_bytes +//! let bytes = os_str.as_bytes(); +//! assert_eq!(bytes, b"foo"); +//! ``` + +#![stable(feature = "rust1", since = "1.0.0")] + +#[stable(feature = "rust1", since = "1.0.0")] +pub use crate::sys_common::os_str_bytes::*; diff --git a/src/libstd/sys/hermit/ext/mod.rs b/src/libstd/sys/hermit/ext/mod.rs new file mode 100644 index 00000000000..ea87d0ad2c9 --- /dev/null +++ b/src/libstd/sys/hermit/ext/mod.rs @@ -0,0 +1,14 @@ +#![stable(feature = "rust1", since = "1.0.0")] +#![allow(missing_docs)] + +pub mod ffi; + +/// A prelude for conveniently writing platform-specific code. +/// +/// Includes all extension traits, and some important type definitions. +#[stable(feature = "rust1", since = "1.0.0")] +pub mod prelude { + #[doc(no_inline)] + #[stable(feature = "rust1", since = "1.0.0")] + pub use super::ffi::{OsStrExt, OsStringExt}; +} diff --git a/src/libstd/sys/hermit/mod.rs b/src/libstd/sys/hermit/mod.rs index 1e4a53abdc7..362461ce97a 100644 --- a/src/libstd/sys/hermit/mod.rs +++ b/src/libstd/sys/hermit/mod.rs @@ -21,6 +21,7 @@ pub mod args; pub mod cmath; pub mod condvar; pub mod env; +pub mod ext; pub mod fast_thread_local; pub mod fd; pub mod fs; -- cgit 1.4.1-3-g733a5 From 87cdfb6e71b0ebe3e41e04d8840a20d7428197be Mon Sep 17 00:00:00 2001 From: John Kåre Alsaker Date: Mon, 30 Mar 2020 14:36:28 +0200 Subject: Add inline attributes for functions used in the query system --- src/liballoc/slice.rs | 1 + src/librustc_query_system/dep_graph/graph.rs | 1 + src/librustc_query_system/query/plumbing.rs | 1 + src/libstd/thread/local.rs | 1 + 4 files changed, 4 insertions(+) (limited to 'src/libstd') diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index d8fc1faca3a..7ec99e0368e 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -141,6 +141,7 @@ mod hack { use crate::string::ToString; use crate::vec::Vec; + #[inline] pub fn into_vec(b: Box<[T]>) -> Vec { unsafe { let len = b.len(); diff --git a/src/librustc_query_system/dep_graph/graph.rs b/src/librustc_query_system/dep_graph/graph.rs index 73983e1644c..fa2b51058a3 100644 --- a/src/librustc_query_system/dep_graph/graph.rs +++ b/src/librustc_query_system/dep_graph/graph.rs @@ -1112,6 +1112,7 @@ impl DepNodeColorMap { DepNodeColorMap { values: (0..size).map(|_| AtomicU32::new(COMPRESSED_NONE)).collect() } } + #[inline] fn get(&self, index: SerializedDepNodeIndex) -> Option { match self.values[index].load(Ordering::Acquire) { COMPRESSED_NONE => None, diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index b371a914c6f..9da13f23664 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -51,6 +51,7 @@ pub struct QueryState { } impl QueryState { + #[inline] pub(super) fn get_lookup<'tcx>( &'tcx self, key: &C::Key, diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 1dd942e252f..29e99c0afd2 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -253,6 +253,7 @@ impl LocalKey { /// This function will still `panic!()` if the key is uninitialized and the /// key's initializer panics. #[stable(feature = "thread_local_try_with", since = "1.26.0")] + #[inline] pub fn try_with(&'static self, f: F) -> Result where F: FnOnce(&T) -> R, -- cgit 1.4.1-3-g733a5