diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-09-12 17:45:23 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-09-12 17:45:36 -0700 |
| commit | ff54ac8e598bfc71e827c0b60e392c5f0fbd4d7e (patch) | |
| tree | c5c20cafe2c415f1f3aecbc2fa60770e3ca9f1e3 /src/libcore | |
| parent | 37cf649311bcf6fec2d9096b483ac4be81b70732 (diff) | |
Rename vec::unsafe to vec::raw
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/at_vec.rs | 6 | ||||
| -rw-r--r-- | src/libcore/flate.rs | 4 | ||||
| -rw-r--r-- | src/libcore/io.rs | 6 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 12 | ||||
| -rw-r--r-- | src/libcore/str.rs | 14 | ||||
| -rw-r--r-- | src/libcore/uint-template.rs | 2 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 66 |
7 files changed, 55 insertions, 55 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index e2749a5bd57..4fbc05821f8 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -15,7 +15,7 @@ export unsafe; #[abi = "cdecl"] extern mod rustrt { fn vec_reserve_shared_actual(++t: *sys::TypeDesc, - ++v: **vec::unsafe::VecRepr, + ++v: **vec::raw::VecRepr, ++n: libc::size_t); } @@ -142,8 +142,8 @@ impl<T: Copy> @[T]: Add<&[const T],@[T]> { mod unsafe { - type VecRepr = vec::unsafe::VecRepr; - type SliceRepr = vec::unsafe::SliceRepr; + type VecRepr = vec::raw::VecRepr; + type SliceRepr = vec::raw::SliceRepr; /** * Sets the length of a vector diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs index fbd6e731e3b..836ffabd0fc 100644 --- a/src/libcore/flate.rs +++ b/src/libcore/flate.rs @@ -28,7 +28,7 @@ fn deflate_buf(buf: &[const u8]) -> ~[u8] { ptr::addr_of(outsz), lz_norm); assert res as int != 0; - let out = vec::unsafe::from_buf(res as *u8, + let out = vec::raw::from_buf(res as *u8, outsz as uint); libc::free(res); move out @@ -46,7 +46,7 @@ fn inflate_buf(buf: &[const u8]) -> ~[u8] { ptr::addr_of(outsz), 0); assert res as int != 0; - let out = vec::unsafe::from_buf(res as *u8, + let out = vec::raw::from_buf(res as *u8, outsz as uint); libc::free(res); move out diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 9d4176ea40b..5f96345d783 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -53,11 +53,11 @@ impl<T: Reader> T : ReaderUtil { fn read_bytes(len: uint) -> ~[u8] { let mut buf = ~[mut]; vec::reserve(buf, len); - unsafe { vec::unsafe::set_len(buf, len); } + unsafe { vec::raw::set_len(buf, len); } let count = self.read(buf, len); - unsafe { vec::unsafe::set_len(buf, count); } + unsafe { vec::raw::set_len(buf, count); } vec::from_mut(move buf) } fn read_line() -> ~str { @@ -682,7 +682,7 @@ impl MemBuffer: Writer { let count = uint::max(buf_len, self.pos + v_len); vec::reserve(buf, count); - unsafe { vec::unsafe::set_len(buf, count); } + unsafe { vec::raw::set_len(buf, count); } vec::u8::memcpy(vec::mut_view(buf, self.pos, count), v, v_len); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 79ec6fea668..c95e2aa6c7c 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -265,14 +265,14 @@ fn test() { let mut v0 = ~[32000u16, 32001u16, 32002u16]; let mut v1 = ~[0u16, 0u16, 0u16]; - ptr::memcpy(ptr::mut_offset(vec::unsafe::to_mut_ptr(v1), 1u), - ptr::offset(vec::unsafe::to_ptr(v0), 1u), 1u); + ptr::memcpy(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 1u), + ptr::offset(vec::raw::to_ptr(v0), 1u), 1u); assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16); - ptr::memcpy(vec::unsafe::to_mut_ptr(v1), - ptr::offset(vec::unsafe::to_ptr(v0), 2u), 1u); + ptr::memcpy(vec::raw::to_mut_ptr(v1), + ptr::offset(vec::raw::to_ptr(v0), 2u), 1u); assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16); - ptr::memcpy(ptr::mut_offset(vec::unsafe::to_mut_ptr(v1), 2u), - vec::unsafe::to_ptr(v0), 1u); + ptr::memcpy(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 2u), + vec::raw::to_ptr(v0), 1u); assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16); } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 88858e2b1ab..88eb4a8d87d 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -439,7 +439,7 @@ Section: Transforming strings */ pure fn to_bytes(s: &str) -> ~[u8] unsafe { let mut v: ~[u8] = ::unsafe::transmute(from_slice(s)); - vec::unsafe::set_len(v, len(s)); + vec::raw::set_len(v, len(s)); move v } @@ -447,7 +447,7 @@ pure fn to_bytes(s: &str) -> ~[u8] unsafe { #[inline(always)] pure fn byte_slice<T>(s: &str, f: fn(v: &[u8]) -> T) -> T { do as_buf(s) |p,n| { - unsafe { vec::unsafe::form_slice(p, n-1u, f) } + unsafe { vec::raw::form_slice(p, n-1u, f) } } } @@ -1996,7 +1996,7 @@ mod unsafe { let vbuf = ::unsafe::transmute_mut_unsafe(vbuf); ptr::memcpy(vbuf, buf as *u8, len) }); - vec::unsafe::set_len(v, len); + vec::raw::set_len(v, len); vec::push(v, 0u8); assert is_utf8(v); @@ -2054,7 +2054,7 @@ mod unsafe { let src = ptr::offset(sbuf, begin); ptr::memcpy(vbuf, src, end - begin); } - vec::unsafe::set_len(v, end - begin); + vec::raw::set_len(v, end - begin); vec::push(v, 0u8); ::unsafe::transmute(move v) } @@ -2118,7 +2118,7 @@ mod unsafe { /// Sets the length of the string and adds the null terminator unsafe fn set_len(&v: ~str, new_len: uint) { - let repr: *vec::unsafe::VecRepr = ::unsafe::reinterpret_cast(&v); + let repr: *vec::raw::VecRepr = ::unsafe::reinterpret_cast(&v); (*repr).fill = new_len + 1u; let null = ptr::mut_offset(ptr::mut_addr_of((*repr).data), new_len); *null = 0u8; @@ -2128,7 +2128,7 @@ mod unsafe { fn test_from_buf_len() { unsafe { let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; - let b = vec::unsafe::to_ptr(a); + let b = vec::raw::to_ptr(a); let c = from_buf_len(b, 3u); assert (c == ~"AAA"); } @@ -2940,7 +2940,7 @@ mod tests { fn test_from_buf() { unsafe { let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; - let b = vec::unsafe::to_ptr(a); + let b = vec::raw::to_ptr(a); let c = unsafe::from_buf(b); assert (c == ~"AAAAAAA"); } diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index 1da46d780be..879ba684698 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -239,7 +239,7 @@ pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint, *ptr::mut_offset(mp, i) = '-' as u8; } - vec::unsafe::form_slice(ptr::offset(p, i), + vec::raw::form_slice(ptr::offset(p, i), len - i, f) } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 62cc5ce6f60..626cb886fb3 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -87,7 +87,7 @@ export windowed; export as_buf; export as_mut_buf; export as_const_buf; -export unsafe; +export raw; export u8; export extensions; export ConstVector; @@ -101,7 +101,7 @@ export vec_concat; #[abi = "cdecl"] extern mod rustrt { fn vec_reserve_shared(++t: *sys::TypeDesc, - ++v: **unsafe::VecRepr, + ++v: **raw::VecRepr, ++n: libc::size_t); } @@ -139,7 +139,7 @@ pure fn same_length<T, U>(xs: &[const T], ys: &[const U]) -> bool { fn reserve<T>(&v: ~[const T], n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(v) < n { - let ptr = ptr::addr_of(v) as **unsafe::VecRepr; + let ptr = ptr::addr_of(v) as **raw::VecRepr; rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), ptr, n as size_t); } @@ -168,7 +168,7 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) { #[inline(always)] pure fn capacity<T>(&&v: ~[const T]) -> uint { unsafe { - let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); (**repr).alloc / sys::size_of::<T>() } } @@ -189,8 +189,8 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] { let mut v = ~[]; unchecked{reserve(v, n_elts);} let mut i: uint = 0u; - while i < n_elts unsafe { unsafe::set(v, i, op(i)); i += 1u; } - unsafe { unsafe::set_len(v, n_elts); } + while i < n_elts unsafe { raw::set(v, i, op(i)); i += 1u; } + unsafe { raw::set_len(v, n_elts); } move v } @@ -205,8 +205,8 @@ pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> ~[T] { unchecked{reserve(v, n_elts)} let mut i: uint = 0u; unsafe { // because unsafe::set is unsafe - while i < n_elts { unsafe::set(v, i, t); i += 1u; } - unsafe { unsafe::set_len(v, n_elts); } + while i < n_elts { raw::set(v, i, t); i += 1u; } + unsafe { raw::set_len(v, n_elts); } } move v } @@ -478,7 +478,7 @@ fn shift<T>(&v: ~[T]) -> T { unsafe { let mut rr; { - let vv = unsafe::to_ptr(vv); + let vv = raw::to_ptr(vv); rr <- *vv; for uint::range(1, ln) |i| { @@ -486,7 +486,7 @@ fn shift<T>(&v: ~[T]) -> T { push(v, move r); } } - unsafe::set_len(vv, 0); + raw::set_len(vv, 0); move rr } @@ -509,7 +509,7 @@ fn consume<T>(+v: ~[T], f: fn(uint, +T)) unsafe { } } - unsafe::set_len(v, 0); + raw::set_len(v, 0); } fn consume_mut<T>(+v: ~[mut T], f: fn(uint, +T)) unsafe { @@ -520,7 +520,7 @@ fn consume_mut<T>(+v: ~[mut T], f: fn(uint, +T)) unsafe { } } - unsafe::set_len(v, 0); + raw::set_len(v, 0); } /// Remove the last element from a vector and return it @@ -532,7 +532,7 @@ fn pop<T>(&v: ~[const T]) -> T { let valptr = ptr::mut_addr_of(v[ln - 1u]); unsafe { let val <- *valptr; - unsafe::set_len(v, ln - 1u); + raw::set_len(v, ln - 1u); move val } } @@ -555,7 +555,7 @@ fn swap_remove<T>(&v: ~[const T], index: uint) -> T { let valptr = ptr::mut_addr_of(v[index]); *valptr <-> val; } - unsafe::set_len(v, ln - 1); + raw::set_len(v, ln - 1); move val } } @@ -564,7 +564,7 @@ fn swap_remove<T>(&v: ~[const T], index: uint) -> T { #[inline(always)] fn push<T>(&v: ~[const T], +initval: T) { unsafe { - let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); let fill = (**repr).fill; if (**repr).alloc > fill { push_fast(v, move initval); @@ -578,7 +578,7 @@ fn push<T>(&v: ~[const T], +initval: T) { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please unsafe fn push_fast<T>(&v: ~[const T], +initval: T) { - let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); let fill = (**repr).fill; (**repr).fill += sys::size_of::<T>(); let p = ptr::addr_of((**repr).data); @@ -597,7 +597,7 @@ fn push_all<T: Copy>(&v: ~[const T], rhs: &[const T]) { reserve(v, v.len() + rhs.len()); for uint::range(0u, rhs.len()) |i| { - push(v, unsafe { unsafe::get(rhs, i) }) + push(v, unsafe { raw::get(rhs, i) }) } } @@ -611,7 +611,7 @@ fn push_all_move<T>(&v: ~[const T], -rhs: ~[const T]) { push(v, move x); } } - unsafe::set_len(rhs, 0); + raw::set_len(rhs, 0); } } @@ -624,7 +624,7 @@ fn truncate<T>(&v: ~[const T], newlen: uint) { for uint::range(newlen, oldlen) |i| { let _dropped <- *ptr::offset(p, i); } - unsafe::set_len(v, newlen); + raw::set_len(v, newlen); } } } @@ -660,7 +660,7 @@ fn dedup<T: Eq>(&v: ~[const T]) unsafe { } } // last_written < next_to_read == ln - unsafe::set_len(v, last_written + 1); + raw::set_len(v, last_written + 1); } @@ -1786,7 +1786,7 @@ impl<T: Copy> &[T]: ImmutableCopyableVector<T> { } /// Unsafe operations -mod unsafe { +mod raw { // FIXME: This should have crate visibility (#1893 blocks that) /// The internal representation of a vector type VecRepr = { @@ -1936,8 +1936,8 @@ mod u8 { let b_len = len(*b); let n = uint::min(a_len, b_len) as libc::size_t; let r = unsafe { - libc::memcmp(unsafe::to_ptr(*a) as *libc::c_void, - unsafe::to_ptr(*b) as *libc::c_void, n) as int + libc::memcmp(raw::to_ptr(*a) as *libc::c_void, + raw::to_ptr(*b) as *libc::c_void, n) as int }; if r != 0 { r } else { @@ -1984,7 +1984,7 @@ mod u8 { assert dst.len() >= count; assert src.len() >= count; - unsafe { vec::unsafe::memcpy(dst, src, count) } + unsafe { vec::raw::memcpy(dst, src, count) } } /** @@ -1997,7 +1997,7 @@ mod u8 { assert dst.len() >= count; assert src.len() >= count; - unsafe { vec::unsafe::memmove(dst, src, count) } + unsafe { vec::raw::memmove(dst, src, count) } } } @@ -2076,8 +2076,8 @@ mod tests { unsafe { // Test on-stack copy-from-buf. let a = ~[1, 2, 3]; - let mut ptr = unsafe::to_ptr(a); - let b = unsafe::from_buf(ptr, 3u); + let mut ptr = raw::to_ptr(a); + let b = raw::from_buf(ptr, 3u); assert (len(b) == 3u); assert (b[0] == 1); assert (b[1] == 2); @@ -2085,8 +2085,8 @@ mod tests { // Test on-heap copy-from-buf. let c = ~[1, 2, 3, 4, 5]; - ptr = unsafe::to_ptr(c); - let d = unsafe::from_buf(ptr, 5u); + ptr = raw::to_ptr(c); + let d = raw::from_buf(ptr, 5u); assert (len(d) == 5u); assert (d[0] == 1); assert (d[1] == 2); @@ -2869,9 +2869,9 @@ mod tests { fn to_mut_no_copy() { unsafe { let x = ~[1, 2, 3]; - let addr = unsafe::to_ptr(x); + let addr = raw::to_ptr(x); let x_mut = to_mut(x); - let addr_mut = unsafe::to_ptr(x_mut); + let addr_mut = raw::to_ptr(x_mut); assert addr == addr_mut; } } @@ -2880,9 +2880,9 @@ mod tests { fn from_mut_no_copy() { unsafe { let x = ~[mut 1, 2, 3]; - let addr = unsafe::to_ptr(x); + let addr = raw::to_ptr(x); let x_imm = from_mut(x); - let addr_imm = unsafe::to_ptr(x_imm); + let addr_imm = raw::to_ptr(x_imm); assert addr == addr_imm; } } |
