Skip to content

Commit 7a103c6

Browse files
committed
---
yaml --- r: 64655 b: refs/heads/snap-stage3 c: cc9666f h: refs/heads/master i: 64653: 36f3789 64651: aa37b65 64647: aab0b62 64639: f6daf75 v: v3
1 parent dad594e commit 7a103c6

File tree

4 files changed

+64
-70
lines changed

4 files changed

+64
-70
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 3b818edeba4dbca7c605ca5600f2d1b4b000120b
4+
refs/heads/snap-stage3: cc9666f68f829c17ff3a535f714fe5dbb3f72755
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,10 @@ fn test_unwrap_ptr() {
445445
#[test]
446446
fn test_unwrap_str() {
447447
let x = ~"test";
448-
let addr_x = x.as_buf(|buf, _len| buf);
448+
let addr_x = x.as_imm_buf(|buf, _len| buf);
449449
let opt = Some(x);
450450
let y = opt.unwrap();
451-
let addr_y = y.as_buf(|buf, _len| buf);
451+
let addr_y = y.as_imm_buf(|buf, _len| buf);
452452
assert_eq!(addr_x, addr_y);
453453
}
454454

branches/snap-stage3/src/libstd/str.rs

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ impl<'self, S: Str> StrVector for &'self [S] {
191191
s.reserve(len);
192192

193193
unsafe {
194-
do s.as_buf |buf, _| {
195-
let mut buf = ::cast::transmute_mut_unsafe(buf);
194+
do s.as_mut_buf |buf, _| {
195+
let mut buf = buf;
196196
for self.iter().advance |ss| {
197-
do ss.as_slice().as_buf |ssbuf, sslen| {
197+
do ss.as_slice().as_imm_buf |ssbuf, sslen| {
198198
let sslen = sslen - 1;
199199
ptr::copy_memory(buf, ssbuf, sslen);
200200
buf = buf.offset(sslen);
@@ -222,12 +222,12 @@ impl<'self, S: Str> StrVector for &'self [S] {
222222
s.reserve(len);
223223

224224
unsafe {
225-
do s.as_buf |buf, _| {
226-
do sep.as_buf |sepbuf, seplen| {
225+
do s.as_mut_buf |buf, _| {
226+
do sep.as_imm_buf |sepbuf, seplen| {
227227
let seplen = seplen - 1;
228228
let mut buf = ::cast::transmute_mut_unsafe(buf);
229229
for self.iter().advance |ss| {
230-
do ss.as_slice().as_buf |ssbuf, sslen| {
230+
do ss.as_slice().as_imm_buf |ssbuf, sslen| {
231231
let sslen = sslen - 1;
232232
if first {
233233
first = false;
@@ -533,8 +533,8 @@ Section: Comparing strings
533533
#[lang="str_eq"]
534534
#[inline]
535535
pub fn eq_slice(a: &str, b: &str) -> bool {
536-
do a.as_buf |ap, alen| {
537-
do b.as_buf |bp, blen| {
536+
do a.as_imm_buf |ap, alen| {
537+
do b.as_imm_buf |bp, blen| {
538538
if (alen != blen) { false }
539539
else {
540540
unsafe {
@@ -550,8 +550,8 @@ pub fn eq_slice(a: &str, b: &str) -> bool {
550550
#[cfg(test)]
551551
#[inline]
552552
pub fn eq_slice(a: &str, b: &str) -> bool {
553-
do a.as_buf |ap, alen| {
554-
do b.as_buf |bp, blen| {
553+
do a.as_imm_buf |ap, alen| {
554+
do b.as_imm_buf |bp, blen| {
555555
if (alen != blen) { false }
556556
else {
557557
unsafe {
@@ -868,7 +868,7 @@ pub mod raw {
868868
* If end is greater than the length of the string.
869869
*/
870870
pub unsafe fn slice_bytes_owned(s: &str, begin: uint, end: uint) -> ~str {
871-
do s.as_buf |sbuf, n| {
871+
do s.as_imm_buf |sbuf, n| {
872872
assert!((begin <= end));
873873
assert!((end <= n));
874874

@@ -896,7 +896,7 @@ pub mod raw {
896896
*/
897897
#[inline]
898898
pub unsafe fn slice_bytes(s: &str, begin: uint, end: uint) -> &str {
899-
do s.as_buf |sbuf, n| {
899+
do s.as_imm_buf |sbuf, n| {
900900
assert!((begin <= end));
901901
assert!((end <= n));
902902

@@ -909,8 +909,7 @@ pub mod raw {
909909
pub unsafe fn push_byte(s: &mut ~str, b: u8) {
910910
let new_len = s.len() + 1;
911911
s.reserve_at_least(new_len);
912-
do s.as_buf |buf, len| {
913-
let buf: *mut u8 = ::cast::transmute(buf);
912+
do s.as_mut_buf |buf, len| {
914913
*ptr::mut_offset(buf, len) = b;
915914
}
916915
set_len(&mut *s, new_len);
@@ -1130,7 +1129,7 @@ impl<'self> Str for @str {
11301129
impl<'self> Container for &'self str {
11311130
#[inline]
11321131
fn len(&self) -> uint {
1133-
do self.as_buf |_p, n| { n - 1u }
1132+
do self.as_imm_buf |_p, n| { n - 1u }
11341133
}
11351134
#[inline]
11361135
fn is_empty(&self) -> bool {
@@ -1225,7 +1224,8 @@ pub trait StrSlice<'self> {
12251224
12261225
fn subslice_offset(&self, inner: &str) -> uint;
12271226
1228-
fn as_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T;
1227+
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T;
1228+
fn as_mut_buf<T>(&self, f: &fn(*mut u8, uint) -> T) -> T;
12291229
fn as_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T;
12301230
}
12311231
@@ -1849,15 +1849,15 @@ impl<'self> StrSlice<'self> for &'self str {
18491849
18501850
/// Given a string, make a new string with repeated copies of it.
18511851
fn repeat(&self, nn: uint) -> ~str {
1852-
do self.as_buf |buf, len| {
1852+
do self.as_imm_buf |buf, len| {
18531853
let mut ret = ~"";
18541854
// ignore the NULL terminator
18551855
let len = len - 1;
18561856
ret.reserve(nn * len);
18571857
18581858
unsafe {
1859-
do ret.as_buf |rbuf, _len| {
1860-
let mut rbuf = ::cast::transmute_mut_unsafe(rbuf);
1859+
do ret.as_mut_buf |rbuf, _len| {
1860+
let mut rbuf = rbuf;
18611861
18621862
for nn.times {
18631863
ptr::copy_memory(rbuf, buf, len);
@@ -1950,8 +1950,8 @@ impl<'self> StrSlice<'self> for &'self str {
19501950
*/
19511951
#[inline]
19521952
fn subslice_offset(&self, inner: &str) -> uint {
1953-
do self.as_buf |a, a_len| {
1954-
do inner.as_buf |b, b_len| {
1953+
do self.as_imm_buf |a, a_len| {
1954+
do inner.as_imm_buf |b, b_len| {
19551955
let a_start: uint;
19561956
let a_end: uint;
19571957
let b_start: uint;
@@ -1976,14 +1976,31 @@ impl<'self> StrSlice<'self> for &'self str {
19761976
* to full strings, or suffixes of them.
19771977
*/
19781978
#[inline]
1979-
fn as_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T {
1979+
fn as_imm_buf<T>(&self, f: &fn(*u8, uint) -> T) -> T {
19801980
unsafe {
19811981
let v: *(*u8, uint) = cast::transmute(self);
19821982
let (buf, len) = *v;
19831983
f(buf, len)
19841984
}
19851985
}
19861986
1987+
/**
1988+
* Work with the byte buffer and length of a slice.
1989+
*
1990+
* The given length is one byte longer than the 'official' indexable
1991+
* length of the string. This is to permit probing the byte past the
1992+
* indexable area for a null byte, as is the case in slices pointing
1993+
* to full strings, or suffixes of them.
1994+
*/
1995+
#[inline]
1996+
fn as_mut_buf<T>(&self, f: &fn(*mut u8, uint) -> T) -> T {
1997+
unsafe {
1998+
let v: *(*mut u8, uint) = cast::transmute(self);
1999+
let (buf, len) = *v;
2000+
f(buf, len)
2001+
}
2002+
}
2003+
19872004
/**
19882005
* Work with the byte buffer of a string as a null-terminated C string.
19892006
*
@@ -2001,7 +2018,7 @@ impl<'self> StrSlice<'self> for &'self str {
20012018
*/
20022019
#[inline]
20032020
fn as_c_str<T>(&self, f: &fn(*libc::c_char) -> T) -> T {
2004-
do self.as_buf |buf, len| {
2021+
do self.as_imm_buf |buf, len| {
20052022
// NB: len includes the trailing null.
20062023
assert!(len > 0);
20072024
if unsafe { *(ptr::offset(buf, len - 1)) != 0 } {
@@ -2068,8 +2085,8 @@ impl OwnedStr for ~str {
20682085
let llen = self.len();
20692086
let rlen = rhs.len();
20702087
self.reserve(llen + rlen);
2071-
do self.as_buf |lbuf, _llen| {
2072-
do rhs.as_buf |rbuf, _rlen| {
2088+
do self.as_imm_buf |lbuf, _llen| {
2089+
do rhs.as_imm_buf |rbuf, _rlen| {
20732090
let dst = ptr::offset(lbuf, llen);
20742091
let dst = ::cast::transmute_mut_unsafe(dst);
20752092
ptr::copy_memory(dst, rbuf, rlen);
@@ -2086,8 +2103,8 @@ impl OwnedStr for ~str {
20862103
let llen = self.len();
20872104
let rlen = rhs.len();
20882105
self.reserve_at_least(llen + rlen);
2089-
do self.as_buf |lbuf, _llen| {
2090-
do rhs.as_buf |rbuf, _rlen| {
2106+
do self.as_imm_buf |lbuf, _llen| {
2107+
do rhs.as_imm_buf |rbuf, _rlen| {
20912108
let dst = ptr::offset(lbuf, llen);
20922109
let dst = ::cast::transmute_mut_unsafe(dst);
20932110
ptr::copy_memory(dst, rbuf, rlen);
@@ -2110,8 +2127,7 @@ impl OwnedStr for ~str {
21102127
let new_len = len + nb;
21112128
self.reserve_at_least(new_len);
21122129
let off = len;
2113-
do self.as_buf |buf, _len| {
2114-
let buf: *mut u8 = ::cast::transmute(buf);
2130+
do self.as_mut_buf |buf, _len| {
21152131
match nb {
21162132
1u => {
21172133
*ptr::mut_offset(buf, off) = code as u8;
@@ -3073,45 +3089,23 @@ mod tests {
30733089
}
30743090
30753091
#[test]
3076-
fn test_as_buf() {
3077-
let a = "Abcdefg";
3078-
let b = do a.as_buf |buf, _l| {
3079-
assert_eq!(unsafe { *buf }, 65u8);
3080-
100
3081-
};
3082-
assert_eq!(b, 100);
3083-
}
3084-
3085-
#[test]
3086-
fn test_as_buf_small() {
3087-
let a = "A";
3088-
let b = do a.as_buf |buf, _l| {
3089-
assert_eq!(unsafe { *buf }, 65u8);
3090-
100
3091-
};
3092-
assert_eq!(b, 100);
3093-
}
3094-
3095-
#[test]
3096-
fn test_as_buf2() {
3097-
unsafe {
3098-
let s = ~"hello";
3099-
let sb = s.as_buf(|b, _l| b);
3100-
let s_cstr = raw::from_buf(sb);
3101-
assert_eq!(s_cstr, s);
3092+
fn test_as_imm_buf() {
3093+
do "".as_imm_buf |buf, len| {
3094+
assert_eq!(len, 1);
3095+
unsafe {
3096+
assert_eq!(*ptr::offset(buf, 0), 0);
3097+
}
31023098
}
3103-
}
31043099
3105-
#[test]
3106-
fn test_as_buf_3() {
3107-
let a = ~"hello";
3108-
do a.as_buf |buf, len| {
3100+
do "hello".as_imm_buf |buf, len| {
3101+
assert_eq!(len, 6);
31093102
unsafe {
3110-
assert_eq!(a[0], 'h' as u8);
3111-
assert_eq!(*buf, 'h' as u8);
3112-
assert_eq!(len, 6u);
3113-
assert_eq!(*ptr::offset(buf,4u), 'o' as u8);
3114-
assert_eq!(*ptr::offset(buf,5u), 0u8);
3103+
assert_eq!(*ptr::offset(buf, 0), 'h' as u8);
3104+
assert_eq!(*ptr::offset(buf, 1), 'e' as u8);
3105+
assert_eq!(*ptr::offset(buf, 2), 'l' as u8);
3106+
assert_eq!(*ptr::offset(buf, 3), 'l' as u8);
3107+
assert_eq!(*ptr::offset(buf, 4), 'o' as u8);
3108+
assert_eq!(*ptr::offset(buf, 5), 0);
31153109
}
31163110
}
31173111
}

branches/snap-stage3/src/test/run-pass/c-stack-returning-int64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ mod libc {
2020
}
2121

2222
fn atol(s: ~str) -> int {
23-
s.as_buf(|x, _len| unsafe { libc::atol(x) })
23+
s.as_imm_buf(|x, _len| unsafe { libc::atol(x) })
2424
}
2525

2626
fn atoll(s: ~str) -> i64 {
27-
s.as_buf(|x, _len| unsafe { libc::atoll(x) })
27+
s.as_imm_buf(|x, _len| unsafe { libc::atoll(x) })
2828
}
2929

3030
pub fn main() {

0 commit comments

Comments
 (0)