Skip to content

Commit 70bd1c9

Browse files
committed
---
yaml --- r: 114011 b: refs/heads/master c: a40b971 h: refs/heads/master i: 114009: e716b0a 114007: 2b66b0f v: v3
1 parent f37b2bb commit 70bd1c9

File tree

143 files changed

+911
-842
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

+911
-842
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: f483aa3a91ff9baf290ddf22209b984ec1f74b0c
2+
refs/heads/master: a40b971aaf64f9ba189ac07eebf1890d995ae2dc
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

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

trunk/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 box containing the value that was cast,
1405+
The resulting value is a managed 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,

trunk/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 a vector
2388+
compile-time error when anyone tries to call `print_all` on an array
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 a vector of circles, or a vector of rectangles
2431+
You can call that on an array of circles, or an array of rectangles
24322432
(assuming those have suitable `Drawable` traits defined), but not on
2433-
a vector containing both circles and rectangles. When such behavior is
2433+
an array 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

trunk/src/libarena/lib.rs

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

2727
extern crate collections;
2828

29+
use std::cast::{transmute, transmute_mut_lifetime};
30+
use std::cast;
2931
use std::cell::{Cell, RefCell};
3032
use std::cmp;
3133
use std::intrinsics::{TyDesc, get_tydesc};
@@ -135,7 +137,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
135137
let fill = chunk.fill.get();
136138

137139
while idx < fill {
138-
let tydesc_data: *uint = mem::transmute(buf.offset(idx as int));
140+
let tydesc_data: *uint = transmute(buf.offset(idx as int));
139141
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
140142
let (size, align) = ((*tydesc).size, (*tydesc).align);
141143

@@ -185,27 +187,28 @@ impl Arena {
185187
#[inline]
186188
fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
187189
unsafe {
188-
let start = round_up(self.copy_head.fill.get(), align);
190+
let this = transmute_mut_lifetime(self);
191+
let start = round_up(this.copy_head.fill.get(), align);
189192
let end = start + n_bytes;
190193
if end > self.chunk_size() {
191-
return self.alloc_copy_grow(n_bytes, align);
194+
return this.alloc_copy_grow(n_bytes, align);
192195
}
193-
self.copy_head.fill.set(end);
196+
this.copy_head.fill.set(end);
194197

195198
//debug!("idx = {}, size = {}, align = {}, fill = {}",
196199
// start, n_bytes, align, head.fill.get());
197200

198-
self.copy_head.as_ptr().offset(start as int)
201+
this.copy_head.as_ptr().offset(start as int)
199202
}
200203
}
201204

202205
#[inline]
203206
fn alloc_copy<'a, T>(&'a mut self, op: || -> T) -> &'a T {
204207
unsafe {
205208
let ptr = self.alloc_copy_inner(mem::size_of::<T>(), min_align_of::<T>());
206-
let ptr = ptr as *mut T;
209+
let ptr: *mut T = transmute(ptr);
207210
mem::move_val_init(&mut (*ptr), op());
208-
return &*ptr;
211+
return transmute(ptr);
209212
}
210213
}
211214

@@ -225,16 +228,26 @@ impl Arena {
225228
fn alloc_noncopy_inner(&mut self, n_bytes: uint, align: uint)
226229
-> (*u8, *u8) {
227230
unsafe {
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;
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+
}
232244

233245
if end > self.head.capacity() {
234246
return self.alloc_noncopy_grow(n_bytes, align);
235247
}
236248

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

239252
//debug!("idx = {}, size = {}, align = {}, fill = {}",
240253
// start, n_bytes, align, head.fill);
@@ -250,18 +263,18 @@ impl Arena {
250263
let tydesc = get_tydesc::<T>();
251264
let (ty_ptr, ptr) =
252265
self.alloc_noncopy_inner(mem::size_of::<T>(), min_align_of::<T>());
253-
let ty_ptr = ty_ptr as *mut uint;
254-
let ptr = ptr as *mut T;
266+
let ty_ptr: *mut uint = transmute(ty_ptr);
267+
let ptr: *mut T = transmute(ptr);
255268
// Write in our tydesc along with a bit indicating that it
256269
// has *not* been initialized yet.
257-
*ty_ptr = mem::transmute(tydesc);
270+
*ty_ptr = transmute(tydesc);
258271
// Actually initialize it
259272
mem::move_val_init(&mut(*ptr), op());
260273
// Now that we are done, update the tydesc to indicate that
261274
// the object is there.
262275
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
263276

264-
return &*ptr;
277+
return transmute(ptr);
265278
}
266279
}
267280

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

354367
let mut chunk = unsafe {
355368
let chunk = exchange_malloc(size);
356-
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
369+
let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
357370
mem::move_val_init(&mut chunk.next, next);
358371
chunk
359372
};
@@ -374,7 +387,7 @@ impl<T> TypedArenaChunk<T> {
374387

375388
let mut chunk = unsafe {
376389
let chunk = exchange_malloc(size, min_align_of::<TypedArenaChunk<T>>());
377-
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
390+
let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
378391
mem::move_val_init(&mut chunk.next, next);
379392
chunk
380393
};
@@ -412,7 +425,7 @@ impl<T> TypedArenaChunk<T> {
412425
fn start(&self) -> *u8 {
413426
let this: *TypedArenaChunk<T> = self;
414427
unsafe {
415-
mem::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
428+
cast::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
416429
}
417430
}
418431

@@ -450,12 +463,12 @@ impl<T> TypedArena<T> {
450463
pub fn alloc<'a>(&'a self, object: T) -> &'a T {
451464
unsafe {
452465
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
453-
let this: &mut TypedArena<T> = mem::transmute::<&_, &mut _>(self);
466+
let this: &mut TypedArena<T> = cast::transmute::<&_, &mut _>(self);
454467
if this.ptr == this.end {
455468
this.grow()
456469
}
457470

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

trunk/src/libcollections/dlist.rs

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

24+
use std::cast;
2425
use std::iter::Rev;
2526
use std::iter;
26-
use std::mem;
27+
use std::mem::{replace, swap};
2728
use std::ptr;
2829

2930
use deque::Deque;
@@ -92,13 +93,13 @@ impl<T> Rawlink<T> {
9293
if self.p.is_null() {
9394
None
9495
} else {
95-
Some(unsafe { mem::transmute(self.p) })
96+
Some(unsafe { cast::transmute(self.p) })
9697
}
9798
}
9899

99100
/// Return the `Rawlink` and replace with `Rawlink::none()`
100101
fn take(&mut self) -> Rawlink<T> {
101-
mem::replace(self, Rawlink::none())
102+
replace(self, Rawlink::none())
102103
}
103104
}
104105

@@ -158,7 +159,7 @@ impl<T> DList<T> {
158159
Some(ref mut head) => {
159160
new_head.prev = Rawlink::none();
160161
head.prev = Rawlink::some(new_head);
161-
mem::swap(head, &mut new_head);
162+
swap(head, &mut new_head);
162163
head.next = Some(new_head);
163164
}
164165
}
@@ -316,7 +317,7 @@ impl<T> DList<T> {
316317
/// O(1)
317318
#[inline]
318319
pub fn prepend(&mut self, mut other: DList<T>) {
319-
mem::swap(self, &mut other);
320+
swap(self, &mut other);
320321
self.append(other);
321322
}
322323

trunk/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::mem;
140+
use std::cast;
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 { mem::transmute(v) }
156+
unsafe { cast::transmute(v) }
157157
}
158158
}
159159

trunk/src/libcollections/hashmap.rs

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

3232
mod table {
33+
extern crate libc;
34+
3335
use std::clone::Clone;
3436
use std::cmp;
3537
use std::cmp::Eq;
@@ -40,10 +42,10 @@ mod table {
4042
use std::prelude::Drop;
4143
use std::ptr;
4244
use std::ptr::RawPtr;
43-
use std::mem::{min_align_of, size_of};
44-
use std::intrinsics::{move_val_init, set_memory, transmute};
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};
4548
use std::iter::{Iterator, range_step_inclusive};
46-
use std::rt::heap::{allocate, deallocate};
4749

4850
static EMPTY_BUCKET: u64 = 0u64;
4951

@@ -183,6 +185,10 @@ mod table {
183185
assert_eq!(round_up_to_next(5, 4), 8);
184186
}
185187

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

240-
let buffer = allocate(size, malloc_alignment);
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));
241252

242253
let hashes = buffer.offset(hash_offset as int) as *mut u64;
243254
let keys = buffer.offset(keys_offset as int) as *mut K;
@@ -407,7 +418,7 @@ mod table {
407418
// modified to no longer assume this.
408419
#[test]
409420
fn can_alias_safehash_as_u64() {
410-
assert_eq!(size_of::<SafeHash>(), size_of::<u64>())
421+
unsafe { assert_eq!(size_of::<SafeHash>(), size_of::<u64>()) };
411422
}
412423

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

550561
assert_eq!(self.size, 0);
551562

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-
559563
unsafe {
560-
deallocate(self.hashes as *mut u8, size, align);
564+
libc::free(self.hashes as *mut libc::c_void);
561565
// Remember how everything was allocated out of one buffer
562566
// during initialization? We only need one call to free here.
563567
}

trunk/src/libcollections/lru_cache.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
//! assert!(cache.get(&2).is_none());
3838
//! ```
3939
40+
use std::cast;
4041
use std::container::Container;
4142
use std::hash::Hash;
4243
use std::fmt;
@@ -92,7 +93,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
9293
let cache = LruCache {
9394
map: HashMap::new(),
9495
max_size: capacity,
95-
head: unsafe{ mem::transmute(box mem::uninit::<LruEntry<K, V>>()) },
96+
head: unsafe{ cast::transmute(box mem::uninit::<LruEntry<K, V>>()) },
9697
};
9798
unsafe {
9899
(*cache.head).next = cache.head;
@@ -240,11 +241,11 @@ impl<K: Hash + TotalEq, V> Mutable for LruCache<K, V> {
240241
impl<K, V> Drop for LruCache<K, V> {
241242
fn drop(&mut self) {
242243
unsafe {
243-
let node: Box<LruEntry<K, V>> = mem::transmute(self.head);
244+
let node: Box<LruEntry<K, V>> = cast::transmute(self.head);
244245
// Prevent compiler from trying to drop the un-initialized field in the sigil node.
245246
let box LruEntry { key: k, value: v, .. } = node;
246-
mem::forget(k);
247-
mem::forget(v);
247+
cast::forget(k);
248+
cast::forget(v);
248249
}
249250
}
250251
}

trunk/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 mem::{transmute, transmute_copy};
23+
use cast::{transmute, transmute_copy};
2424
use option::{Option, Some, None};
2525
use owned::Box;
2626
use raw::TraitObject;

0 commit comments

Comments
 (0)