Skip to content

Commit 3d03c15

Browse files
committed
---
yaml --- r: 151545 b: refs/heads/try2 c: b40c3e9 h: refs/heads/master i: 151543: c962146 v: v3
1 parent 292ee3c commit 3d03c15

File tree

143 files changed

+841
-894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+841
-894
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a40b971aaf64f9ba189ac07eebf1890d995ae2dc
8+
refs/heads/try2: b40c3e9d3dd0a6be4d048389d33435f82205d376
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide-unsafe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ restrictions is undefined behaviour. For example, the following
6666
creates two aliasing `&mut` pointers, and is invalid.
6767

6868
```
69-
use std::cast;
69+
use std::mem;
7070
let mut x: u8 = 1;
7171
7272
let ref_1: &mut u8 = &mut x;
73-
let ref_2: &mut u8 = unsafe { cast::transmute_mut_lifetime(ref_1) };
73+
let ref_2: &mut u8 = unsafe { mem::transmute(&mut *ref_1) };
7474
7575
// oops, ref_1 and ref_2 point to the same piece of data (x) and are
7676
// both usable

branches/try2/src/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ to pointers to the trait name, used as a type.
14021402
let myshape: Box<Shape> = box mycircle as Box<Shape>;
14031403
~~~~
14041404

1405-
The resulting value is a managed box containing the value that was cast,
1405+
The resulting value is a box containing the value that was cast,
14061406
along with information that identifies the methods of the implementation that was used.
14071407
Values with a trait type can have [methods called](#method-call-expressions) on them,
14081408
for any method in the trait,

branches/try2/src/doc/tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ fn print_all<T: Printable>(printable_things: ~[T]) {
23852385
Declaring `T` as conforming to the `Printable` trait (as we earlier
23862386
did with `Clone`) makes it possible to call methods from that trait
23872387
on values of type `T` inside the function. It will also cause a
2388-
compile-time error when anyone tries to call `print_all` on an array
2388+
compile-time error when anyone tries to call `print_all` on a vector
23892389
whose element type does not have a `Printable` implementation.
23902390

23912391
Type parameters can have multiple bounds by separating them with `+`,
@@ -2428,9 +2428,9 @@ fn draw_all<T: Drawable>(shapes: ~[T]) {
24282428
# draw_all(~[c]);
24292429
~~~~
24302430

2431-
You can call that on an array of circles, or an array of rectangles
2431+
You can call that on a vector of circles, or a vector of rectangles
24322432
(assuming those have suitable `Drawable` traits defined), but not on
2433-
an array containing both circles and rectangles. When such behavior is
2433+
a vector containing both circles and rectangles. When such behavior is
24342434
needed, a trait name can alternately be used as a type, called
24352435
an _object_.
24362436

branches/try2/src/libarena/lib.rs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
extern crate collections;
2828

29-
use std::cast::{transmute, transmute_mut_lifetime};
30-
use std::cast;
3129
use std::cell::{Cell, RefCell};
3230
use std::cmp;
3331
use std::intrinsics::{TyDesc, get_tydesc};
@@ -137,7 +135,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
137135
let fill = chunk.fill.get();
138136

139137
while idx < fill {
140-
let tydesc_data: *uint = transmute(buf.offset(idx as int));
138+
let tydesc_data: *uint = mem::transmute(buf.offset(idx as int));
141139
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
142140
let (size, align) = ((*tydesc).size, (*tydesc).align);
143141

@@ -187,28 +185,27 @@ impl Arena {
187185
#[inline]
188186
fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
189187
unsafe {
190-
let this = transmute_mut_lifetime(self);
191-
let start = round_up(this.copy_head.fill.get(), align);
188+
let start = round_up(self.copy_head.fill.get(), align);
192189
let end = start + n_bytes;
193190
if end > self.chunk_size() {
194-
return this.alloc_copy_grow(n_bytes, align);
191+
return self.alloc_copy_grow(n_bytes, align);
195192
}
196-
this.copy_head.fill.set(end);
193+
self.copy_head.fill.set(end);
197194

198195
//debug!("idx = {}, size = {}, align = {}, fill = {}",
199196
// start, n_bytes, align, head.fill.get());
200197

201-
this.copy_head.as_ptr().offset(start as int)
198+
self.copy_head.as_ptr().offset(start as int)
202199
}
203200
}
204201

205202
#[inline]
206203
fn alloc_copy<'a, T>(&'a mut self, op: || -> T) -> &'a T {
207204
unsafe {
208205
let ptr = self.alloc_copy_inner(mem::size_of::<T>(), min_align_of::<T>());
209-
let ptr: *mut T = transmute(ptr);
206+
let ptr = ptr as *mut T;
210207
mem::move_val_init(&mut (*ptr), op());
211-
return transmute(ptr);
208+
return &*ptr;
212209
}
213210
}
214211

@@ -228,26 +225,16 @@ impl Arena {
228225
fn alloc_noncopy_inner(&mut self, n_bytes: uint, align: uint)
229226
-> (*u8, *u8) {
230227
unsafe {
231-
let start;
232-
let end;
233-
let tydesc_start;
234-
let after_tydesc;
235-
236-
{
237-
let head = transmute_mut_lifetime(&mut self.head);
238-
239-
tydesc_start = head.fill.get();
240-
after_tydesc = head.fill.get() + mem::size_of::<*TyDesc>();
241-
start = round_up(after_tydesc, align);
242-
end = start + n_bytes;
243-
}
228+
let tydesc_start = self.head.fill.get();
229+
let after_tydesc = self.head.fill.get() + mem::size_of::<*TyDesc>();
230+
let start = round_up(after_tydesc, align);
231+
let end = start + n_bytes;
244232

245233
if end > self.head.capacity() {
246234
return self.alloc_noncopy_grow(n_bytes, align);
247235
}
248236

249-
let head = transmute_mut_lifetime(&mut self.head);
250-
head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>()));
237+
self.head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>()));
251238

252239
//debug!("idx = {}, size = {}, align = {}, fill = {}",
253240
// start, n_bytes, align, head.fill);
@@ -263,18 +250,18 @@ impl Arena {
263250
let tydesc = get_tydesc::<T>();
264251
let (ty_ptr, ptr) =
265252
self.alloc_noncopy_inner(mem::size_of::<T>(), min_align_of::<T>());
266-
let ty_ptr: *mut uint = transmute(ty_ptr);
267-
let ptr: *mut T = transmute(ptr);
253+
let ty_ptr = ty_ptr as *mut uint;
254+
let ptr = ptr as *mut T;
268255
// Write in our tydesc along with a bit indicating that it
269256
// has *not* been initialized yet.
270-
*ty_ptr = transmute(tydesc);
257+
*ty_ptr = mem::transmute(tydesc);
271258
// Actually initialize it
272259
mem::move_val_init(&mut(*ptr), op());
273260
// Now that we are done, update the tydesc to indicate that
274261
// the object is there.
275262
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
276263

277-
return transmute(ptr);
264+
return &*ptr;
278265
}
279266
}
280267

@@ -283,7 +270,7 @@ impl Arena {
283270
pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T {
284271
unsafe {
285272
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
286-
let this: &mut Arena = transmute::<&_, &mut _>(self);
273+
let this: &mut Arena = mem::transmute::<&_, &mut _>(self);
287274
if intrinsics::needs_drop::<T>() {
288275
this.alloc_noncopy(op)
289276
} else {
@@ -366,7 +353,7 @@ impl<T> TypedArenaChunk<T> {
366353

367354
let mut chunk = unsafe {
368355
let chunk = exchange_malloc(size);
369-
let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
356+
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
370357
mem::move_val_init(&mut chunk.next, next);
371358
chunk
372359
};
@@ -387,7 +374,7 @@ impl<T> TypedArenaChunk<T> {
387374

388375
let mut chunk = unsafe {
389376
let chunk = exchange_malloc(size, min_align_of::<TypedArenaChunk<T>>());
390-
let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
377+
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
391378
mem::move_val_init(&mut chunk.next, next);
392379
chunk
393380
};
@@ -425,7 +412,7 @@ impl<T> TypedArenaChunk<T> {
425412
fn start(&self) -> *u8 {
426413
let this: *TypedArenaChunk<T> = self;
427414
unsafe {
428-
cast::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
415+
mem::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
429416
}
430417
}
431418

@@ -463,12 +450,12 @@ impl<T> TypedArena<T> {
463450
pub fn alloc<'a>(&'a self, object: T) -> &'a T {
464451
unsafe {
465452
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
466-
let this: &mut TypedArena<T> = cast::transmute::<&_, &mut _>(self);
453+
let this: &mut TypedArena<T> = mem::transmute::<&_, &mut _>(self);
467454
if this.ptr == this.end {
468455
this.grow()
469456
}
470457

471-
let ptr: &'a mut T = cast::transmute(this.ptr);
458+
let ptr: &'a mut T = mem::transmute(this.ptr);
472459
mem::move_val_init(ptr, object);
473460
this.ptr = this.ptr.offset(1);
474461
let ptr: &'a T = ptr;

branches/try2/src/libcollections/dlist.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
// Backlinks over DList::prev are raw pointers that form a full chain in
2222
// the reverse direction.
2323

24-
use std::cast;
2524
use std::iter::Rev;
2625
use std::iter;
27-
use std::mem::{replace, swap};
26+
use std::mem;
2827
use std::ptr;
2928

3029
use deque::Deque;
@@ -93,13 +92,13 @@ impl<T> Rawlink<T> {
9392
if self.p.is_null() {
9493
None
9594
} else {
96-
Some(unsafe { cast::transmute(self.p) })
95+
Some(unsafe { mem::transmute(self.p) })
9796
}
9897
}
9998

10099
/// Return the `Rawlink` and replace with `Rawlink::none()`
101100
fn take(&mut self) -> Rawlink<T> {
102-
replace(self, Rawlink::none())
101+
mem::replace(self, Rawlink::none())
103102
}
104103
}
105104

@@ -159,7 +158,7 @@ impl<T> DList<T> {
159158
Some(ref mut head) => {
160159
new_head.prev = Rawlink::none();
161160
head.prev = Rawlink::some(new_head);
162-
swap(head, &mut new_head);
161+
mem::swap(head, &mut new_head);
163162
head.next = Some(new_head);
164163
}
165164
}
@@ -317,7 +316,7 @@ impl<T> DList<T> {
317316
/// O(1)
318317
#[inline]
319318
pub fn prepend(&mut self, mut other: DList<T>) {
320-
swap(self, &mut other);
319+
mem::swap(self, &mut other);
321320
self.append(other);
322321
}
323322

branches/try2/src/libcollections/enum_set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<E:CLike> Iterator<E> for Items<E> {
137137
#[cfg(test)]
138138
mod test {
139139

140-
use std::cast;
140+
use std::mem;
141141

142142
use enum_set::{EnumSet, CLike};
143143

@@ -153,7 +153,7 @@ mod test {
153153
}
154154

155155
fn from_uint(v: uint) -> Foo {
156-
unsafe { cast::transmute(v) }
156+
unsafe { mem::transmute(v) }
157157
}
158158
}
159159

branches/try2/src/libcollections/hashmap.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ use std::result::{Ok, Err};
3030
use std::slice::ImmutableVector;
3131

3232
mod table {
33-
extern crate libc;
34-
3533
use std::clone::Clone;
3634
use std::cmp;
3735
use std::cmp::Eq;
@@ -42,10 +40,10 @@ mod table {
4240
use std::prelude::Drop;
4341
use std::ptr;
4442
use std::ptr::RawPtr;
45-
use std::rt::libc_heap;
46-
use std::intrinsics::{size_of, min_align_of, transmute};
47-
use std::intrinsics::{move_val_init, set_memory};
43+
use std::mem::{min_align_of, size_of};
44+
use std::intrinsics::{move_val_init, set_memory, transmute};
4845
use std::iter::{Iterator, range_step_inclusive};
46+
use std::rt::heap::{allocate, deallocate};
4947

5048
static EMPTY_BUCKET: u64 = 0u64;
5149

@@ -185,10 +183,6 @@ mod table {
185183
assert_eq!(round_up_to_next(5, 4), 8);
186184
}
187185

188-
fn has_alignment(n: uint, alignment: uint) -> bool {
189-
round_up_to_next(n, alignment) == n
190-
}
191-
192186
// Returns a tuple of (minimum required malloc alignment, hash_offset,
193187
// key_offset, val_offset, array_size), from the start of a mallocated array.
194188
fn calculate_offsets(
@@ -243,12 +237,7 @@ mod table {
243237
keys_size, min_align_of::< K >(),
244238
vals_size, min_align_of::< V >());
245239

246-
let buffer = libc_heap::malloc_raw(size) as *mut u8;
247-
248-
// FIXME #13094: If malloc was not at as aligned as we expected,
249-
// our offset calculations are just plain wrong. We could support
250-
// any alignment if we switched from `malloc` to `posix_memalign`.
251-
assert!(has_alignment(buffer as uint, malloc_alignment));
240+
let buffer = allocate(size, malloc_alignment);
252241

253242
let hashes = buffer.offset(hash_offset as int) as *mut u64;
254243
let keys = buffer.offset(keys_offset as int) as *mut K;
@@ -418,7 +407,7 @@ mod table {
418407
// modified to no longer assume this.
419408
#[test]
420409
fn can_alias_safehash_as_u64() {
421-
unsafe { assert_eq!(size_of::<SafeHash>(), size_of::<u64>()) };
410+
assert_eq!(size_of::<SafeHash>(), size_of::<u64>())
422411
}
423412

424413
pub struct Entries<'a, K, V> {
@@ -560,8 +549,15 @@ mod table {
560549

561550
assert_eq!(self.size, 0);
562551

552+
let hashes_size = self.capacity * size_of::<u64>();
553+
let keys_size = self.capacity * size_of::<K>();
554+
let vals_size = self.capacity * size_of::<V>();
555+
let (align, _, _, _, size) = calculate_offsets(hashes_size, min_align_of::<u64>(),
556+
keys_size, min_align_of::<K>(),
557+
vals_size, min_align_of::<V>());
558+
563559
unsafe {
564-
libc::free(self.hashes as *mut libc::c_void);
560+
deallocate(self.hashes as *mut u8, size, align);
565561
// Remember how everything was allocated out of one buffer
566562
// during initialization? We only need one call to free here.
567563
}

branches/try2/src/libcollections/lru_cache.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
//! assert!(cache.get(&2).is_none());
3838
//! ```
3939
40-
use std::cast;
4140
use std::container::Container;
4241
use std::hash::Hash;
4342
use std::fmt;
@@ -93,7 +92,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
9392
let cache = LruCache {
9493
map: HashMap::new(),
9594
max_size: capacity,
96-
head: unsafe{ cast::transmute(box mem::uninit::<LruEntry<K, V>>()) },
95+
head: unsafe{ mem::transmute(box mem::uninit::<LruEntry<K, V>>()) },
9796
};
9897
unsafe {
9998
(*cache.head).next = cache.head;
@@ -241,11 +240,11 @@ impl<K: Hash + TotalEq, V> Mutable for LruCache<K, V> {
241240
impl<K, V> Drop for LruCache<K, V> {
242241
fn drop(&mut self) {
243242
unsafe {
244-
let node: Box<LruEntry<K, V>> = cast::transmute(self.head);
243+
let node: Box<LruEntry<K, V>> = mem::transmute(self.head);
245244
// Prevent compiler from trying to drop the un-initialized field in the sigil node.
246245
let box LruEntry { key: k, value: v, .. } = node;
247-
cast::forget(k);
248-
cast::forget(v);
246+
mem::forget(k);
247+
mem::forget(v);
249248
}
250249
}
251250
}

branches/try2/src/libcore/any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! value. `Box<Any>` adds the `move` method, which will unwrap a `Box<T>` from the object. See
2121
//! the extension traits (`*Ext`) for the full details.
2222
23-
use cast::{transmute, transmute_copy};
23+
use mem::{transmute, transmute_copy};
2424
use option::{Option, Some, None};
2525
use owned::Box;
2626
use raw::TraitObject;

0 commit comments

Comments
 (0)