Skip to content

Commit ab210b5

Browse files
committed
---
yaml --- r: 30495 b: refs/heads/incoming c: 5d540de h: refs/heads/master i: 30493: 5911445 30491: fb15f49 30487: cf856c3 30479: 8ede134 30463: e17c8be v: v3
1 parent 82e5f3a commit ab210b5

35 files changed

+354
-183
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 8fbe4b58412b2818d4ef3d92259bdf5f88f61606
9+
refs/heads/incoming: 5d540de76993eb6dac9893138e45d0324c23e631
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/dvec.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export unwrap;
5050
* type could only produce 47 million pushes/second.
5151
*/
5252
type DVec_<A> = {
53-
mut data: ~[mut A]
53+
mut data: ~[A]
5454
};
5555

5656
enum DVec<A> {
@@ -59,21 +59,21 @@ enum DVec<A> {
5959

6060
/// Creates a new, empty dvec
6161
fn DVec<A>() -> DVec<A> {
62-
DVec_({mut data: ~[mut]})
62+
DVec_({mut data: ~[]})
6363
}
6464

6565
/// Creates a new dvec with a single element
6666
fn from_elem<A>(+e: A) -> DVec<A> {
67-
DVec_({mut data: ~[mut move e]})
67+
DVec_({mut data: ~[move e]})
6868
}
6969

7070
/// Creates a new dvec with the contents of a vector
71-
fn from_vec<A>(+v: ~[mut A]) -> DVec<A> {
71+
fn from_vec<A>(+v: ~[A]) -> DVec<A> {
7272
DVec_({mut data: move v})
7373
}
7474

7575
/// Consumes the vector and returns its contents
76-
fn unwrap<A>(+d: DVec<A>) -> ~[mut A] {
76+
fn unwrap<A>(+d: DVec<A>) -> ~[A] {
7777
let DVec_({data: v}) <- d;
7878
move v
7979
}
@@ -89,7 +89,7 @@ priv impl<A> DVec<A> {
8989
}
9090

9191
#[inline(always)]
92-
fn check_out<B>(f: fn(-~[mut A]) -> B) -> B {
92+
fn check_out<B>(f: fn(-~[A]) -> B) -> B {
9393
unsafe {
9494
let mut data = unsafe::reinterpret_cast(&null::<()>());
9595
data <-> self.data;
@@ -100,9 +100,9 @@ priv impl<A> DVec<A> {
100100
}
101101

102102
#[inline(always)]
103-
fn give_back(-data: ~[mut A]) {
103+
fn give_back(+data: ~[A]) {
104104
unsafe {
105-
self.data <- data;
105+
self.data = move data;
106106
}
107107
}
108108
}
@@ -122,10 +122,22 @@ impl<A> DVec<A> {
122122
* and return a new vector to replace it with.
123123
*/
124124
#[inline(always)]
125-
fn swap(f: fn(-~[mut A]) -> ~[mut A]) {
125+
fn swap(f: fn(-~[A]) -> ~[A]) {
126126
self.check_out(|v| self.give_back(f(move v)))
127127
}
128128

129+
/**
130+
* Swaps out the current vector and hands it off to a user-provided
131+
* function `f`. The function should transform it however is desired
132+
* and return a new vector to replace it with.
133+
*/
134+
#[inline(always)]
135+
fn swap_mut(f: fn(-~[mut A]) -> ~[mut A]) {
136+
do self.swap |v| {
137+
vec::from_mut(f(vec::to_mut(move v)))
138+
}
139+
}
140+
129141
/// Returns the number of elements currently in the dvec
130142
pure fn len() -> uint {
131143
unchecked {
@@ -138,7 +150,7 @@ impl<A> DVec<A> {
138150
}
139151

140152
/// Overwrite the current contents
141-
fn set(+w: ~[mut A]) {
153+
fn set(+w: ~[A]) {
142154
self.check_not_borrowed();
143155
self.data <- w;
144156
}
@@ -161,7 +173,7 @@ impl<A> DVec<A> {
161173
let data_ptr: *() = unsafe::reinterpret_cast(&data);
162174
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
163175
log(error, ~"a");
164-
self.data <- ~[mut move t];
176+
self.data <- ~[move t];
165177
vec::push_all_move(self.data, move data);
166178
log(error, ~"b");
167179
}
@@ -176,16 +188,17 @@ impl<A> DVec<A> {
176188
/// Remove and return the first element
177189
fn shift() -> A {
178190
do self.check_out |v| {
179-
let mut v = vec::from_mut(move v);
191+
let mut v = move v;
180192
let result = vec::shift(v);
181-
self.give_back(vec::to_mut(move v));
193+
self.give_back(move v);
182194
move result
183195
}
184196
}
185197
186198
/// Reverse the elements in the list, in place
187199
fn reverse() {
188200
do self.check_out |v| {
201+
let mut v = move v;
189202
vec::reverse(v);
190203
self.give_back(move v);
191204
}
@@ -203,6 +216,7 @@ impl<A> DVec<A> {
203216
/// Gives access to the vector as a slice with mutable contents
204217
fn borrow_mut<R>(op: fn(x: &[mut A]) -> R) -> R {
205218
do self.check_out |v| {
219+
let mut v = move v;
206220
let result = op(v);
207221
self.give_back(move v);
208222
move result
@@ -268,7 +282,7 @@ impl<A: Copy> DVec<A> {
268282
pure fn get() -> ~[A] {
269283
unchecked {
270284
do self.check_out |v| {
271-
let w = vec::from_mut(copy v);
285+
let w = copy v;
272286
self.give_back(move v);
273287
move w
274288
}
@@ -295,9 +309,9 @@ impl<A: Copy> DVec<A> {
295309
*/
296310
fn grow_set_elt(idx: uint, initval: A, val: A) {
297311
do self.swap |v| {
298-
let mut v <- v;
312+
let mut v = vec::to_mut(move v);
299313
vec::grow_set(v, idx, initval, val);
300-
move v
314+
move vec::from_mut(v)
301315
}
302316
}
303317

branches/incoming/src/libcore/hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pure fn hash_keyed_5<A: IterBytes,
130130
}
131131
}
132132

133-
pure fn hash_bytes_keyed(val: &[const u8], k0: u64, k1: u64) -> u64 {
133+
pure fn hash_bytes_keyed(val: &[u8], k0: u64, k1: u64) -> u64 {
134134
val.hash_keyed(k0, k1)
135135
}
136136
pure fn hash_str_keyed(val: &str, k0: u64, k1: u64) -> u64 {
@@ -152,7 +152,7 @@ pure fn hash_uint_keyed(val: uint, k0: u64, k1: u64) -> u64 {
152152
val.hash_keyed(k0, k1)
153153
}
154154

155-
pure fn hash_bytes(val: &[const u8]) -> u64 { hash_bytes_keyed(val, 0, 0) }
155+
pure fn hash_bytes(val: &[u8]) -> u64 { hash_bytes_keyed(val, 0, 0) }
156156
pure fn hash_str(val: &str) -> u64 { hash_str_keyed(val, 0, 0) }
157157
pure fn hash_u64(val: u64) -> u64 { hash_u64_keyed(val, 0, 0) }
158158
pure fn hash_u32(val: u32) -> u64 { hash_u32_keyed(val, 0, 0) }

branches/incoming/src/libcore/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn convert_whence(whence: SeekStyle) -> i32 {
214214

215215
impl *libc::FILE: Reader {
216216
fn read(buf: &[mut u8], len: uint) -> uint {
217-
do vec::as_buf(buf) |buf_p, buf_len| {
217+
do vec::as_mut_buf(buf) |buf_p, buf_len| {
218218
assert buf_len <= len;
219219

220220
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,

branches/incoming/src/libcore/ptr.rs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
export addr_of;
44
export to_unsafe_ptr;
5+
export to_const_unsafe_ptr;
56
export to_mut_unsafe_ptr;
67
export mut_addr_of;
78
export offset;
@@ -26,11 +27,16 @@ use libc::{c_void, size_t};
2627
#[abi = "cdecl"]
2728
extern mod libc_ {
2829
#[rust_stack]
29-
fn memcpy(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
30+
fn memcpy(dest: *mut c_void, src: *const c_void,
31+
n: libc::size_t) -> *c_void;
32+
3033
#[rust_stack]
31-
fn memmove(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
34+
fn memmove(dest: *mut c_void, src: *const c_void,
35+
n: libc::size_t) -> *c_void;
36+
3237
#[rust_stack]
33-
fn memset(dest: *c_void, c: libc::c_int, len: libc::size_t) -> *c_void;
38+
fn memset(dest: *mut c_void, c: libc::c_int,
39+
len: libc::size_t) -> *c_void;
3440
}
3541

3642
#[abi = "rust-intrinsic"]
@@ -105,9 +111,9 @@ pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
105111
* and destination may not overlap.
106112
*/
107113
#[inline(always)]
108-
unsafe fn memcpy<T>(dst: *T, src: *T, count: uint) {
114+
unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
109115
let n = count * sys::size_of::<T>();
110-
libc_::memcpy(dst as *c_void, src as *c_void, n as size_t);
116+
libc_::memcpy(dst as *mut c_void, src as *c_void, n as size_t);
111117
}
112118

113119
/**
@@ -117,15 +123,15 @@ unsafe fn memcpy<T>(dst: *T, src: *T, count: uint) {
117123
* and destination may overlap.
118124
*/
119125
#[inline(always)]
120-
unsafe fn memmove<T>(dst: *T, src: *T, count: uint) {
126+
unsafe fn memmove<T>(dst: *mut T, src: *const T, count: uint) {
121127
let n = count * sys::size_of::<T>();
122-
libc_::memmove(dst as *c_void, src as *c_void, n as size_t);
128+
libc_::memmove(dst as *mut c_void, src as *c_void, n as size_t);
123129
}
124130

125131
#[inline(always)]
126132
unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
127133
let n = count * sys::size_of::<T>();
128-
libc_::memset(dst as *c_void, c as libc::c_int, n as size_t);
134+
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
129135
}
130136

131137

@@ -135,8 +141,18 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
135141
reinterpret_cast.
136142
*/
137143
#[inline(always)]
138-
fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
139-
unsafe::reinterpret_cast(&thing)
144+
fn to_unsafe_ptr<T>(thing: &T) -> *T {
145+
unsafe { unsafe::reinterpret_cast(&thing) }
146+
}
147+
148+
/**
149+
Transform a const region pointer - &const T - to a const unsafe pointer -
150+
*const T. This is safe, but is implemented with an unsafe block due to
151+
reinterpret_cast.
152+
*/
153+
#[inline(always)]
154+
fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
155+
unsafe { unsafe::reinterpret_cast(&thing) }
140156
}
141157

142158
/**
@@ -145,8 +161,8 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
145161
reinterpret_cast.
146162
*/
147163
#[inline(always)]
148-
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T unsafe {
149-
unsafe::reinterpret_cast(&thing)
164+
fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
165+
unsafe { unsafe::reinterpret_cast(&thing) }
150166
}
151167

152168
/**
@@ -246,16 +262,16 @@ fn test() {
246262
assert (p.fst == 50);
247263
assert (p.snd == 60);
248264

249-
let v0 = ~[32000u16, 32001u16, 32002u16];
250-
let v1 = ~[0u16, 0u16, 0u16];
265+
let mut v0 = ~[32000u16, 32001u16, 32002u16];
266+
let mut v1 = ~[0u16, 0u16, 0u16];
251267

252-
ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 1u),
268+
ptr::memcpy(ptr::mut_offset(vec::unsafe::to_mut_ptr(v1), 1u),
253269
ptr::offset(vec::unsafe::to_ptr(v0), 1u), 1u);
254270
assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16);
255-
ptr::memcpy(vec::unsafe::to_ptr(v1),
271+
ptr::memcpy(vec::unsafe::to_mut_ptr(v1),
256272
ptr::offset(vec::unsafe::to_ptr(v0), 2u), 1u);
257273
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16);
258-
ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 2u),
274+
ptr::memcpy(ptr::mut_offset(vec::unsafe::to_mut_ptr(v1), 2u),
259275
vec::unsafe::to_ptr(v0), 1u);
260276
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16);
261277
}

branches/incoming/src/libcore/str.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ fn push_str_no_overallocate(&lhs: ~str, rhs: &str) {
250250
do as_buf(lhs) |lbuf, _llen| {
251251
do as_buf(rhs) |rbuf, _rlen| {
252252
let dst = ptr::offset(lbuf, llen);
253+
let dst = ::unsafe::transmute_mut_unsafe(dst);
253254
ptr::memcpy(dst, rbuf, rlen);
254255
}
255256
}
@@ -266,6 +267,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
266267
do as_buf(lhs) |lbuf, _llen| {
267268
do as_buf(rhs) |rbuf, _rlen| {
268269
let dst = ptr::offset(lbuf, llen);
270+
let dst = ::unsafe::transmute_mut_unsafe(dst);
269271
ptr::memcpy(dst, rbuf, rlen);
270272
}
271273
}
@@ -1990,7 +1992,10 @@ mod unsafe {
19901992
unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str {
19911993
let mut v: ~[mut u8] = ~[mut];
19921994
vec::reserve(v, len + 1u);
1993-
vec::as_buf(v, |b, _len| ptr::memcpy(b, buf as *u8, len));
1995+
vec::as_buf(v, |vbuf, _len| {
1996+
let vbuf = ::unsafe::transmute_mut_unsafe(vbuf);
1997+
ptr::memcpy(vbuf, buf as *u8, len)
1998+
});
19941999
vec::unsafe::set_len(v, len);
19952000
vec::push(v, 0u8);
19962001

@@ -2045,6 +2050,7 @@ mod unsafe {
20452050
vec::reserve(v, end - begin + 1u);
20462051
unsafe {
20472052
do vec::as_buf(v) |vbuf, _vlen| {
2053+
let vbuf = ::unsafe::transmute_mut_unsafe(vbuf);
20482054
let src = ptr::offset(sbuf, begin);
20492055
ptr::memcpy(vbuf, src, end - begin);
20502056
}

0 commit comments

Comments
 (0)