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/rt | |
| 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/rt')
| -rw-r--r-- | src/libstd/rt/borrowck.rs | 13 | ||||
| -rw-r--r-- | src/libstd/rt/logging.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/uv/uvio.rs | 26 | ||||
| -rw-r--r-- | src/libstd/rt/uv/uvll.rs | 5 |
4 files changed, 25 insertions, 23 deletions
diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index afbb0fcb567..f620a7347a4 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use c_str::ToCStr; use cast::transmute; use libc::{c_char, size_t, STDERR_FILENO}; use io; @@ -51,8 +52,8 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) { match try_take_task_borrow_list() { None => { // not recording borrows let msg = "borrowed"; - do msg.as_c_str |msg_p| { - sys::begin_unwind_(msg_p as *c_char, file, line); + do msg.to_c_str().with_ref |msg_p| { + sys::begin_unwind_(msg_p, file, line); } } Some(borrow_list) => { // recording borrows @@ -67,8 +68,8 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) { sep = " and at "; } } - do msg.as_c_str |msg_p| { - sys::begin_unwind_(msg_p as *c_char, file, line) + do msg.to_c_str().with_ref |msg_p| { + sys::begin_unwind_(msg_p, file, line) } } } @@ -207,8 +208,8 @@ pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint, let br = borrow_list.pop(); if br.box != a || br.file != file || br.line != line { let err = fmt!("wrong borrow found, br=%?", br); - do err.as_c_str |msg_p| { - sys::begin_unwind_(msg_p as *c_char, file, line) + do err.to_c_str().with_ref |msg_p| { + sys::begin_unwind_(msg_p, file, line) } } borrow_list diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index 9056f0d52e0..117795f6c90 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -58,15 +58,15 @@ impl Logger for StdErrLogger { /// Configure logging by traversing the crate map and setting the /// per-module global logging flags based on the logging spec pub fn init(crate_map: *u8) { + use c_str::ToCStr; use os; - use str::StrSlice; use ptr; use option::{Some, None}; let log_spec = os::getenv("RUST_LOG"); match log_spec { Some(spec) => { - do spec.as_c_str |buf| { + do spec.to_c_str().with_ref |buf| { unsafe { rust_update_log_settings(crate_map, buf) } } } diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 70a397199ab..038ebad3540 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -8,26 +8,26 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use option::*; -use result::*; -use ops::Drop; -use cell::Cell; -use cast; +use c_str::ToCStr; use cast::transmute; +use cast; +use cell::Cell; use clone::Clone; use libc::{c_int, c_uint, c_void}; +use ops::Drop; +use option::*; use ptr; +use result::*; use rt::io::IoError; use rt::io::net::ip::{SocketAddr, IpAddr}; -use rt::uv::*; -use rt::uv::idle::IdleWatcher; -use rt::uv::net::{UvIpv4SocketAddr, UvIpv6SocketAddr}; +use rt::io::{standard_error, OtherIoError}; +use rt::local::Local; use rt::rtio::*; use rt::sched::Scheduler; -use rt::io::{standard_error, OtherIoError}; use rt::tube::Tube; -use rt::local::Local; -use str::StrSlice; +use rt::uv::*; +use rt::uv::idle::IdleWatcher; +use rt::uv::net::{UvIpv4SocketAddr, UvIpv6SocketAddr}; use unstable::sync::Exclusive; #[cfg(test)] use container::Container; @@ -654,7 +654,7 @@ impl RtioUdpSocket for UvUdpSocket { fn join_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> { let r = unsafe { - do multi.to_str().as_c_str |m_addr| { + do multi.to_str().to_c_str().with_ref |m_addr| { uvll::udp_set_membership(self.native_handle(), m_addr, ptr::null(), uvll::UV_JOIN_GROUP) } @@ -668,7 +668,7 @@ impl RtioUdpSocket for UvUdpSocket { fn leave_multicast(&mut self, multi: IpAddr) -> Result<(), IoError> { let r = unsafe { - do multi.to_str().as_c_str |m_addr| { + do multi.to_str().to_c_str().with_ref |m_addr| { uvll::udp_set_membership(self.native_handle(), m_addr, ptr::null(), uvll::UV_LEAVE_GROUP) } diff --git a/src/libstd/rt/uv/uvll.rs b/src/libstd/rt/uv/uvll.rs index a06247a1036..e240395a495 100644 --- a/src/libstd/rt/uv/uvll.rs +++ b/src/libstd/rt/uv/uvll.rs @@ -29,6 +29,7 @@ #[allow(non_camel_case_types)]; // C types +use c_str::ToCStr; use libc::{size_t, c_int, c_uint, c_void, c_char, uintptr_t}; use libc::{malloc, free}; use libc; @@ -372,12 +373,12 @@ pub unsafe fn is_ip6_addr(addr: *sockaddr) -> bool { } pub unsafe fn malloc_ip4_addr(ip: &str, port: int) -> *sockaddr_in { - do ip.as_c_str |ip_buf| { + do ip.to_c_str().with_ref |ip_buf| { rust_uv_ip4_addrp(ip_buf as *u8, port as libc::c_int) } } pub unsafe fn malloc_ip6_addr(ip: &str, port: int) -> *sockaddr_in6 { - do ip.as_c_str |ip_buf| { + do ip.to_c_str().with_ref |ip_buf| { rust_uv_ip6_addrp(ip_buf as *u8, port as libc::c_int) } } |
