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/uv | |
| parent | e81e81f234731a31fad9afdc2045bef3fbdf1109 (diff) | |
| parent | ee59aacac490edd619db1c4e2fcd848f793bc3b9 (diff) | |
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/uv')
| -rw-r--r-- | src/libstd/rt/uv/uvio.rs | 26 | ||||
| -rw-r--r-- | src/libstd/rt/uv/uvll.rs | 5 |
2 files changed, 16 insertions, 15 deletions
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) } } |
