Skip to content

Commit 30e098a

Browse files
Aatchbrson
authored andcommitted
---
yaml --- r: 65183 b: refs/heads/master c: 6d8d73c h: refs/heads/master i: 65181: 89bf70a 65179: a78a573 65175: a676730 65167: 447b6b1 65151: c8a2c60 v: v3
1 parent 777ead3 commit 30e098a

File tree

161 files changed

+3820
-3484
lines changed

Some content is hidden

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

161 files changed

+3820
-3484
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: 799f281b43bbd52c01c5e404cc09674ec52eb696
2+
refs/heads/master: 6d8d73cfc4cba2fdb2ee67448df39d89be08ce69
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libcore/cast.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@
1212
1313
use sys;
1414
use unstable;
15-
use unstable::intrinsics;
15+
16+
pub mod rusti {
17+
#[abi = "rust-intrinsic"]
18+
#[link_name = "rusti"]
19+
pub extern "rust-intrinsic" {
20+
fn forget<T>(x: T);
21+
22+
fn transmute<T,U>(e: T) -> U;
23+
}
24+
}
1625

1726
/// Casts the value at `src` to U. The two types must have the same length.
1827
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
19-
let mut dest: U = intrinsics::init();
28+
let mut dest: U = unstable::intrinsics::init();
2029
{
21-
let dest_ptr: *mut u8 = transmute(&mut dest);
22-
let src_ptr: *u8 = transmute(src);
23-
intrinsics::memmove64(dest_ptr,
24-
src_ptr,
25-
sys::size_of::<U>() as u64);
30+
let dest_ptr: *mut u8 = rusti::transmute(&mut dest);
31+
let src_ptr: *u8 = rusti::transmute(src);
32+
unstable::intrinsics::memmove64(dest_ptr,
33+
src_ptr,
34+
sys::size_of::<U>() as u64);
2635
}
2736
dest
2837
}
@@ -36,7 +45,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
3645
* reinterpret_cast on pointer types.
3746
*/
3847
#[inline(always)]
39-
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
48+
pub unsafe fn forget<T>(thing: T) { rusti::forget(thing); }
4049

4150
/**
4251
* Force-increment the reference count on a shared box. If used
@@ -56,7 +65,7 @@ pub unsafe fn bump_box_refcount<T>(t: @T) { forget(t); }
5665
*/
5766
#[inline(always)]
5867
pub unsafe fn transmute<L, G>(thing: L) -> G {
59-
intrinsics::transmute(thing)
68+
rusti::transmute(thing)
6069
}
6170

6271
/// Coerce an immutable reference to be mutable.

trunk/src/libcore/clone.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ by convention implementing the `Clone` trait and calling the
2525
use core::kinds::Const;
2626

2727
pub trait Clone {
28-
/// Returns a copy of the value. The contents of owned pointers
29-
/// are copied to maintain uniqueness, while the contents of
30-
/// managed pointers are not copied.
28+
/// Return a deep copy of the owned object tree. Types with shared ownership like managed boxes
29+
/// are cloned with a shallow copy.
3130
fn clone(&self) -> Self;
3231
}
3332

@@ -86,9 +85,8 @@ clone_impl!(bool)
8685
clone_impl!(char)
8786

8887
pub trait DeepClone {
89-
/// Return a deep copy of the value. Unlike `Clone`, the contents of shared pointer types
90-
/// *are* copied. Note that this is currently unimplemented for managed boxes, as
91-
/// it would need to handle cycles, but it is implemented for other smart-pointer types.
88+
/// Return a deep copy of the object tree. Types with shared ownership are also copied via a
89+
/// deep copy, unlike `Clone`.
9290
fn deep_clone(&self) -> Self;
9391
}
9492

trunk/src/libcore/hashmap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> {
303303

304304
/// Visit all key-value pairs
305305
fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool {
306-
for self.buckets.each |bucket| {
307-
for bucket.each |pair| {
308-
if !blk(&pair.key, &pair.value) {
306+
for uint::range(0, self.buckets.len()) |i| {
307+
for self.buckets[i].each |bucket| {
308+
if !blk(&bucket.key, &bucket.value) {
309309
return false;
310310
}
311311
}

trunk/src/libcore/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub fn self_exe_path() -> Option<Path> {
509509
* Otherwise, homedir returns option::none.
510510
*/
511511
pub fn homedir() -> Option<Path> {
512-
return match getenv("HOME") {
512+
return match getenv(~"HOME") {
513513
Some(ref p) => if !str::is_empty(*p) {
514514
Some(Path(*p))
515515
} else {

trunk/src/libcore/ptr.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use cast;
1414
use libc;
1515
use libc::{c_void, size_t};
16-
use option::{Option, Some, None};
1716
use sys;
1817

1918
#[cfg(not(test))] use cmp::{Eq, Ord};
@@ -210,7 +209,6 @@ pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
210209
pub trait Ptr<T> {
211210
fn is_null(&const self) -> bool;
212211
fn is_not_null(&const self) -> bool;
213-
unsafe fn to_option(&const self) -> Option<&T>;
214212
fn offset(&self, count: uint) -> Self;
215213
}
216214

@@ -224,23 +222,6 @@ impl<T> Ptr<T> for *T {
224222
#[inline(always)]
225223
fn is_not_null(&const self) -> bool { is_not_null(*self) }
226224

227-
///
228-
/// Returns `None` if the pointer is null, or else returns the value wrapped
229-
/// in `Some`.
230-
///
231-
/// # Safety Notes
232-
///
233-
/// While this method is useful for null-safety, it is important to note
234-
/// that this is still an unsafe operation because the returned value could
235-
/// be pointing to invalid memory.
236-
///
237-
#[inline(always)]
238-
unsafe fn to_option(&const self) -> Option<&T> {
239-
if self.is_null() { None } else {
240-
Some(cast::transmute(*self))
241-
}
242-
}
243-
244225
/// Calculates the offset from a pointer.
245226
#[inline(always)]
246227
fn offset(&self, count: uint) -> *T { offset(*self, count) }
@@ -256,23 +237,6 @@ impl<T> Ptr<T> for *mut T {
256237
#[inline(always)]
257238
fn is_not_null(&const self) -> bool { is_not_null(*self) }
258239

259-
///
260-
/// Returns `None` if the pointer is null, or else returns the value wrapped
261-
/// in `Some`.
262-
///
263-
/// # Safety Notes
264-
///
265-
/// While this method is useful for null-safety, it is important to note
266-
/// that this is still an unsafe operation because the returned value could
267-
/// be pointing to invalid memory.
268-
///
269-
#[inline(always)]
270-
unsafe fn to_option(&const self) -> Option<&T> {
271-
if self.is_null() { None } else {
272-
Some(cast::transmute(*self))
273-
}
274-
}
275-
276240
/// Calculates the offset from a mutable pointer.
277241
#[inline(always)]
278242
fn offset(&self, count: uint) -> *mut T { mut_offset(*self, count) }
@@ -459,21 +423,6 @@ pub mod ptr_tests {
459423
assert!(mq.is_not_null());
460424
}
461425

462-
#[test]
463-
fn test_to_option() {
464-
let p: *int = null();
465-
// FIXME (#6641): Usage of unsafe methods in safe code doesn't cause an error.
466-
assert_eq!(p.to_option(), None);
467-
468-
let q: *int = &2;
469-
assert_eq!(q.to_option().unwrap(), &2); // FIXME (#6641)
470-
471-
let p: *mut int = mut_null();
472-
assert_eq!(p.to_option(), None); // FIXME (#6641)
473-
474-
let q: *mut int = &mut 2;
475-
assert_eq!(q.to_option().unwrap(), &2); // FIXME (#6641)
476-
}
477426

478427
#[test]
479428
fn test_ptr_array_each_with_len() {

trunk/src/libcore/rt/context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ fn new_regs() -> ~Registers { ~([0, .. 32]) }
183183

184184
#[cfg(target_arch = "mips")]
185185
fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp: *mut uint) {
186-
let sp = align_down(sp);
187-
// sp of mips o32 is 8-byte aligned
188-
let sp = mut_offset(sp, -2);
186+
let sp = mut_offset(sp, -1);
189187

190188
// The final return address. 0 indicates the bottom of the stack
191189
unsafe { *sp = 0; }

trunk/src/libcore/rt/uv/async.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use libc::{c_int, c_void};
12+
use option::Some;
13+
use rt::uv::uvll;
14+
use rt::uv::uvll::UV_ASYNC;
15+
use rt::uv::{Watcher, Loop, NativeHandle, AsyncCallback, NullCallback};
16+
use rt::uv::WatcherInterop;
17+
use rt::uv::status_to_maybe_uv_error;
18+
19+
pub struct AsyncWatcher(*uvll::uv_async_t);
20+
impl Watcher for AsyncWatcher { }
21+
22+
impl AsyncWatcher {
23+
fn new(loop_: &mut Loop, cb: AsyncCallback) -> AsyncWatcher {
24+
unsafe {
25+
let handle = uvll::malloc_handle(UV_ASYNC);
26+
assert!(handle.is_not_null());
27+
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
28+
watcher.install_watcher_data();
29+
let data = watcher.get_watcher_data();
30+
data.async_cb = Some(cb);
31+
assert_eq!(0, uvll::async_init(loop_.native_handle(), handle, async_cb));
32+
return watcher;
33+
}
34+
35+
extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
36+
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
37+
let status = status_to_maybe_uv_error(watcher.native_handle(), status);
38+
let data = watcher.get_watcher_data();
39+
let cb = data.async_cb.get_ref();
40+
(*cb)(watcher, status);
41+
}
42+
}
43+
44+
fn send(&mut self) {
45+
unsafe {
46+
let handle = self.native_handle();
47+
uvll::async_send(handle);
48+
}
49+
}
50+
51+
fn close(self, cb: NullCallback) {
52+
let mut this = self;
53+
let data = this.get_watcher_data();
54+
assert!(data.close_cb.is_none());
55+
data.close_cb = Some(cb);
56+
57+
unsafe {
58+
uvll::close(self.native_handle(), close_cb);
59+
}
60+
61+
extern fn close_cb(handle: *uvll::uv_stream_t) {
62+
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
63+
{
64+
let data = watcher.get_watcher_data();
65+
data.close_cb.swap_unwrap()();
66+
}
67+
watcher.drop_watcher_data();
68+
unsafe { uvll::free_handle(handle as *c_void); }
69+
}
70+
}
71+
}
72+
73+
impl NativeHandle<*uvll::uv_async_t> for AsyncWatcher {
74+
fn from_native_handle(handle: *uvll::uv_async_t) -> AsyncWatcher {
75+
AsyncWatcher(handle)
76+
}
77+
fn native_handle(&self) -> *uvll::uv_async_t {
78+
match self { &AsyncWatcher(ptr) => ptr }
79+
}
80+
}
81+
82+
#[cfg(test)]
83+
mod test {
84+
85+
use super::*;
86+
use rt::uv::Loop;
87+
use unstable::run_in_bare_thread;
88+
use rt::thread::Thread;
89+
use cell::Cell;
90+
91+
#[test]
92+
fn smoke_test() {
93+
do run_in_bare_thread {
94+
let mut loop_ = Loop::new();
95+
let watcher = AsyncWatcher::new(&mut loop_, |w, _| w.close(||()) );
96+
let watcher_cell = Cell(watcher);
97+
let _thread = do Thread::start {
98+
let mut watcher = watcher_cell.take();
99+
watcher.send();
100+
};
101+
loop_.run();
102+
loop_.close();
103+
}
104+
}
105+
}

trunk/src/libcore/rt/uv/idle.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,65 @@ impl NativeHandle<*uvll::uv_idle_t> for IdleWatcher {
8989
match self { &IdleWatcher(ptr) => ptr }
9090
}
9191
}
92+
93+
#[cfg(test)]
94+
mod test {
95+
96+
use rt::uv::Loop;
97+
use super::*;
98+
use unstable::run_in_bare_thread;
99+
100+
#[test]
101+
#[ignore(reason = "valgrind - loop destroyed before watcher?")]
102+
fn idle_new_then_close() {
103+
do run_in_bare_thread {
104+
let mut loop_ = Loop::new();
105+
let idle_watcher = { IdleWatcher::new(&mut loop_) };
106+
idle_watcher.close(||());
107+
}
108+
}
109+
110+
#[test]
111+
fn idle_smoke_test() {
112+
do run_in_bare_thread {
113+
let mut loop_ = Loop::new();
114+
let mut idle_watcher = { IdleWatcher::new(&mut loop_) };
115+
let mut count = 10;
116+
let count_ptr: *mut int = &mut count;
117+
do idle_watcher.start |idle_watcher, status| {
118+
let mut idle_watcher = idle_watcher;
119+
assert!(status.is_none());
120+
if unsafe { *count_ptr == 10 } {
121+
idle_watcher.stop();
122+
idle_watcher.close(||());
123+
} else {
124+
unsafe { *count_ptr = *count_ptr + 1; }
125+
}
126+
}
127+
loop_.run();
128+
loop_.close();
129+
assert_eq!(count, 10);
130+
}
131+
}
132+
133+
#[test]
134+
fn idle_start_stop_start() {
135+
do run_in_bare_thread {
136+
let mut loop_ = Loop::new();
137+
let mut idle_watcher = { IdleWatcher::new(&mut loop_) };
138+
do idle_watcher.start |idle_watcher, status| {
139+
let mut idle_watcher = idle_watcher;
140+
assert!(status.is_none());
141+
idle_watcher.stop();
142+
do idle_watcher.start |idle_watcher, status| {
143+
assert!(status.is_none());
144+
let mut idle_watcher = idle_watcher;
145+
idle_watcher.stop();
146+
idle_watcher.close(||());
147+
}
148+
}
149+
loop_.run();
150+
loop_.close();
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)