diff options
| author | bors <bors@rust-lang.org> | 2013-08-09 21:56:17 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-09 21:56:17 -0700 |
| commit | 60f5011005eda4f08f0c36fe56e4df07ae9a903f (patch) | |
| tree | 4f3636735525b80b6aa3c6fc37b88a5f9057548c /src/libstd/unstable | |
| parent | e81e81f234731a31fad9afdc2045bef3fbdf1109 (diff) | |
| parent | ee59aacac490edd619db1c4e2fcd848f793bc3b9 (diff) | |
| download | rust-60f5011005eda4f08f0c36fe56e4df07ae9a903f.tar.gz rust-60f5011005eda4f08f0c36fe56e4df07ae9a903f.zip | |
auto merge of #8296 : erickt/rust/remove-str-trailing-nulls, r=erickt
This PR fixes #7235 and #3371, which removes trailing nulls from `str` types. Instead, it replaces the creation of c strings with a new type, `std::c_str::CString`, which wraps a malloced byte array, and respects: * No interior nulls * Ends with a trailing null
Diffstat (limited to 'src/libstd/unstable')
| -rw-r--r-- | src/libstd/unstable/dynamic_lib.rs | 6 | ||||
| -rw-r--r-- | src/libstd/unstable/extfmt.rs | 14 | ||||
| -rw-r--r-- | src/libstd/unstable/lang.rs | 3 |
3 files changed, 14 insertions, 9 deletions
diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index 8d5654255f1..49e3e0777df 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -15,6 +15,7 @@ Dynamic library facilities. A simple wrapper over the platforms dynamic library facilities */ +use c_str::ToCStr; use cast; use path; use libc; @@ -65,7 +66,7 @@ impl DynamicLibrary { // T but that feature is still unimplemented let maybe_symbol_value = do dl::check_for_errors_in { - do symbol.as_c_str |raw_string| { + do symbol.to_c_str().with_ref |raw_string| { dl::symbol(self.handle, raw_string) } }; @@ -135,6 +136,7 @@ mod test { #[cfg(target_os = "macos")] #[cfg(target_os = "freebsd")] mod dl { + use c_str::ToCStr; use libc; use path; use ptr; @@ -143,7 +145,7 @@ mod dl { use result::*; pub unsafe fn open_external(filename: &path::Path) -> *libc::c_void { - do filename.to_str().as_c_str |raw_name| { + do filename.to_c_str().with_ref |raw_name| { dlopen(raw_name, Lazy as libc::c_int) } } diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs index 7b05515f74a..d63f914bc73 100644 --- a/src/libstd/unstable/extfmt.rs +++ b/src/libstd/unstable/extfmt.rs @@ -549,12 +549,14 @@ pub mod rt { // For strings, precision is the maximum characters // displayed let unpadded = match cv.precision { - CountImplied => s, - CountIs(max) => if (max as uint) < s.char_len() { - s.slice(0, max as uint) - } else { - s - } + CountImplied => s, + CountIs(max) => { + if (max as uint) < s.char_len() { + s.slice(0, max as uint) + } else { + s + } + } }; pad(cv, unpadded, None, PadNozero, buf); } diff --git a/src/libstd/unstable/lang.rs b/src/libstd/unstable/lang.rs index 455877687b9..9e7ac1fd7db 100644 --- a/src/libstd/unstable/lang.rs +++ b/src/libstd/unstable/lang.rs @@ -10,6 +10,7 @@ //! Runtime calls emitted by the compiler. +use c_str::ToCStr; use cast::transmute; use libc::{c_char, c_uchar, c_void, size_t, uintptr_t}; use str; @@ -28,7 +29,7 @@ pub fn fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t) { let msg = fmt!("index out of bounds: the len is %d but the index is %d", len as int, index as int); - do msg.as_c_str |buf| { + do msg.to_c_str().with_ref |buf| { fail_(buf, file, line); } } |
