about summary refs log tree commit diff
path: root/src/libstd/ffi
AgeCommit message (Collapse)AuthorLines
2020-04-15big-O notation: parenthesis, multiplication and backticksRalf Jung-2/+2
2020-04-06Forward OsStr::clone_into to the inner VecJosh Stone-2/+1
Despite OS differences, they're all just `Vec<u8>` inside, so we can just forward `clone_into` calls to that optimized implementation.
2020-04-06Implement ToOwned::clone_into for CStrJosh Stone-0/+17
It can try to keep its allocation by converting the inner `Box` to `Vec`, using `clone_into` on the bytes, then convert back to `Box`.
2020-03-28add tracking issueTyPR124-6/+6
2020-03-28move doc links for consistencyTyPR124-4/+4
2020-03-28remove unnecessary commentsTyPR124-2/+0
2020-03-28ascii methods on osstrTyPR124-0/+143
2020-03-20add comment about maintaining OsStr encodingTyPR124-0/+2
2020-03-16add comments about safetyTyPR124-0/+4
2020-03-16allowing getting &mut OsStr from OsStringTyPR124-0/+21
2020-02-15Rollup merge of #64069 - ↵Dylan DPC-0/+27
danielhenrymantilla:feature/cstring_from_vec_of_nonzerou8, r=KodrAus Added From<Vec<NonZeroU8>> for CString Added a `From<Vec<NonZeroU8>>` `impl` for `CString` # Rationale - `CString::from_vec_unchecked` is a subtle function, that makes `unsafe` code harder to audit when the generated `Vec`'s creation is non-trivial. This `impl` allows to write safer `unsafe` code thanks to the very explicit semantics of the `Vec<NonZeroU8>` type. - One such situation is when trying to `.read()` a `CString`, see issue #59229. - this lead to a PR: #59314, that was closed for being too specific / narrow (it only targetted being able to `.read()` a `CString`, when this pattern could have been generalized). - the issue suggested another route, based on `From<Vec<NonZeroU8>>`, which is indeed a less general and more concise code pattern. - quoting @shnatsel: - > For me the main thing about making this safe is simplifying auditing - people have spent like an hour looking at just this one unsafe block in libflate because it's not clear what exactly is unchecked, so you have to look it up when auditing anyway. This has distracted us from much more serious memory safety issues the library had. Having this trivial impl in stdlib would turn this into safe code with compiler more or less guaranteeing that it's fine, and save anyone auditing the code a whole lot of time.
2020-02-04Added From<Vec<NonZeroU8>> for CStringDaniel Henry-Mantilla-0/+27
Updated tracking issue number Added safeguards for transmute_vec potentially being factored out elsewhere Clarified comment about avoiding mem::forget Removed unneeded unstable guard Added back a stability annotation for CI Minor documentation improvements Thanks to @Centril's code review Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com> Improved layout checks, type annotations and removed unaccurate comment Removed unnecessary check on array layout Adapt the stability annotation to the new 1.41 milestone Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com> Simplify the implementation. Use `Vec::into_raw_parts` instead of a manual implementation of `Vec::transmute`. If `Vec::into_raw_parts` uses `NonNull` instead, then the code here will need to be adjusted to take it into account (issue #65816) Reduce the whitespace of safety comments
2020-01-10inline `impl AsRef<OsStr> for OsString`Lzu Tao-0/+1
2020-01-10Inline to make OsStr::is_empty zero costLzu Tao-0/+1
2020-01-07Remove insignificant notes from CStr documentationDavid Tolnay-10/+0
These notes are about a distinction that is not going to be observable in the API. Whether or not the UTF-8 check knows the string length ahead of time, these methods require linear time.
2019-12-24Deprecate Error::description for realDavid Tolnay-0/+5
`description` has been documented as soft-deprecated since 1.27.0 (17 months ago). There is no longer any reason to call it or implement it. This commit: - adds #[rustc_deprecated(since = "1.41.0")] to Error::description; - moves description (and cause, which is also deprecated) below the source and backtrace methods in the Error trait; - reduces documentation of description and cause to take up much less vertical real estate in rustdocs, while preserving the example that shows how to render errors without needing to call description; - removes the description function of all *currently unstable* Error impls in the standard library; - marks #[allow(deprecated)] the description function of all *stable* Error impls in the standard library; - replaces miscellaneous uses of description in example code and the compiler.
2019-12-22Format the worldMark Rousskov-54/+77
2019-12-21Require issue = "none" over issue = "0" in unstable attributesRoss MacArthur-1/+1
2019-12-18Propagate cfg bootstrapMark Rousskov-3/+2
2019-12-13Require stable/unstable annotations for the constness of all stable ↵Oliver Scherer-1/+3
functions with a `const` modifier
2019-12-09inline some common methods on OsStrLzu Tao-0/+8
2019-11-29Format libstd with rustfmtDavid Tolnay-8/+10
This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *that are not involved in any currently open PR* to minimize merge conflicts. THe list of files involved in open PRs was determined by querying GitHub's GraphQL API with this script: https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8 With the list of files from the script in outstanding_files, the relevant commands were: $ find src/libstd -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libstd. To confirm no funny business: $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference
2019-10-29doc: use new feature gate for c_void typeLzu Tao-1/+1
2019-10-18Avoid realloc in `CString::new`Shotaro Yamada-1/+25
2019-10-13Implement Error::source on IntoStringErrorLinus Färnstrand-1/+1
IntoStringError only implemented Error::cause, which is deprecated. This implemements Error::source instead. Error::cause will still work as before, thanks to the default implementation.
2019-09-14Rollup merge of #64203 - alexreg:rush-pr-2, r=centrilMazdak Farrokhzad-1/+1
A few cosmetic improvements to code & comments in liballoc and libcore Factored out from hacking on rustc for work on the REPL. r? @Centril
2019-09-09Update added backticks around a function callhman523-1/+1
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-09-09Fixed documentation within c_str::from_ptrhman523-2/+4
2019-09-06A few cosmetic improvements to code & comments in liballoc and libcoreAlexander Regueiro-1/+1
2019-08-22Fix for 7e13679.Tomasz Różański-2/+2
2019-08-22Change variables names to be more consistent.Tomasz Różański-16/+16
Changed all instances of `c_str` into `cstr` in the documentation examples. This is also consistent with the module source code.
2019-08-22Fix punctuation.Tomasz Różański-1/+1
2019-08-22Remove redundant `mut`.Tomasz Różański-1/+1
2019-08-11Rollup merge of #61969 - MikailBag:master, r=CentrilMark Rousskov-0/+12
Add #[repr(transparent)] for several types In some functions, types mentioned in this PR are transmuted into their inner value. Example for `PathBuf`: https://github.com/rust-lang/rust/blob/master/src/libstd/path.rs#L1132. This PR adds `#[repr(transparent)]` to those types, so their correct behavior doesn't depend on compiler details. (As far as I understand, currently that line, converting `PathBuf` to `Vec<u8>`, is UB).
2019-08-09Add FIXME-s that some types should be transparentMikail Bagishov-0/+12
2019-08-02Remove extraneous {} in use stmts in doc comments.Bruce Mitchener-2/+2
2019-07-14Auto merge of #62610 - Stargateur:fix-miri-error-cstring-into_inner, r=RalfJungbors-5/+6
Fix miri error in into_inner() of CString Fix #62553 I choice to not transmute because I think it's more unsafe and in case the structure change this code should always work. r? @RalfJung
2019-07-13Fix miri error in into_inner() of CStringAntoine PLASKOWSKI-5/+6
2019-07-07Add missing urls for osstrGuillaume Gomez-3/+4
2019-06-17Expose `VaListImpl` as the Rust equivalent of `__va_list_tag` and implement ↵Andrei Homescu-1/+1
Clone for it.
2019-05-20Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPCMazdak Farrokhzad-0/+2
Fix intra-doc link resolution failure on re-exporting libstd Currently, re-exporting libstd items as below will [occur a lot of failures](https://gist.github.com/taiki-e/e33e0e8631ef47f65a74a3b69f456366). ```rust pub use std::*; ``` Until the underlying issue (#56922) fixed, we can fix that so they don't propagate to downstream crates. Related: https://github.com/rust-lang/rust/pull/56941 (That PR fixed failures that occur when re-exporting from libcore to libstd.) r? @QuietMisdreavus
2019-05-04Fix intra-doc link resolution failure on re-exporting libstdTaiki Endo-0/+2
2019-05-01as_ptr returns a read-only pointerRalf Jung-2/+7
2019-04-04Mark unix::ffi::OsStrExt methods as inlineKonrad Borowski-0/+1
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-11/+11
2019-03-09Use lifetime contravariance to elide more lifetimes in core+alloc+stdScott McMurray-14/+14
2019-02-28libstd => 2018Taiki Endo-34/+34
2019-02-20Rollup merge of #58553 - scottmcm:more-ihle, r=Centrilkennytm-4/+4
Use more impl header lifetime elision Inspired by seeing explicit lifetimes on these two: - https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator - https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore. Most of the changes in here fall into two big categories: - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm). I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-17Use more impl header lifetime elisionScott McMurray-4/+4
There are two big categories of changes in here - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-10libs: doc commentsAlexander Regueiro-2/+2