Skip to content

Commit 6ab02bc

Browse files
committed
---
yaml --- r: 149246 b: refs/heads/try2 c: 49e1163 h: refs/heads/master v: v3
1 parent 2848ea9 commit 6ab02bc

33 files changed

+178
-408
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a7aa4c477e7ccc51f19805c42b74cf22dfe22c39
8+
refs/heads/try2: 49e11630fa84eefc27a34c39ad28a9afb515c5a1
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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_ptr(self.ptr, x);
232+
ptr::replace(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.

branches/try2/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

branches/try2/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: ptr::to_mut_unsafe_ptr(n)}
86+
Rawlink{p: n}
8787
}
8888

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

branches/try2/src/librustc/middle/ty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ 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;
3736
use std::rc::Rc;
3837
use std::to_bytes;
3938
use std::to_str::ToStr;
@@ -1137,7 +1136,7 @@ pub fn mk_t(cx: ctxt, st: sty) -> t {
11371136
_ => {}
11381137
};
11391138

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

11421141
{
11431142
let mut interner = cx.interner.borrow_mut();
@@ -1234,7 +1233,7 @@ pub fn mk_t(cx: ctxt, st: sty) -> t {
12341233
flags: flags,
12351234
};
12361235

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

12391238
let key = intern_key {
12401239
sty: sty_ptr,

branches/try2/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();

branches/try2/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 {}

branches/try2/src/libstd/io/test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,15 @@ 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::{to_unsafe_ptr, to_mut_unsafe_ptr, mut_null};
158+
use 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(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),
166+
if sysctl(&mut mib[0], 2, &mut maxfiles as *mut libc::c_int as *mut libc::c_void, &mut size,
169167
mut_null(), 0) != 0 {
170168
let err = last_os_error();
171169
error!("raise_fd_limit: error calling sysctl: {}", err);
@@ -174,7 +172,7 @@ mod darwin_fd_limit {
174172

175173
// Fetch the current resource limits
176174
let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0};
177-
if getrlimit(RLIMIT_NOFILE, to_mut_unsafe_ptr(&mut rlim)) != 0 {
175+
if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 {
178176
let err = last_os_error();
179177
error!("raise_fd_limit: error calling getrlimit: {}", err);
180178
return;
@@ -184,7 +182,7 @@ mod darwin_fd_limit {
184182
rlim.rlim_cur = ::cmp::min(maxfiles as rlim_t, rlim.rlim_max);
185183

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

branches/try2/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());

branches/try2/src/libstd/managed.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
//! Operations on managed box types
1212
13-
use ptr::to_unsafe_ptr;
14-
1513
#[cfg(not(test))] use cmp::*;
1614

1715
/// Returns the refcount of a shared box (as just before calling this)
@@ -24,8 +22,7 @@ pub fn refcount<T>(t: @T) -> uint {
2422
/// Determine if two shared boxes point to the same object
2523
#[inline]
2624
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
27-
let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
28-
a_ptr == b_ptr
25+
&*a as *T == &*b as *T
2926
}
3027

3128
#[cfg(not(test))]

0 commit comments

Comments
 (0)