diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-07-22 21:45:33 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-07-23 16:56:22 -0700 |
| commit | 3b818edeba4dbca7c605ca5600f2d1b4b000120b (patch) | |
| tree | debfc8b7cbf00f368b3f4267048c877ad9549f2a /src/libstd | |
| parent | cf75330807ad908a428e9c162a388e367fb07781 (diff) | |
| download | rust-3b818edeba4dbca7c605ca5600f2d1b4b000120b.tar.gz rust-3b818edeba4dbca7c605ca5600f2d1b4b000120b.zip | |
std and extra: use as_c_str instead of as_buf in a couple places
These uses are assuming the strings are null terminated, so it should be using `as_c_str` instead of `as_buf`
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rt/borrowck.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys.rs | 20 | ||||
| -rw-r--r-- | src/libstd/unstable/lang.rs | 4 |
3 files changed, 11 insertions, 19 deletions
diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index 42e545ce1a9..1a468fcf215 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -76,7 +76,7 @@ unsafe fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) { match try_take_task_borrow_list() { None => { // not recording borrows let msg = "borrowed"; - do msg.as_buf |msg_p, _| { + do msg.as_c_str |msg_p| { sys::begin_unwind_(msg_p as *c_char, file, line); } } @@ -92,7 +92,7 @@ unsafe fn fail_borrowed(box: *mut BoxRepr, file: *c_char, line: size_t) { sep = " and at "; } } - do msg.as_buf |msg_p, _| { + do msg.as_c_str |msg_p| { sys::begin_unwind_(msg_p as *c_char, file, line) } } @@ -231,7 +231,7 @@ 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_buf |msg_p, _| { + do err.as_c_str |msg_p| { sys::begin_unwind_(msg_p as *c_char, file, line) } } diff --git a/src/libstd/sys.rs b/src/libstd/sys.rs index 0c497ecef27..28cd2345aab 100644 --- a/src/libstd/sys.rs +++ b/src/libstd/sys.rs @@ -123,13 +123,9 @@ pub trait FailWithCause { impl FailWithCause for ~str { fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! { - do cause.as_buf |msg_buf, _msg_len| { - do file.as_buf |file_buf, _file_len| { - unsafe { - let msg_buf = cast::transmute(msg_buf); - let file_buf = cast::transmute(file_buf); - begin_unwind_(msg_buf, file_buf, line as libc::size_t) - } + do cause.as_c_str |msg_buf| { + do file.as_c_str |file_buf| { + begin_unwind_(msg_buf, file_buf, line as libc::size_t) } } } @@ -137,13 +133,9 @@ impl FailWithCause for ~str { impl FailWithCause for &'static str { fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! { - do cause.as_buf |msg_buf, _msg_len| { - do file.as_buf |file_buf, _file_len| { - unsafe { - let msg_buf = cast::transmute(msg_buf); - let file_buf = cast::transmute(file_buf); - begin_unwind_(msg_buf, file_buf, line as libc::size_t) - } + do cause.as_c_str |msg_buf| { + do file.as_c_str |file_buf| { + begin_unwind_(msg_buf, file_buf, line as libc::size_t) } } } diff --git a/src/libstd/unstable/lang.rs b/src/libstd/unstable/lang.rs index f8cd08b4bf6..d96681ae803 100644 --- a/src/libstd/unstable/lang.rs +++ b/src/libstd/unstable/lang.rs @@ -56,8 +56,8 @@ 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_buf |p, _len| { - fail_(p as *c_char, file, line); + do msg.as_c_str |buf| { + fail_(buf, file, line); } } |
