about summary refs log tree commit diff
path: root/src/libstd/ffi/c_str.rs
AgeCommit message (Collapse)AuthorLines
2017-06-20Add doc example for `CStr::to_bytes_with_nul`.Corey Farwell-0/+9
2017-06-20Add doc example for `CStr::to_bytes`.Corey Farwell-0/+9
2017-06-20Mark smaller CStr and CString functions as #[inline]Alexander Bulaev-0/+15
2017-06-05Add doc example for `CString::as_bytes`.Corey Farwell-0/+10
2017-06-05Add doc example for `CString::as_bytes_with_nul`.Corey Farwell-0/+10
2017-06-05Add doc example for `CString::into_bytes_with_nul`.Corey Farwell-0/+10
2017-06-05Add doc example for `CString::into_bytes`.Corey Farwell-0/+10
2017-06-05Add doc example for `CString::into_raw`.Corey Farwell-0/+20
2017-05-22Add missing links for CStr and CStringGuillaume Gomez-30/+74
2017-05-20Correct some stability versionsOliver Middleton-2/+2
These were found by running tidy on stable versions of rust and finding features stabilised with the wrong version numbers.
2017-05-09Remove wrong or outdated info from CString docs.Matt Brubeck-6/+4
2017-04-09Auto merge of #41095 - clarcharr:as_extras, r=alexcrichtonbors-0/+6
Add as_c_str Again, tying up some consistencies with `CString`.
2017-04-07Add as_c_str.Clar Charr-0/+6
2017-04-06Remove some CStr transmutes.Clar Charr-2/+3
2017-03-15Auto merge of #40009 - clarcharr:box_to_buf, r=alexcrichtonbors-7/+26
Leftovers from #39594; From<Box> impls These are a few more impls that follow the same reasoning as those from #39594. What's included: * `From<Box<str>> for String` * `From<Box<[T]>> for Vec<T>` * `From<Box<CStr>> for CString` * `From<Box<OsStr>> for OsString` * `From<Box<Path>> for PathBuf` * `Into<Box<str>> for String` * `Into<Box<[T]>> for Vec<T>` * `Into<Box<CStr>> for CString` * `Into<Box<OsStr>> for OsString` * `Into<Box<Path>> for PathBuf` * `<Box<CStr>>::into_c_string` * `<Box<OsStr>>::into_os_string` * `<Box<Path>>::into_path_buf` * Tracking issue for latter three methods + three from previous PR. Currently, the opposite direction isn't doable with `From` (only `Into`) because of the separation between `liballoc` and `libcollections`. I'm holding off on those for a later PR.
2017-03-10Add From<Box<..>> implementations.Clar Charr-7/+26
2017-03-09Distinguish the ways `CStr::from_bytes_with_nul` can failTobias Bucher-6/+40
2017-02-21changed stability annotationslukaramu-2/+2
Changed stability annotations for the new Error and Display impls for std::ffi::FromBytesWithNulError as they aren't subject to stability the same way.
2017-02-19added Error and Display impl for std::ffi::FromBytesWithNulErrorlukaramu-0/+14
2017-02-14Conversions between CStr/OsStr/Path and boxes.Clar Charr-1/+41
2016-11-08Slightly optimise CStringOliver Middleton-1/+1
Avoid a reallocation in CString::from and CStr::to_owned.
2016-10-03std: Stabilize and deprecate APIs for 1.13Alex Crichton-3/+4
This commit is intended to be backported to the 1.13 branch, and works with the following APIs: Stabilized * `i32::checked_abs` * `i32::wrapping_abs` * `i32::overflowing_abs` * `RefCell::try_borrow` * `RefCell::try_borrow_mut` * `DefaultHasher` * `DefaultHasher::new` * `DefaultHasher::default` Deprecated * `BinaryHeap::push_pop` * `BinaryHeap::replace` * `SipHash13` * `SipHash24` * `SipHasher` - use `DefaultHasher` instead in the `std::collections::hash_map` module Closes #28147 Closes #34767 Closes #35057 Closes #35070
2016-09-26Remove CString drop test.Aleksey Kladov-1/+3
The test relies on the undefined behavior, and so may fail in some circumstances. This can be worked around by stubbing a memory allocator in the test, but it is a bit of work, and LLVM could still theoretically eliminate the write of the zero byte in release mode (which is intended). So let's just remove the test and mark the function as inline. It shouldn't be optimized away when inlined into the debug build of user's code.
2016-09-24Rollup merge of #36018 - durka:patch-28, r=steveklabnikGuillaume Gomez-2/+7
strengthen doc warning about CString::from_raw Saw unsound code using this function on IRC.
2016-09-22Rollup merge of #36423 - GuillaumeGomez:eq_impl, r=pnkfelixJonathan Turner-3/+3
Add missing Eq implementations Part of #36301.
2016-09-18Add missing Eq implementationsGuillaume Gomez-3/+3
2016-09-14add stronger warning to CString::from_rawAlex Burka-2/+7
2016-09-14Rollup merge of #36396 - athulappadan:Default-docs, r=blussGuillaume Gomez-0/+1
Documentation of what Default does for each type Addresses #36265 I haven't changed the following types due to doubts: 1)src/libstd/ffi/c_str.rs 2)src/libcore/iter/sources.rs 3)src/libcore/hash/mod.rs 4)src/libcore/hash/mod.rs 5)src/librustc/middle/privacy.rs r? @steveklabnik
2016-09-11Documentation for default types modifiedathulappadan-1/+1
2016-09-11Documentation of what does for each typeathulappadan-0/+1
2016-09-07Zero first byte of CString on dropAleksey Kladov-3/+25
This should prevent code like ``` let ptr = CString::new("hello").unwrap().as_ptr(); ``` from working by accident.
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-10/+2
2016-08-22Auto merge of #35871 - bluss:cstring-new, r=alexcrichtonbors-0/+1
cstring: avoid excessive growth just to 0-terminate Based on following what happens in CString::new("string literal"): 1. Using `Into<Vec<u8>>`, a Vec is allocated with capacity exactly equal to the string's input length. 2. By `v.push(0)`, the Vec is grown to twice capacity, since it was full. 3. By `v.into_boxed_slice()`, the Vec capacity is shrunk to fit the length again. If we use `.reserve_exact(1)` just before the push, then we avoid the capacity doubling that we're going to have to shrink anyway. Growing by just 1 byte means that the step (2) is less likely to have to move the memory to a larger allocation chunk, and that the step (3) does not have to reallocate. Addresses part of #35838
2016-08-21cstring: avoid excessive growth just to 0-terminateUlrik Sverdrup-0/+1
Based on following what happens in CString::new("string literal"): 1. Using `Into<Vec<u8>>`, a Vec is allocated with capacity exactly equal to the string's input length. 2. By `v.push(0)`, the Vec is grown to twice capacity, since it was full. 3. By `v.into_boxed_slice()`, the Vec capacity is shrunk to fit the length again. If we use `.reserve_exact(1)` just before the push, then we avoid the capacity doubling that we're going to have to shrink anyway. Growing by just 1 byte means that the step (2) is less likely to have to move the memory to a larger allocation chunk, and that the step (3) does not have to reallocate.
2016-08-12Add doc example for `std::ffi::CString::from_vec_unchecked`.Corey Farwell-0/+11
2016-08-08Remove unnecessary `main` functions in doc examples.Corey Farwell-17/+9
2016-08-06Add doc example for `std::ffi::NulError::into_vec`.Corey Farwell-0/+9
2016-08-02Add doc example for `std::ffi::NulError::nul_position`.Corey Farwell-0/+12
2016-06-19Document `CStr::as_ptr` dangers.Aleksey Kladov-0/+32
2016-05-24std: Stabilize APIs for the 1.10 releaseAlex Crichton-17/+20
This commit applies the FCP decisions made by the libs team for the 1.10 cycle, including both new stabilizations and deprecations. Specifically, the list of APIs is: Stabilized: * `os::windows::fs::OpenOptionsExt::access_mode` * `os::windows::fs::OpenOptionsExt::share_mode` * `os::windows::fs::OpenOptionsExt::custom_flags` * `os::windows::fs::OpenOptionsExt::attributes` * `os::windows::fs::OpenOptionsExt::security_qos_flags` * `os::unix::fs::OpenOptionsExt::custom_flags` * `sync::Weak::new` * `Default for sync::Weak` * `panic::set_hook` * `panic::take_hook` * `panic::PanicInfo` * `panic::PanicInfo::payload` * `panic::PanicInfo::location` * `panic::Location` * `panic::Location::file` * `panic::Location::line` * `ffi::CStr::from_bytes_with_nul` * `ffi::CStr::from_bytes_with_nul_unchecked` * `ffi::FromBytesWithNulError` * `fs::Metadata::modified` * `fs::Metadata::accessed` * `fs::Metadata::created` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange` * `sync::atomic::Atomic{Usize,Isize,Bool,Ptr}::compare_exchange_weak` * `collections::{btree,hash}_map::{Occupied,Vacant,}Entry::key` * `os::unix::net::{UnixStream, UnixListener, UnixDatagram, SocketAddr}` * `SocketAddr::is_unnamed` * `SocketAddr::as_pathname` * `UnixStream::connect` * `UnixStream::pair` * `UnixStream::try_clone` * `UnixStream::local_addr` * `UnixStream::peer_addr` * `UnixStream::set_read_timeout` * `UnixStream::set_write_timeout` * `UnixStream::read_timeout` * `UnixStream::write_Timeout` * `UnixStream::set_nonblocking` * `UnixStream::take_error` * `UnixStream::shutdown` * Read/Write/RawFd impls for `UnixStream` * `UnixListener::bind` * `UnixListener::accept` * `UnixListener::try_clone` * `UnixListener::local_addr` * `UnixListener::set_nonblocking` * `UnixListener::take_error` * `UnixListener::incoming` * RawFd impls for `UnixListener` * `UnixDatagram::bind` * `UnixDatagram::unbound` * `UnixDatagram::pair` * `UnixDatagram::connect` * `UnixDatagram::try_clone` * `UnixDatagram::local_addr` * `UnixDatagram::peer_addr` * `UnixDatagram::recv_from` * `UnixDatagram::recv` * `UnixDatagram::send_to` * `UnixDatagram::send` * `UnixDatagram::set_read_timeout` * `UnixDatagram::set_write_timeout` * `UnixDatagram::read_timeout` * `UnixDatagram::write_timeout` * `UnixDatagram::set_nonblocking` * `UnixDatagram::take_error` * `UnixDatagram::shutdown` * RawFd impls for `UnixDatagram` * `{BTree,Hash}Map::values_mut` * `<[_]>::binary_search_by_key` Deprecated: * `StaticCondvar` - this, and all other static synchronization primitives below, are usable today through the lazy-static crate on stable Rust today. Additionally, we'd like the non-static versions to be directly usable in a static context one day, so they're unlikely to be the final forms of the APIs in any case. * `CONDVAR_INIT` * `StaticMutex` * `MUTEX_INIT` * `StaticRwLock` * `RWLOCK_INIT` * `iter::Peekable::is_empty` Closes #27717 Closes #27720 cc #27784 (but encode methods still exist) Closes #30014 Closes #30425 Closes #30449 Closes #31190 Closes #31399 Closes #31767 Closes #32111 Closes #32281 Closes #32312 Closes #32551 Closes #33018
2016-05-05Add `Default` implementation for `&CStr` and `CString`Tobias Bucher-0/+16
2016-03-22try! -> ?Jorge Aparicio-2/+2
Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry
2016-02-23CStr::from_bytes_with_nul testsarcnmx-0/+27
2016-02-23Link cstr from_bytes to tracking issuearcnmx-5/+5
2016-02-23Rename CStr::from_bytes to from_bytes_with_nularcnmx-5/+5
2016-02-23CStr::from_bytesarcnmx-0/+51
2016-01-27Fix formatting in documentation of `ffi::CString`Dirk Gadsden-2/+2
2016-01-24Add section about memory safety to `ffi::CString` documentationDirk Gadsden-3/+15
Also a minor language tweak to the documentation of the `ffi::CString::from_raw` function.
2016-01-20Remove leftover import of `std::str` in doc testAndrea Bedini-1/+0
2016-01-19Improve CStr::from_ptr example in docsAndrea Bedini-2/+1
Documentation of `CStr::from_ptr` suggests using `str::from_utf8(slice.to_bytes()).unwrap()` to obtain a `&str` but `CStr` has `CStr::to_str` that does exactly that.