Skip to content

Commit 0f3c064

Browse files
committed
---
yaml --- r: 130619 b: refs/heads/snap-stage3 c: c6633fd h: refs/heads/master i: 130617: 2df4007 130615: 0590e4d v: v3
1 parent 9ce2016 commit 0f3c064

Some content is hidden

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

49 files changed

+326
-623
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: ee72e46638f2b2ae92e99df2a7ea92690baa0d07
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ab7b1c896d5d929f3e150bf62c69b1459427a538
4+
refs/heads/snap-stage3: c6633fde5302be357014c9aa14461857d99d0075
55
refs/heads/try: a2473a89da106f7dd3be86e9d52fe23f43d5bfa5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/doc/guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ but also working properly. And printing information to the screen is a pretty
116116
common thing to do.
117117

118118
The first thing that we need to do is make a file to put our code in. I like
119-
to make a `projects` directory in my home directory, and keep all my projects
119+
to make a projects directory in my home directory, and keep all my projects
120120
there. Rust does not care where your code lives.
121121

122122
This actually leads to one other concern we should address: this tutorial will
@@ -765,7 +765,7 @@ This is a deliberate design decision. While full-program inference is possible,
765765
languages which have it, like Haskell, often suggest that documenting your
766766
types explicitly is a best-practice. We agree that forcing functions to declare
767767
types while allowing for inference inside of function bodies is a wonderful
768-
sweet spot between full inference and no inference.
768+
compromise between full inference and no inference.
769769

770770
What about returning a value? Here's a function that adds one to an integer:
771771

branches/snap-stage3/src/liballoc/heap.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use core::ptr::RawPtr;
1616
#[cfg(not(test))] use core::raw;
17-
#[cfg(stage0, not(test))] use util;
17+
#[cfg(not(test))] use util;
1818

1919
/// Returns a pointer to `size` bytes of memory.
2020
///
@@ -119,7 +119,7 @@ unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
119119
}
120120

121121
// FIXME: #7496
122-
#[cfg(stage0, not(test))]
122+
#[cfg(not(test))]
123123
#[lang="closure_exchange_malloc"]
124124
#[inline]
125125
#[allow(deprecated)]
@@ -134,21 +134,6 @@ unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
134134
alloc as *mut u8
135135
}
136136

137-
// FIXME: #7496
138-
#[cfg(not(stage0), not(test))]
139-
#[lang="closure_exchange_malloc"]
140-
#[inline]
141-
#[allow(deprecated)]
142-
unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint,
143-
align: uint) -> *mut u8 {
144-
let p = allocate(size, align);
145-
146-
let alloc = p as *mut raw::Box<()>;
147-
(*alloc).drop_glue = drop_glue;
148-
149-
alloc as *mut u8
150-
}
151-
152137
#[cfg(jemalloc)]
153138
mod imp {
154139
use core::option::{None, Option};

branches/snap-stage3/src/libarena/lib.rs

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,17 @@ use std::mem;
3939
use std::num;
4040
use std::ptr;
4141
use std::rc::Rc;
42-
use std::rt::heap::{allocate, deallocate};
42+
use std::rt::heap::allocate;
4343

4444
// The way arena uses arrays is really deeply awful. The arrays are
4545
// allocated, and have capacities reserved, but the fill for the array
4646
// will always stay at 0.
4747
#[deriving(Clone, PartialEq)]
4848
struct Chunk {
49-
data: Rc<RefCell<Vec<u8>>>,
49+
data: Rc<RefCell<Vec<u8> >>,
5050
fill: Cell<uint>,
5151
is_copy: Cell<bool>,
5252
}
53-
5453
impl Chunk {
5554
fn capacity(&self) -> uint {
5655
self.data.borrow().capacity()
@@ -358,37 +357,38 @@ pub struct TypedArena<T> {
358357
end: Cell<*const T>,
359358

360359
/// A pointer to the first arena segment.
361-
first: RefCell<*mut TypedArenaChunk<T>>,
360+
first: RefCell<TypedArenaChunkRef<T>>,
362361
}
362+
type TypedArenaChunkRef<T> = Option<Box<TypedArenaChunk<T>>>;
363363

364364
struct TypedArenaChunk<T> {
365365
/// Pointer to the next arena segment.
366-
next: *mut TypedArenaChunk<T>,
366+
next: TypedArenaChunkRef<T>,
367367

368368
/// The number of elements that this chunk can hold.
369369
capacity: uint,
370370

371371
// Objects follow here, suitably aligned.
372372
}
373373

374-
fn calculate_size<T>(capacity: uint) -> uint {
375-
let mut size = mem::size_of::<TypedArenaChunk<T>>();
376-
size = round_up(size, mem::min_align_of::<T>());
377-
let elem_size = mem::size_of::<T>();
378-
let elems_size = elem_size.checked_mul(&capacity).unwrap();
379-
size = size.checked_add(&elems_size).unwrap();
380-
size
381-
}
382-
383374
impl<T> TypedArenaChunk<T> {
384375
#[inline]
385-
unsafe fn new(next: *mut TypedArenaChunk<T>, capacity: uint)
386-
-> *mut TypedArenaChunk<T> {
387-
let size = calculate_size::<T>(capacity);
388-
let chunk = allocate(size, mem::min_align_of::<TypedArenaChunk<T>>())
389-
as *mut TypedArenaChunk<T>;
390-
(*chunk).next = next;
391-
(*chunk).capacity = capacity;
376+
fn new(next: Option<Box<TypedArenaChunk<T>>>, capacity: uint)
377+
-> Box<TypedArenaChunk<T>> {
378+
let mut size = mem::size_of::<TypedArenaChunk<T>>();
379+
size = round_up(size, mem::min_align_of::<T>());
380+
let elem_size = mem::size_of::<T>();
381+
let elems_size = elem_size.checked_mul(&capacity).unwrap();
382+
size = size.checked_add(&elems_size).unwrap();
383+
384+
let mut chunk = unsafe {
385+
let chunk = allocate(size, mem::min_align_of::<TypedArenaChunk<T>>());
386+
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
387+
ptr::write(&mut chunk.next, next);
388+
chunk
389+
};
390+
391+
chunk.capacity = capacity;
392392
chunk
393393
}
394394

@@ -406,13 +406,14 @@ impl<T> TypedArenaChunk<T> {
406406
}
407407

408408
// Destroy the next chunk.
409-
let next = self.next;
410-
let size = calculate_size::<T>(self.capacity);
411-
deallocate(self as *mut TypedArenaChunk<T> as *mut u8, size,
412-
mem::min_align_of::<TypedArenaChunk<T>>());
413-
if next.is_not_null() {
414-
let capacity = (*next).capacity;
415-
(*next).destroy(capacity);
409+
let next_opt = mem::replace(&mut self.next, None);
410+
match next_opt {
411+
None => {}
412+
Some(mut next) => {
413+
// We assume that the next chunk is completely filled.
414+
let capacity = next.capacity;
415+
next.destroy(capacity)
416+
}
416417
}
417418
}
418419

@@ -447,13 +448,11 @@ impl<T> TypedArena<T> {
447448
/// objects.
448449
#[inline]
449450
pub fn with_capacity(capacity: uint) -> TypedArena<T> {
450-
unsafe {
451-
let chunk = TypedArenaChunk::<T>::new(ptr::mut_null(), capacity);
452-
TypedArena {
453-
ptr: Cell::new((*chunk).start() as *const T),
454-
end: Cell::new((*chunk).end() as *const T),
455-
first: RefCell::new(chunk),
456-
}
451+
let chunk = TypedArenaChunk::<T>::new(None, capacity);
452+
TypedArena {
453+
ptr: Cell::new(chunk.start() as *const T),
454+
end: Cell::new(chunk.end() as *const T),
455+
first: RefCell::new(Some(chunk)),
457456
}
458457
}
459458

@@ -477,28 +476,26 @@ impl<T> TypedArena<T> {
477476
/// Grows the arena.
478477
#[inline(never)]
479478
fn grow(&self) {
480-
unsafe {
481-
let chunk = *self.first.borrow_mut();
482-
let new_capacity = (*chunk).capacity.checked_mul(&2).unwrap();
483-
let chunk = TypedArenaChunk::<T>::new(chunk, new_capacity);
484-
self.ptr.set((*chunk).start() as *const T);
485-
self.end.set((*chunk).end() as *const T);
486-
*self.first.borrow_mut() = chunk
487-
}
479+
let chunk = self.first.borrow_mut().take().unwrap();
480+
let new_capacity = chunk.capacity.checked_mul(&2).unwrap();
481+
let chunk = TypedArenaChunk::<T>::new(Some(chunk), new_capacity);
482+
self.ptr.set(chunk.start() as *const T);
483+
self.end.set(chunk.end() as *const T);
484+
*self.first.borrow_mut() = Some(chunk)
488485
}
489486
}
490487

491488
#[unsafe_destructor]
492489
impl<T> Drop for TypedArena<T> {
493490
fn drop(&mut self) {
494-
unsafe {
495-
// Determine how much was filled.
496-
let start = self.first.borrow().as_ref().unwrap().start() as uint;
497-
let end = self.ptr.get() as uint;
498-
let diff = (end - start) / mem::size_of::<T>();
491+
// Determine how much was filled.
492+
let start = self.first.borrow().as_ref().unwrap().start() as uint;
493+
let end = self.ptr.get() as uint;
494+
let diff = (end - start) / mem::size_of::<T>();
499495

500-
// Pass that to the `destroy` method.
501-
(**self.first.borrow_mut()).destroy(diff)
496+
// Pass that to the `destroy` method.
497+
unsafe {
498+
self.first.borrow_mut().as_mut().unwrap().destroy(diff)
502499
}
503500
}
504501
}

branches/snap-stage3/src/libcore/num/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub trait Int: Primitive
406406
///
407407
/// assert_eq!(n.count_ones(), 3);
408408
/// ```
409-
fn count_ones(self) -> uint;
409+
fn count_ones(self) -> Self;
410410

411411
/// Returns the number of zeros in the binary representation of the integer.
412412
///
@@ -418,7 +418,7 @@ pub trait Int: Primitive
418418
/// assert_eq!(n.count_zeros(), 5);
419419
/// ```
420420
#[inline]
421-
fn count_zeros(self) -> uint {
421+
fn count_zeros(self) -> Self {
422422
(!self).count_ones()
423423
}
424424

@@ -432,7 +432,7 @@ pub trait Int: Primitive
432432
///
433433
/// assert_eq!(n.leading_zeros(), 10);
434434
/// ```
435-
fn leading_zeros(self) -> uint;
435+
fn leading_zeros(self) -> Self;
436436

437437
/// Returns the number of trailing zeros in the binary representation
438438
/// of the integer.
@@ -444,7 +444,7 @@ pub trait Int: Primitive
444444
///
445445
/// assert_eq!(n.trailing_zeros(), 3);
446446
/// ```
447-
fn trailing_zeros(self) -> uint;
447+
fn trailing_zeros(self) -> Self;
448448

449449
/// Shifts the bits to the left by a specified amount amount, `n`, wrapping
450450
/// the truncated bits to the end of the resulting integer.
@@ -569,13 +569,13 @@ macro_rules! int_impl {
569569
($T:ty, $BITS:expr, $ctpop:path, $ctlz:path, $cttz:path, $bswap:path) => {
570570
impl Int for $T {
571571
#[inline]
572-
fn count_ones(self) -> uint { unsafe { $ctpop(self) as uint } }
572+
fn count_ones(self) -> $T { unsafe { $ctpop(self) } }
573573

574574
#[inline]
575-
fn leading_zeros(self) -> uint { unsafe { $ctlz(self) as uint } }
575+
fn leading_zeros(self) -> $T { unsafe { $ctlz(self) } }
576576

577577
#[inline]
578-
fn trailing_zeros(self) -> uint { unsafe { $cttz(self) as uint } }
578+
fn trailing_zeros(self) -> $T { unsafe { $cttz(self) } }
579579

580580
#[inline]
581581
fn rotate_left(self, n: uint) -> $T {
@@ -629,13 +629,13 @@ macro_rules! int_cast_impl {
629629
($T:ty, $U:ty) => {
630630
impl Int for $T {
631631
#[inline]
632-
fn count_ones(self) -> uint { (self as $U).count_ones() }
632+
fn count_ones(self) -> $T { (self as $U).count_ones() as $T }
633633

634634
#[inline]
635-
fn leading_zeros(self) -> uint { (self as $U).leading_zeros() }
635+
fn leading_zeros(self) -> $T { (self as $U).leading_zeros() as $T }
636636

637637
#[inline]
638-
fn trailing_zeros(self) -> uint { (self as $U).trailing_zeros() }
638+
fn trailing_zeros(self) -> $T { (self as $U).trailing_zeros() as $T }
639639

640640
#[inline]
641641
fn rotate_left(self, n: uint) -> $T { (self as $U).rotate_left(n) as $T }

branches/snap-stage3/src/libcore/slice.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,12 +806,7 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] {
806806
let mut i: uint = 0;
807807
let ln = self.len();
808808
while i < ln / 2 {
809-
// Unsafe swap to avoid the bounds check in safe swap.
810-
unsafe {
811-
let pa: *mut T = self.unsafe_mut_ref(i);
812-
let pb: *mut T = self.unsafe_mut_ref(ln - i - 1);
813-
ptr::swap(pa, pb);
814-
}
809+
self.swap(i, ln - i - 1);
815810
i += 1;
816811
}
817812
}

branches/snap-stage3/src/libcoretest/num/int_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ mod tests {
9595

9696
#[test]
9797
fn test_count_zeros() {
98-
assert!(A.count_zeros() == BITS - 3);
99-
assert!(B.count_zeros() == BITS - 2);
100-
assert!(C.count_zeros() == BITS - 5);
98+
assert!(A.count_zeros() == BITS as $T - 3);
99+
assert!(B.count_zeros() == BITS as $T - 2);
100+
assert!(C.count_zeros() == BITS as $T - 5);
101101
}
102102

103103
#[test]

branches/snap-stage3/src/libcoretest/num/uint_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ mod tests {
5555

5656
#[test]
5757
fn test_count_zeros() {
58-
assert!(A.count_zeros() == BITS - 3);
59-
assert!(B.count_zeros() == BITS - 2);
60-
assert!(C.count_zeros() == BITS - 5);
58+
assert!(A.count_zeros() == BITS as $T - 3);
59+
assert!(B.count_zeros() == BITS as $T - 2);
60+
assert!(C.count_zeros() == BITS as $T - 5);
6161
}
6262

6363
#[test]

branches/snap-stage3/src/liblibc/lib.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pub use funcs::bsd43::{shutdown};
249249
#[cfg(windows)] pub use types::os::arch::extra::{LARGE_INTEGER, LPVOID, LONG};
250250
#[cfg(windows)] pub use types::os::arch::extra::{time64_t, OVERLAPPED, LPCWSTR};
251251
#[cfg(windows)] pub use types::os::arch::extra::{LPOVERLAPPED, SIZE_T, LPDWORD};
252-
#[cfg(windows)] pub use types::os::arch::extra::{SECURITY_ATTRIBUTES, WIN32_FIND_DATAW};
252+
#[cfg(windows)] pub use types::os::arch::extra::{SECURITY_ATTRIBUTES};
253253
#[cfg(windows)] pub use funcs::c95::string::{wcslen};
254254
#[cfg(windows)] pub use funcs::posix88::stat_::{wstat, wutime, wchmod, wrmdir};
255255
#[cfg(windows)] pub use funcs::bsd43::{closesocket};
@@ -1638,22 +1638,6 @@ pub mod types {
16381638
pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO;
16391639

16401640
pub type GROUP = c_uint;
1641-
1642-
#[repr(C)]
1643-
pub struct WIN32_FIND_DATAW {
1644-
pub dwFileAttributes: DWORD,
1645-
pub ftCreationTime: FILETIME,
1646-
pub ftLastAccessTime: FILETIME,
1647-
pub ftLastWriteTime: FILETIME,
1648-
pub nFileSizeHigh: DWORD,
1649-
pub nFileSizeLow: DWORD,
1650-
pub dwReserved0: DWORD,
1651-
pub dwReserved1: DWORD,
1652-
pub cFileName: [wchar_t, ..260], // #define MAX_PATH 260
1653-
pub cAlternateFileName: [wchar_t, ..14],
1654-
}
1655-
1656-
pub type LPWIN32_FIND_DATAW = *mut WIN32_FIND_DATAW;
16571641
}
16581642
}
16591643
}
@@ -4779,7 +4763,7 @@ pub mod funcs {
47794763
LPMEMORY_BASIC_INFORMATION,
47804764
LPSYSTEM_INFO, HANDLE, LPHANDLE,
47814765
LARGE_INTEGER, PLARGE_INTEGER,
4782-
LPFILETIME, LPWIN32_FIND_DATAW};
4766+
LPFILETIME};
47834767

47844768
extern "system" {
47854769
pub fn GetEnvironmentVariableW(n: LPCWSTR,
@@ -4809,9 +4793,9 @@ pub mod funcs {
48094793
-> DWORD;
48104794
pub fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
48114795
pub fn GetLastError() -> DWORD;
4812-
pub fn FindFirstFileW(fileName: LPCWSTR, findFileData: LPWIN32_FIND_DATAW)
4796+
pub fn FindFirstFileW(fileName: LPCWSTR, findFileData: HANDLE)
48134797
-> HANDLE;
4814-
pub fn FindNextFileW(findFile: HANDLE, findFileData: LPWIN32_FIND_DATAW)
4798+
pub fn FindNextFileW(findFile: HANDLE, findFileData: HANDLE)
48154799
-> BOOL;
48164800
pub fn FindClose(findFile: HANDLE) -> BOOL;
48174801
pub fn DuplicateHandle(hSourceProcessHandle: HANDLE,

0 commit comments

Comments
 (0)