Skip to content

Commit c4e6faa

Browse files
committed
---
yaml --- r: 101867 b: refs/heads/master c: 359ac36 h: refs/heads/master i: 101865: 6725b9e 101863: e900571 v: v3
1 parent a3eb6a9 commit c4e6faa

Some content is hidden

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

43 files changed

+355
-424
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: 4af28c98fac5bc36a93527b79c77081eedfb554b
2+
refs/heads/master: 359ac360a453b31494d18bf838f6620032a663e5
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/doc/guide-ffi.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<T: Send> Drop for Unique<T> {
229229
let x = mem::uninit(); // dummy value to swap in
230230
// We need to move the object out of the box, so that
231231
// the destructor is called (at the end of this scope.)
232-
ptr::replace(self.ptr, x);
232+
ptr::replace_ptr(self.ptr, x);
233233
free(self.ptr as *mut c_void)
234234
}
235235
}
@@ -306,7 +306,7 @@ which would call back to `callback()` in Rust.
306306
The former example showed how a global function can be called from C code.
307307
However it is often desired that the callback is targetted to a special
308308
Rust object. This could be the object that represents the wrapper for the
309-
respective C object.
309+
respective C object.
310310

311311
This can be achieved by passing an unsafe pointer to the object down to the
312312
C library. The C library can then include the pointer to the Rust object in
@@ -335,7 +335,7 @@ extern {
335335
fn main() {
336336
// Create the object that will be referenced in the callback
337337
let rust_object = ~RustObject{a: 5, ...};
338-
338+
339339
unsafe {
340340
// Gets a raw pointer to the object
341341
let target_addr:*RustObject = ptr::to_unsafe_ptr(rust_object);
@@ -380,8 +380,8 @@ Rust is to use channels (in `std::comm`) to forward data from the C thread
380380
that invoked the callback into a Rust task.
381381

382382
If an asychronous callback targets a special object in the Rust address space
383-
it is also absolutely necessary that no more callbacks are performed by the
384-
C library after the respective Rust object gets destroyed.
383+
it is also absolutely necessary that no more callbacks are performed by the
384+
C library after the respective Rust object gets destroyed.
385385
This can be achieved by unregistering the callback in the object's
386386
destructor and designing the library in a way that guarantees that no
387387
callback will be performed after unregistration.

trunk/src/doc/tutorial.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,7 @@ guides on individual topics.
32403240
* [Macros][macros]
32413241
* [The foreign function interface][ffi]
32423242
* [Containers and iterators][container]
3243+
* [Error-handling and Conditions][conditions]
32433244
* [Documenting Rust code][rustdoc]
32443245
* [Testing Rust code][testing]
32453246
* [The Rust Runtime][runtime]
@@ -3252,6 +3253,7 @@ There is further documentation on the [wiki], however those tend to be even more
32523253
[macros]: guide-macros.html
32533254
[ffi]: guide-ffi.html
32543255
[container]: guide-container.html
3256+
[conditions]: guide-conditions.html
32553257
[testing]: guide-testing.html
32563258
[runtime]: guide-runtime.html
32573259
[rustdoc]: rustdoc.html

trunk/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<T> Rawlink<T> {
8383

8484
/// Like Option::Some for Rawlink
8585
fn some(n: &mut T) -> Rawlink<T> {
86-
Rawlink{p: n}
86+
Rawlink{p: ptr::to_mut_unsafe_ptr(n)}
8787
}
8888

8989
/// Convert the `Rawlink` into an Option value

trunk/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
273273
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
274274
}
275275
}
276-
_ => {
277-
// For non-immediate arguments the callee gets its own copy of
278-
// the value on the stack, so there are no aliases
279-
if !type_is_immediate(ccx, arg_ty) {
280-
unsafe {
281-
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
282-
}
283-
}
284-
}
276+
_ => {}
285277
}
286278
}
287279

trunk/src/librustc/middle/ty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use std::cell::{Cell, RefCell};
3333
use std::cmp;
3434
use std::hashmap::{HashMap, HashSet};
3535
use std::ops;
36+
use std::ptr::to_unsafe_ptr;
3637
use std::rc::Rc;
3738
use std::to_bytes;
3839
use std::to_str::ToStr;
@@ -1136,7 +1137,7 @@ pub fn mk_t(cx: ctxt, st: sty) -> t {
11361137
_ => {}
11371138
};
11381139

1139-
let key = intern_key { sty: &st };
1140+
let key = intern_key { sty: to_unsafe_ptr(&st) };
11401141

11411142
{
11421143
let mut interner = cx.interner.borrow_mut();
@@ -1233,7 +1234,7 @@ pub fn mk_t(cx: ctxt, st: sty) -> t {
12331234
flags: flags,
12341235
};
12351236

1236-
let sty_ptr = &t.sty as *sty;
1237+
let sty_ptr = to_unsafe_ptr(&t.sty);
12371238

12381239
let key = intern_key {
12391240
sty: sty_ptr,

trunk/src/libstd/c_str.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ use str;
7979
use vec::{ImmutableVector, MutableVector};
8080
use vec;
8181
use rt::global_heap::malloc_raw;
82-
use unstable::raw::Slice;
8382

8483
/// The representation of a C String.
8584
///
@@ -170,7 +169,6 @@ impl CString {
170169
}
171170

172171
/// Converts the CString into a `&[u8]` without copying.
173-
/// Includes the terminating NUL byte.
174172
///
175173
/// # Failure
176174
///
@@ -179,21 +177,7 @@ impl CString {
179177
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
180178
if self.buf.is_null() { fail!("CString is null!"); }
181179
unsafe {
182-
cast::transmute(Slice { data: self.buf, len: self.len() + 1 })
183-
}
184-
}
185-
186-
/// Converts the CString into a `&[u8]` without copying.
187-
/// Does not include the terminating NUL byte.
188-
///
189-
/// # Failure
190-
///
191-
/// Fails if the CString is null.
192-
#[inline]
193-
pub fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8] {
194-
if self.buf.is_null() { fail!("CString is null!"); }
195-
unsafe {
196-
cast::transmute(Slice { data: self.buf, len: self.len() })
180+
cast::transmute((self.buf, self.len() + 1))
197181
}
198182
}
199183

@@ -205,7 +189,8 @@ impl CString {
205189
/// Fails if the CString is null.
206190
#[inline]
207191
pub fn as_str<'a>(&'a self) -> Option<&'a str> {
208-
let buf = self.as_bytes_no_nul();
192+
let buf = self.as_bytes();
193+
let buf = buf.slice_to(buf.len()-1); // chop off the trailing NUL
209194
str::from_utf8(buf)
210195
}
211196

@@ -432,7 +417,7 @@ mod tests {
432417
let expected = ["zero", "one"];
433418
let mut it = expected.iter();
434419
let result = from_c_multistring(ptr as *libc::c_char, None, |c| {
435-
let cbytes = c.as_bytes_no_nul();
420+
let cbytes = c.as_bytes().slice_to(c.len());
436421
assert_eq!(cbytes, it.next().unwrap().as_bytes());
437422
});
438423
assert_eq!(result, 2);
@@ -567,31 +552,13 @@ mod tests {
567552
assert_eq!(c_str.as_bytes(), bytes!("foo", 0xff, 0));
568553
}
569554

570-
#[test]
571-
fn test_as_bytes_no_nul() {
572-
let c_str = "hello".to_c_str();
573-
assert_eq!(c_str.as_bytes_no_nul(), bytes!("hello"));
574-
let c_str = "".to_c_str();
575-
let exp: &[u8] = [];
576-
assert_eq!(c_str.as_bytes_no_nul(), exp);
577-
let c_str = bytes!("foo", 0xff).to_c_str();
578-
assert_eq!(c_str.as_bytes_no_nul(), bytes!("foo", 0xff));
579-
}
580-
581555
#[test]
582556
#[should_fail]
583557
fn test_as_bytes_fail() {
584558
let c_str = unsafe { CString::new(ptr::null(), false) };
585559
c_str.as_bytes();
586560
}
587561

588-
#[test]
589-
#[should_fail]
590-
fn test_as_bytes_no_nul_fail() {
591-
let c_str = unsafe { CString::new(ptr::null(), false) };
592-
c_str.as_bytes_no_nul();
593-
}
594-
595562
#[test]
596563
fn test_as_str() {
597564
let c_str = "hello".to_c_str();

trunk/src/libstd/fmt/mod.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,17 +1200,7 @@ impl<T> Pointer for *T {
12001200
}
12011201
impl<T> Pointer for *mut T {
12021202
fn fmt(&self, f: &mut Formatter) -> Result {
1203-
secret_pointer::<*T>(&(*self as *T), f)
1204-
}
1205-
}
1206-
impl<'a, T> Pointer for &'a T {
1207-
fn fmt(&self, f: &mut Formatter) -> Result {
1208-
secret_pointer::<*T>(&(&**self as *T), f)
1209-
}
1210-
}
1211-
impl<'a, T> Pointer for &'a mut T {
1212-
fn fmt(&self, f: &mut Formatter) -> Result {
1213-
secret_pointer::<*T>(&(&**self as *T), f)
1203+
secret_pointer(&(*self as *T), f)
12141204
}
12151205
}
12161206

trunk/src/libstd/hashmap.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
5656
use clone::Clone;
5757
use cmp::{Eq, Equiv, max};
5858
use default::Default;
59-
#[cfg(not(stage0))] use fmt;
59+
use fmt;
6060
use hash::Hash;
6161
use iter;
6262
use iter::{Iterator, FromIterator, Extendable};
@@ -66,7 +66,7 @@ use num;
6666
use option::{None, Option, Some};
6767
use rand::Rng;
6868
use rand;
69-
#[cfg(not(stage0))] use result::{Ok, Err};
69+
use result::{Ok, Err};
7070
use vec::{ImmutableVector, MutableVector, OwnedVector, Items, MutItems};
7171
use vec_ng;
7272
use vec_ng::Vec;
@@ -597,7 +597,6 @@ impl<K:Hash + Eq + Clone,V:Clone> Clone for HashMap<K,V> {
597597
}
598598
}
599599

600-
#[cfg(not(stage0))]
601600
impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for HashMap<A, B> {
602601
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
603602
if_ok!(write!(f.buf, r"\{"))
@@ -876,7 +875,6 @@ impl<T:Hash + Eq + Clone> Clone for HashSet<T> {
876875
}
877876
}
878877

879-
#[cfg(not(stage0))]
880878
impl<A: fmt::Show + Hash + Eq> fmt::Show for HashSet<A> {
881879
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
882880
if_ok!(write!(f.buf, r"\{"))

trunk/src/libstd/io/mod.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,6 @@ pub trait Reader {
779779
self.read_byte().map(|i| i as i8)
780780
}
781781

782-
/// Creates a wrapper around a mutable reference to the reader.
783-
///
784-
/// This is useful to allow applying adaptors while still
785-
/// retaining ownership of the original value.
786-
fn by_ref<'a>(&'a mut self) -> RefReader<'a, Self> {
787-
RefReader { inner: self }
788-
}
789782
}
790783

791784
impl Reader for ~Reader {
@@ -796,14 +789,6 @@ impl<'a> Reader for &'a mut Reader {
796789
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.read(buf) }
797790
}
798791

799-
pub struct RefReader<'a, R> {
800-
priv inner: &'a mut R
801-
}
802-
803-
impl<'a, R: Reader> Reader for RefReader<'a, R> {
804-
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.inner.read(buf) }
805-
}
806-
807792
fn extend_sign(val: u64, nbytes: uint) -> i64 {
808793
let shift = (8 - nbytes) * 8;
809794
(val << shift) as i64 >> shift
@@ -984,14 +969,6 @@ pub trait Writer {
984969
fn write_i8(&mut self, n: i8) -> IoResult<()> {
985970
self.write([n as u8])
986971
}
987-
988-
/// Creates a wrapper around a mutable reference to the writer.
989-
///
990-
/// This is useful to allow applying wrappers while still
991-
/// retaining ownership of the original value.
992-
fn by_ref<'a>(&'a mut self) -> RefWriter<'a, Self> {
993-
RefWriter { inner: self }
994-
}
995972
}
996973

997974
impl Writer for ~Writer {
@@ -1004,16 +981,6 @@ impl<'a> Writer for &'a mut Writer {
1004981
fn flush(&mut self) -> IoResult<()> { self.flush() }
1005982
}
1006983

1007-
pub struct RefWriter<'a, W> {
1008-
inner: &'a mut W
1009-
}
1010-
1011-
impl<'a, W: Writer> Writer for RefWriter<'a, W> {
1012-
fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.inner.write(buf) }
1013-
fn flush(&mut self) -> IoResult<()> { self.inner.flush() }
1014-
}
1015-
1016-
1017984
pub trait Stream: Reader + Writer { }
1018985

1019986
impl<T: Reader + Writer> Stream for T {}

trunk/src/libstd/io/test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,17 @@ mod darwin_fd_limit {
155155
pub unsafe fn raise_fd_limit() {
156156
// The strategy here is to fetch the current resource limits, read the kern.maxfilesperproc
157157
// sysctl value, and bump the soft resource limit for maxfiles up to the sysctl value.
158-
use ptr::mut_null;
158+
use ptr::{to_unsafe_ptr, to_mut_unsafe_ptr, mut_null};
159159
use mem::size_of_val;
160160
use os::last_os_error;
161161

162162
// Fetch the kern.maxfilesperproc value
163163
let mut mib: [libc::c_int, ..2] = [CTL_KERN, KERN_MAXFILESPERPROC];
164164
let mut maxfiles: libc::c_int = 0;
165165
let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
166-
if sysctl(&mut mib[0], 2, &mut maxfiles as *mut libc::c_int as *mut libc::c_void, &mut size,
166+
if sysctl(to_mut_unsafe_ptr(&mut mib[0]), 2,
167+
to_mut_unsafe_ptr(&mut maxfiles) as *mut libc::c_void,
168+
to_mut_unsafe_ptr(&mut size),
167169
mut_null(), 0) != 0 {
168170
let err = last_os_error();
169171
error!("raise_fd_limit: error calling sysctl: {}", err);
@@ -172,7 +174,7 @@ mod darwin_fd_limit {
172174

173175
// Fetch the current resource limits
174176
let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0};
175-
if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 {
177+
if getrlimit(RLIMIT_NOFILE, to_mut_unsafe_ptr(&mut rlim)) != 0 {
176178
let err = last_os_error();
177179
error!("raise_fd_limit: error calling getrlimit: {}", err);
178180
return;
@@ -182,7 +184,7 @@ mod darwin_fd_limit {
182184
rlim.rlim_cur = ::cmp::min(maxfiles as rlim_t, rlim.rlim_max);
183185

184186
// Set our newly-increased resource limit
185-
if setrlimit(RLIMIT_NOFILE, &rlim) != 0 {
187+
if setrlimit(RLIMIT_NOFILE, to_unsafe_ptr(&rlim)) != 0 {
186188
let err = last_os_error();
187189
error!("raise_fd_limit: error calling setrlimit: {}", err);
188190
return;

trunk/src/libstd/io/util.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ use io;
1414
use vec::bytes::MutableByteVector;
1515

1616
/// Wraps a `Reader`, limiting the number of bytes that can be read from it.
17-
pub struct LimitReader<R> {
17+
pub struct LimitReader<'a, R> {
1818
priv limit: uint,
19-
priv inner: R
19+
priv inner: &'a mut R
2020
}
2121

22-
impl<R: Reader> LimitReader<R> {
22+
impl<'a, R: Reader> LimitReader<'a, R> {
2323
/// Creates a new `LimitReader`
24-
pub fn new(r: R, limit: uint) -> LimitReader<R> {
24+
pub fn new<'a>(r: &'a mut R, limit: uint) -> LimitReader<'a, R> {
2525
LimitReader { limit: limit, inner: r }
2626
}
27-
pub fn unwrap(self) -> R { self.inner }
2827
}
2928

30-
impl<R: Reader> Reader for LimitReader<R> {
29+
impl<'a, R: Reader> Reader for LimitReader<'a, R> {
3130
fn read(&mut self, buf: &mut [u8]) -> io::IoResult<uint> {
3231
if self.limit == 0 {
3332
return Err(io::standard_error(io::EndOfFile));
@@ -193,7 +192,7 @@ mod test {
193192
fn test_bounded_reader_unlimited() {
194193
let mut r = MemReader::new(~[0, 1, 2]);
195194
{
196-
let mut r = LimitReader::new(r.by_ref(), 4);
195+
let mut r = LimitReader::new(&mut r, 4);
197196
assert_eq!(~[0, 1, 2], r.read_to_end().unwrap());
198197
}
199198
}
@@ -202,7 +201,7 @@ mod test {
202201
fn test_bound_reader_limited() {
203202
let mut r = MemReader::new(~[0, 1, 2]);
204203
{
205-
let mut r = LimitReader::new(r.by_ref(), 2);
204+
let mut r = LimitReader::new(&mut r, 2);
206205
assert_eq!(~[0, 1], r.read_to_end().unwrap());
207206
}
208207
assert_eq!(~[2], r.read_to_end().unwrap());

0 commit comments

Comments
 (0)