Skip to content

Commit 7eac82d

Browse files
committed
---
yaml --- r: 65481 b: refs/heads/master c: ed93cc1 h: refs/heads/master i: 65479: 6c9c7e5 v: v3
1 parent 050172a commit 7eac82d

File tree

11 files changed

+118
-147
lines changed

11 files changed

+118
-147
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: 1dc4ea004eee73be098279832c4f6cf558a35269
2+
refs/heads/master: ed93cc1987842d05992376c25a02d21d049ef792
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/doc/tutorial-ffi.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ use std::cast;
153153
use std::libc::{c_void, size_t, malloc, free};
154154
use std::ptr;
155155
use std::unstable::intrinsics;
156-
use std::util;
157156
158157
// a wrapper around the handle returned by the foreign code
159158
pub struct Unique<T> {
@@ -186,9 +185,9 @@ pub impl<T: Owned> Unique<T> {
186185
impl<T: Owned> Drop for Unique<T> {
187186
fn finalize(&self) {
188187
unsafe {
189-
let mut x = intrinsics::init(); // dummy value to swap in
188+
let x = intrinsics::init(); // dummy value to swap in
190189
// moving the object out is needed to call the destructor
191-
util::replace_ptr(self.ptr, x);
190+
ptr::replace_ptr(self.ptr, x);
192191
free(self.ptr as *c_void)
193192
}
194193
}

trunk/src/libextra/rc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use core::libc::{c_void, size_t, malloc, free};
2828
use core::ptr;
2929
use core::sys;
3030
use core::unstable::intrinsics;
31-
use core::util;
3231

3332
struct RcBox<T> {
3433
value: T,
@@ -73,7 +72,7 @@ impl<T> Drop for Rc<T> {
7372
unsafe {
7473
(*self.ptr).count -= 1;
7574
if (*self.ptr).count == 0 {
76-
util::replace_ptr(self.ptr, intrinsics::uninit());
75+
ptr::replace_ptr(self.ptr, intrinsics::uninit());
7776
free(self.ptr as *c_void)
7877
}
7978
}
@@ -223,7 +222,7 @@ impl<T> Drop for RcMut<T> {
223222
unsafe {
224223
(*self.ptr).count -= 1;
225224
if (*self.ptr).count == 0 {
226-
util::replace_ptr(self.ptr, uninit());
225+
ptr::replace_ptr(self.ptr, uninit());
227226
free(self.ptr as *c_void)
228227
}
229228
}

trunk/src/librustc/back/passes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub fn create_standard_passes(level:OptLevel) -> ~[~str] {
134134
passes.push(~"correlated-propagation");
135135
passes.push(~"dse");
136136

137+
passes.push(~"bb-vectorize");
137138
passes.push(~"instcombine");
138139
passes.push(~"early-cse");
139140

trunk/src/libstd/bool.rs

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.
3838
use cmp::{Eq, Ord, TotalOrd, Ordering};
3939
use option::{None, Option, Some};
4040
use from_str::FromStr;
41-
use to_str::ToStr;
4241

4342
/**
4443
* Negation of a boolean value.
@@ -130,6 +129,44 @@ pub fn xor(a: bool, b: bool) -> bool { (a && !b) || (!a && b) }
130129
*/
131130
pub fn implies(a: bool, b: bool) -> bool { !a || b }
132131

132+
/**
133+
* Equality between two boolean values.
134+
*
135+
* Two booleans are equal if they have the same value.
136+
*
137+
* # Examples
138+
*
139+
* ~~~ {.rust}
140+
* rusti> std::bool::eq(false, true)
141+
* false
142+
* ~~~
143+
*
144+
* ~~~ {.rust}
145+
* rusti> std::bool::eq(false, false)
146+
* true
147+
* ~~~
148+
*/
149+
pub fn eq(a: bool, b: bool) -> bool { a == b }
150+
151+
/**
152+
* Non-equality between two boolean values.
153+
*
154+
* Two booleans are not equal if they have different values.
155+
*
156+
* # Examples
157+
*
158+
* ~~~ {.rust}
159+
* rusti> std::bool::ne(false, true)
160+
* true
161+
* ~~~
162+
*
163+
* ~~~ {.rust}
164+
* rusti> std::bool::ne(false, false)
165+
* false
166+
* ~~~
167+
*/
168+
pub fn ne(a: bool, b: bool) -> bool { a != b }
169+
133170
/**
134171
* Is a given boolean value true?
135172
*
@@ -202,21 +239,16 @@ impl FromStr for bool {
202239
* # Examples
203240
*
204241
* ~~~ {.rust}
205-
* rusti> true.to_str()
242+
* rusti> std::bool::to_str(true)
206243
* "true"
207244
* ~~~
208245
*
209246
* ~~~ {.rust}
210-
* rusti> false.to_str()
247+
* rusti> std::bool::to_str(false)
211248
* "false"
212249
* ~~~
213250
*/
214-
impl ToStr for bool {
215-
#[inline(always)]
216-
fn to_str(&self) -> ~str {
217-
if *self { ~"true" } else { ~"false" }
218-
}
219-
}
251+
pub fn to_str(v: bool) -> ~str { if v { ~"true" } else { ~"false" } }
220252

221253
/**
222254
* Iterates over all truth values, passing them to the given block.
@@ -226,7 +258,7 @@ impl ToStr for bool {
226258
* # Examples
227259
* ~~~
228260
* do std::bool::all_values |x: bool| {
229-
* println(x.to_str())
261+
* println(std::bool::to_str(x));
230262
* }
231263
* ~~~
232264
*/
@@ -271,31 +303,6 @@ impl TotalOrd for bool {
271303
fn cmp(&self, other: &bool) -> Ordering { to_bit(*self).cmp(&to_bit(*other)) }
272304
}
273305

274-
/**
275-
* Equality between two boolean values.
276-
*
277-
* Two booleans are equal if they have the same value.
278-
*
279-
* ~~~ {.rust}
280-
* rusti> false.eq(&true)
281-
* false
282-
* ~~~
283-
*
284-
* ~~~ {.rust}
285-
* rusti> false == false
286-
* true
287-
* ~~~
288-
*
289-
* ~~~ {.rust}
290-
* rusti> false != true
291-
* true
292-
* ~~~
293-
*
294-
* ~~~ {.rust}
295-
* rusti> false.ne(&false)
296-
* false
297-
* ~~~
298-
*/
299306
#[cfg(not(test))]
300307
impl Eq for bool {
301308
#[inline(always)]
@@ -312,14 +319,14 @@ mod tests {
312319
#[test]
313320
fn test_bool_from_str() {
314321
do all_values |v| {
315-
assert!(Some(v) == FromStr::from_str(v.to_str()))
322+
assert!(Some(v) == FromStr::from_str(to_str(v)))
316323
}
317324
}
318325

319326
#[test]
320327
fn test_bool_to_str() {
321-
assert_eq!(false.to_str(), ~"false");
322-
assert_eq!(true.to_str(), ~"true");
328+
assert_eq!(to_str(false), ~"false");
329+
assert_eq!(to_str(true), ~"true");
323330
}
324331

325332
#[test]

trunk/src/libstd/ptr.rs

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use cast;
1515
#[cfg(stage0)] use libc::{c_void, size_t};
1616
use option::{Option, Some, None};
1717
use sys;
18+
use unstable::intrinsics;
1819

1920
#[cfg(not(test))] use cmp::{Eq, Ord};
2021
use uint;
@@ -71,11 +72,11 @@ pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
7172

7273
/// Create an unsafe null pointer
7374
#[inline(always)]
74-
pub fn null<T>() -> *T { unsafe { cast::transmute(0u) } }
75+
pub fn null<T>() -> *T { 0 as *T }
7576

7677
/// Create an unsafe mutable null pointer
7778
#[inline(always)]
78-
pub fn mut_null<T>() -> *mut T { unsafe { cast::transmute(0u) } }
79+
pub fn mut_null<T>() -> *mut T { 0 as *mut T }
7980

8081
/// Returns true if the pointer is equal to the null pointer.
8182
#[inline(always)]
@@ -207,47 +208,57 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: u8, count: uint) {
207208
}
208209

209210
/**
210-
Transform a region pointer - &T - to an unsafe pointer - *T.
211-
This is safe, but is implemented with an unsafe block due to
212-
transmute.
213-
*/
211+
* Swap the values at two mutable locations of the same type, without
212+
* deinitialising or copying either one.
213+
*/
214+
#[inline]
215+
pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
216+
// Give ourselves some scratch space to work with
217+
let mut tmp: T = intrinsics::uninit();
218+
let t: *mut T = &mut tmp;
219+
220+
// Perform the swap
221+
copy_memory(t, x, 1);
222+
copy_memory(x, y, 1);
223+
copy_memory(y, t, 1);
224+
225+
// y and t now point to the same thing, but we need to completely forget `tmp`
226+
// because it's no longer relevant.
227+
cast::forget(tmp);
228+
}
229+
230+
/**
231+
* Replace the value at a mutable location with a new one, returning the old
232+
* value, without deinitialising or copying either one.
233+
*/
234+
#[inline(always)]
235+
pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
236+
swap_ptr(dest, &mut src);
237+
src
238+
}
239+
240+
/// Transform a region pointer - &T - to an unsafe pointer - *T.
214241
#[inline(always)]
215242
pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
216-
unsafe { cast::transmute(thing) }
243+
thing as *T
217244
}
218245

219-
/**
220-
Transform a const region pointer - &const T - to a const unsafe pointer -
221-
*const T. This is safe, but is implemented with an unsafe block due to
222-
transmute.
223-
*/
246+
/// Transform a const region pointer - &const T - to a const unsafe pointer - *const T.
224247
#[inline(always)]
225248
pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
226-
unsafe { cast::transmute(thing) }
249+
thing as *const T
227250
}
228251

229-
/**
230-
Transform a mutable region pointer - &mut T - to a mutable unsafe pointer -
231-
*mut T. This is safe, but is implemented with an unsafe block due to
232-
transmute.
233-
*/
252+
/// Transform a mutable region pointer - &mut T - to a mutable unsafe pointer - *mut T.
234253
#[inline(always)]
235254
pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
236-
unsafe { cast::transmute(thing) }
255+
thing as *mut T
237256
}
238257

239-
/**
240-
Cast a region pointer - &T - to a uint.
241-
This is safe, but is implemented with an unsafe block due to
242-
transmute.
243-
244-
(I couldn't think of a cutesy name for this one.)
245-
*/
258+
/// Cast a region pointer - &T - to a uint.
246259
#[inline(always)]
247260
pub fn to_uint<T>(thing: &T) -> uint {
248-
unsafe {
249-
cast::transmute(thing)
250-
}
261+
thing as *T as uint
251262
}
252263

253264
/// Determine if two borrowed pointers point to the same thing.
@@ -373,50 +384,30 @@ impl<T> Ptr<T> for *mut T {
373384
impl<T> Eq for *const T {
374385
#[inline(always)]
375386
fn eq(&self, other: &*const T) -> bool {
376-
unsafe {
377-
let a: uint = cast::transmute(*self);
378-
let b: uint = cast::transmute(*other);
379-
return a == b;
380-
}
387+
(*self as uint) == (*other as uint)
381388
}
382389
#[inline(always)]
383-
fn ne(&self, other: &*const T) -> bool { !(*self).eq(other) }
390+
fn ne(&self, other: &*const T) -> bool { !self.eq(other) }
384391
}
385392

386393
// Comparison for pointers
387394
#[cfg(not(test))]
388395
impl<T> Ord for *const T {
389396
#[inline(always)]
390397
fn lt(&self, other: &*const T) -> bool {
391-
unsafe {
392-
let a: uint = cast::transmute(*self);
393-
let b: uint = cast::transmute(*other);
394-
return a < b;
395-
}
398+
(*self as uint) < (*other as uint)
396399
}
397400
#[inline(always)]
398401
fn le(&self, other: &*const T) -> bool {
399-
unsafe {
400-
let a: uint = cast::transmute(*self);
401-
let b: uint = cast::transmute(*other);
402-
return a <= b;
403-
}
402+
(*self as uint) <= (*other as uint)
404403
}
405404
#[inline(always)]
406405
fn ge(&self, other: &*const T) -> bool {
407-
unsafe {
408-
let a: uint = cast::transmute(*self);
409-
let b: uint = cast::transmute(*other);
410-
return a >= b;
411-
}
406+
(*self as uint) >= (*other as uint)
412407
}
413408
#[inline(always)]
414409
fn gt(&self, other: &*const T) -> bool {
415-
unsafe {
416-
let a: uint = cast::transmute(*self);
417-
let b: uint = cast::transmute(*other);
418-
return a > b;
419-
}
410+
(*self as uint) > (*other as uint)
420411
}
421412
}
422413

@@ -425,11 +416,11 @@ impl<T> Ord for *const T {
425416
impl<'self,T:Eq> Eq for &'self T {
426417
#[inline(always)]
427418
fn eq(&self, other: & &'self T) -> bool {
428-
return *(*self) == *(*other);
419+
*(*self) == *(*other)
429420
}
430421
#[inline(always)]
431422
fn ne(&self, other: & &'self T) -> bool {
432-
return *(*self) != *(*other);
423+
*(*self) != *(*other)
433424
}
434425
}
435426

trunk/src/libstd/to_str.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ pub trait ToStrConsume {
3434
fn to_str_consume(self) -> ~str;
3535
}
3636

37+
impl ToStr for bool {
38+
#[inline(always)]
39+
fn to_str(&self) -> ~str { ::bool::to_str(*self) }
40+
}
3741
impl ToStr for () {
3842
#[inline(always)]
3943
fn to_str(&self) -> ~str { ~"()" }

0 commit comments

Comments
 (0)