Skip to content

Commit 3f6e653

Browse files
committed
make vec fns/methods take imm slices.
this also repairs the unsoundness in typing of unpack_slice, which was silently converting a const ptr to an imm one.
1 parent e94683d commit 3f6e653

File tree

12 files changed

+235
-194
lines changed

12 files changed

+235
-194
lines changed

doc/tutorial.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,14 +908,13 @@ for the parameter list, as in `{|| ...}`.
908908
Partial application is done using the `bind` keyword in Rust.
909909

910910
~~~~
911-
let daynum = bind vec::position_elem(["mo", "tu", "we", "th",
912-
"fr", "sa", "su"], _);
911+
let findx = bind str::find_char(_, 'x');
913912
~~~~
914913

915914
Binding a function produces a boxed closure (`fn@` type) in which some
916915
of the arguments to the bound function have already been provided.
917-
`daynum` will be a function taking a single string argument, and
918-
returning the day of the week that string corresponds to (if any).
916+
`findx` will be a function taking a single string argument, and
917+
returning the position where the letter `x` occurs.
919918

920919
## Iteration
921920

src/libcore/core.rc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export swappable;
4545
export dvec, dvec_iter;
4646

4747
// NDM seems to be necessary for resolve to work
48-
export vec_iter, option_iter;
48+
export option_iter;
4949

5050
// FIXME: This creates some APIs that I do not want to commit to. It is
5151
// currently exported for the uv code in std, but when that code moves into
@@ -146,11 +146,6 @@ mod f64;
146146
mod str;
147147
mod ptr;
148148
mod vec;
149-
#[path="iter-trait"]
150-
mod vec_iter {
151-
#[path = "vec.rs"]
152-
mod inst;
153-
}
154149
mod bool;
155150
mod tuple;
156151

src/libcore/core.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import option = option::option;
77
import path = path::path;
88
import str::extensions;
99
import vec::extensions;
10-
import vec_iter::extensions;
1110
import option::extensions;
1211
import option_iter::extensions;
1312
import ptr::extensions;

src/libcore/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl <T: writer, C> of writer for {base: T, cleanup: C} {
331331

332332
impl of writer for *libc::FILE {
333333
fn write(v: [const u8]/&) unsafe {
334-
vec::unpack_slice(v) {|vbuf, len|
334+
vec::unpack_const_slice(v) {|vbuf, len|
335335
let nout = libc::fwrite(vbuf as *c_void, len, 1u, self);
336336
if nout < 1 as size_t {
337337
#error("error writing buffer");
@@ -359,9 +359,9 @@ fn FILE_writer(f: *libc::FILE, cleanup: bool) -> writer {
359359
impl of writer for fd_t {
360360
fn write(v: [const u8]/&) unsafe {
361361
let mut count = 0u;
362-
vec::unpack_slice(v) {|vbuf, len|
362+
vec::unpack_const_slice(v) {|vbuf, len|
363363
while count < len {
364-
let vb = ptr::offset(vbuf, count) as *c_void;
364+
let vb = ptr::const_offset(vbuf, count) as *c_void;
365365
let nout = libc::write(self, vb, len);
366366
if nout < 0 as ssize_t {
367367
#error("error writing buffer");

src/libcore/iter-trait/vec.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/libcore/ptr.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export addr_of;
44
export mut_addr_of;
55
export offset;
6+
export const_offset;
67
export mut_offset;
78
export null;
89
export is_null;
@@ -45,6 +46,12 @@ fn offset<T>(ptr: *T, count: uint) -> *T unsafe {
4546
(ptr as uint + count * sys::size_of::<T>()) as *T
4647
}
4748

49+
#[doc = "Calculate the offset from a const pointer"]
50+
#[inline(always)]
51+
fn const_offset<T>(ptr: *const T, count: uint) -> *const T unsafe {
52+
(ptr as uint + count * sys::size_of::<T>()) as *T
53+
}
54+
4855
#[doc = "Calculate the offset from a mut pointer"]
4956
#[inline(always)]
5057
fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {

0 commit comments

Comments
 (0)