about summary refs log tree commit diff
path: root/src/libstd/ffi
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-3333/+0
2020-07-18Update stability attribute for CStr indexingDavid Tolnay-1/+1
2020-07-18impl Index<RangeFrom<usize>> for CStr1011X-0/+38
2020-06-15Rollup merge of #73139 - poliorcetics:cstring-from-vec-with-nul, r=dtolnayRalf Jung-6/+183
Add methods to go from a nul-terminated Vec<u8> to a CString Fixes #73100. Doc tests have been written and the documentation on the error type updated too. I used `#[stable(feature = "cstring_from_vec_with_nul", since = "1.46.0")]` but I don't know if the version is correct.
2020-06-14Update to use the new error type and correctly compile the doc testsAlexis Bourget-16/+21
2020-06-14Add a new error type for the new methodAlexis Bourget-0/+98
2020-06-14Removing the TryFrom implAlexis Bourget-14/+0
2020-06-11Fix the link in the TryFrom implAlexis Bourget-1/+1
2020-06-11Add a TryFrom<Vec<u8>> impl that mirror from_vec_with_nulAlexis Bourget-0/+14
2020-06-09Move to unstable, linking the issueAlexis Bourget-2/+2
2020-06-08Add methods to go from a nul-terminated Vec<u8> to a CString, checked and ↵Alexis Bourget-3/+77
unchecked. Doc tests have been written and the documentation on the error type updated too.
2020-06-03Added a warning to CString::into_raw tooAlexis Bourget-0/+5
2020-06-03Added the documentation about length to CString::from_rawAlexis Bourget-0/+6
2020-05-19Auto merge of #71447 - cuviper:unsized_cow, r=dtolnaybors-0/+22
impl From<Cow> for Box, Rc, and Arc These forward `Borrowed`/`Owned` values to existing `From` impls. - `Box<T>` is a fundamental type, so it would be a breaking change to add a blanket impl. Therefore, `From<Cow>` is only implemented for `[T]`, `str`, `CStr`, `OsStr`, and `Path`. - For `Rc<T>` and `Arc<T>`, `From<Cow>` is implemented for everything that implements `From` the borrowed and owned types separately.
2020-04-29Implement FromStr for OsStringMike Hommey-0/+10
2020-04-22impl From<Cow> for boxed slices and stringsJosh Stone-0/+22
These forward `Borrowed`/`Owned` values to existing `Box::from` impls. - `From<Cow<'_, [T]>> for Box<[T]>` - `From<Cow<'_, str>> for Box<str>` - `From<Cow<'_, CStr>> for Box<CStr>` - `From<Cow<'_, OsStr>> for Box<OsStr>` - `From<Cow<'_, Path>> for Box<Path>`
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).