Skip to content

Commit 1795cda

Browse files
committed
De-mode more pieces of core.
1 parent 1d3b547 commit 1795cda

File tree

7 files changed

+61
-33
lines changed

7 files changed

+61
-33
lines changed

src/libcore/hash.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
/*!
26
* Implementation of SipHash 2-4
37
*
@@ -362,9 +366,9 @@ fn test_siphash() {
362366
let stream_inc = &State(k0,k1);
363367
let stream_full = &State(k0,k1);
364368

365-
fn to_hex_str(r:[u8]/8) -> ~str {
369+
fn to_hex_str(r: &[u8]/8) -> ~str {
366370
let mut s = ~"";
367-
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
371+
for vec::each(*r) |b| { s += uint::to_str(b as uint, 16u); }
368372
return s;
369373
}
370374

@@ -379,7 +383,7 @@ fn test_siphash() {
379383
stream_full.input(buf);
380384
let f = stream_full.result_str();
381385
let i = stream_inc.result_str();
382-
let v = to_hex_str(vecs[t]);
386+
let v = to_hex_str(&vecs[t]);
383387
debug!{"%d: (%s) => inc=%s full=%s", t, v, i, f};
384388

385389
assert f == i && f == v;

src/libcore/run.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
//! Process spawning
26
import option::{some, none};
37
import libc::{pid_t, c_void, c_int};
@@ -62,9 +66,9 @@ trait program {
6266
*
6367
* The process id of the spawned process
6468
*/
65-
fn spawn_process(prog: ~str, args: ~[~str],
66-
env: option<~[(~str,~str)]>,
67-
dir: option<~str>,
69+
fn spawn_process(prog: &str, args: &[~str],
70+
env: &option<~[(~str,~str)]>,
71+
dir: &option<~str>,
6872
in_fd: c_int, out_fd: c_int, err_fd: c_int)
6973
-> pid_t {
7074
do with_argv(prog, args) |argv| {
@@ -77,7 +81,7 @@ fn spawn_process(prog: ~str, args: ~[~str],
7781
}
7882
}
7983

80-
fn with_argv<T>(prog: ~str, args: ~[~str],
84+
fn with_argv<T>(prog: &str, args: &[~str],
8185
cb: fn(**libc::c_char) -> T) -> T {
8286
let mut argptrs = str::as_c_str(prog, |b| ~[b]);
8387
let mut tmps = ~[];
@@ -91,11 +95,11 @@ fn with_argv<T>(prog: ~str, args: ~[~str],
9195
}
9296

9397
#[cfg(unix)]
94-
fn with_envp<T>(env: option<~[(~str,~str)]>,
98+
fn with_envp<T>(env: &option<~[(~str,~str)]>,
9599
cb: fn(*c_void) -> T) -> T {
96100
// On posixy systems we can pass a char** for envp, which is
97101
// a null-terminated array of "k=v\n" strings.
98-
match env {
102+
match *env {
99103
some(es) if !vec::is_empty(es) => {
100104
let mut tmps = ~[];
101105
let mut ptrs = ~[];
@@ -140,9 +144,9 @@ fn with_envp<T>(env: option<~[(~str,~str)]>,
140144
}
141145
}
142146

143-
fn with_dirp<T>(d: option<~str>,
147+
fn with_dirp<T>(d: &option<~str>,
144148
cb: fn(*libc::c_char) -> T) -> T {
145-
match d {
149+
match *d {
146150
some(dir) => str::as_c_str(dir, cb),
147151
none => cb(ptr::null())
148152
}
@@ -160,8 +164,8 @@ fn with_dirp<T>(d: option<~str>,
160164
*
161165
* The process id
162166
*/
163-
fn run_program(prog: ~str, args: ~[~str]) -> int {
164-
let pid = spawn_process(prog, args, none, none,
167+
fn run_program(prog: &str, args: &[~str]) -> int {
168+
let pid = spawn_process(prog, args, &none, &none,
165169
0i32, 0i32, 0i32);
166170
if pid == -1 as pid_t { fail; }
167171
return waitpid(pid);
@@ -183,12 +187,12 @@ fn run_program(prog: ~str, args: ~[~str]) -> int {
183187
*
184188
* A class with a <program> field
185189
*/
186-
fn start_program(prog: ~str, args: ~[~str]) -> program {
190+
fn start_program(prog: &str, args: &[~str]) -> program {
187191
let pipe_input = os::pipe();
188192
let pipe_output = os::pipe();
189193
let pipe_err = os::pipe();
190194
let pid =
191-
spawn_process(prog, args, none, none,
195+
spawn_process(prog, args, &none, &none,
192196
pipe_input.in, pipe_output.out,
193197
pipe_err.out);
194198

@@ -203,45 +207,45 @@ fn start_program(prog: ~str, args: ~[~str]) -> program {
203207
err_file: *libc::FILE,
204208
mut finished: bool};
205209

206-
fn close_repr_input(r: prog_repr) {
210+
fn close_repr_input(r: &prog_repr) {
207211
let invalid_fd = -1i32;
208212
if r.in_fd != invalid_fd {
209213
libc::close(r.in_fd);
210214
r.in_fd = invalid_fd;
211215
}
212216
}
213-
fn finish_repr(r: prog_repr) -> int {
217+
fn finish_repr(r: &prog_repr) -> int {
214218
if r.finished { return 0; }
215219
r.finished = true;
216220
close_repr_input(r);
217221
return waitpid(r.pid);
218222
}
219-
fn destroy_repr(r: prog_repr) {
223+
fn destroy_repr(r: &prog_repr) {
220224
finish_repr(r);
221225
libc::fclose(r.out_file);
222226
libc::fclose(r.err_file);
223227
}
224228
class prog_res {
225229
let r: prog_repr;
226-
new(-r: prog_repr) { self.r = r; }
227-
drop { destroy_repr(self.r); }
230+
new(+r: prog_repr) { self.r = r; }
231+
drop { destroy_repr(&self.r); }
228232
}
229233

230234
impl prog_res: program {
231235
fn get_id() -> pid_t { return self.r.pid; }
232236
fn input() -> io::writer { io::fd_writer(self.r.in_fd, false) }
233237
fn output() -> io::reader { io::FILE_reader(self.r.out_file, false) }
234238
fn err() -> io::reader { io::FILE_reader(self.r.err_file, false) }
235-
fn close_input() { close_repr_input(self.r); }
236-
fn finish() -> int { finish_repr(self.r) }
237-
fn destroy() { destroy_repr(self.r); }
239+
fn close_input() { close_repr_input(&self.r); }
240+
fn finish() -> int { finish_repr(&self.r) }
241+
fn destroy() { destroy_repr(&self.r); }
238242
}
239243
let repr = {pid: pid,
240244
mut in_fd: pipe_input.out,
241245
out_file: os::fdopen(pipe_output.in),
242246
err_file: os::fdopen(pipe_err.in),
243247
mut finished: false};
244-
return prog_res(repr) as program;
248+
return prog_res(move repr) as program;
245249
}
246250

247251
fn read_all(rd: io::reader) -> ~str {
@@ -267,13 +271,13 @@ fn read_all(rd: io::reader) -> ~str {
267271
* A record, {status: int, out: str, err: str} containing the exit code,
268272
* the contents of stdout and the contents of stderr.
269273
*/
270-
fn program_output(prog: ~str, args: ~[~str]) ->
274+
fn program_output(prog: &str, args: &[~str]) ->
271275
{status: int, out: ~str, err: ~str} {
272276

273277
let pipe_in = os::pipe();
274278
let pipe_out = os::pipe();
275279
let pipe_err = os::pipe();
276-
let pid = spawn_process(prog, args, none, none,
280+
let pid = spawn_process(prog, args, &none, &none,
277281
pipe_in.in, pipe_out.out, pipe_err.out);
278282

279283
os::close(pipe_in.in);
@@ -321,7 +325,7 @@ fn program_output(prog: ~str, args: ~[~str]) ->
321325
return {status: status, out: outs, err: errs};
322326
}
323327

324-
fn writeclose(fd: c_int, s: ~str) {
328+
fn writeclose(fd: c_int, s: &str) {
325329
import io::writer_util;
326330

327331
error!{"writeclose %d, %s", fd as int, s};
@@ -393,9 +397,9 @@ mod tests {
393397
// Regression test for memory leaks
394398
#[ignore(cfg(windows))] // FIXME (#2626)
395399
fn test_leaks() {
396-
run::run_program(~"echo", ~[]);
397-
run::start_program(~"echo", ~[]);
398-
run::program_output(~"echo", ~[]);
400+
run::run_program("echo", []);
401+
run::start_program("echo", []);
402+
run::program_output("echo", []);
399403
}
400404

401405
#[test]
@@ -406,7 +410,7 @@ mod tests {
406410

407411
let pid =
408412
run::spawn_process(
409-
~"cat", ~[], none, none,
413+
"cat", [], &none, &none,
410414
pipe_in.in, pipe_out.out, pipe_err.out);
411415
os::close(pipe_in.in);
412416
os::close(pipe_out.out);
@@ -426,8 +430,8 @@ mod tests {
426430

427431
#[test]
428432
fn waitpid() {
429-
let pid = run::spawn_process(~"false", ~[],
430-
none, none,
433+
let pid = run::spawn_process("false", [],
434+
&none, &none,
431435
0i32, 0i32, 0i32);
432436
let status = run::waitpid(pid);
433437
assert status == 1;

src/libcore/to_bytes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
trait ToBytes {
26
fn to_bytes() -> ~[u8];
37
}

src/libcore/to_str.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
trait ToStr { fn to_str() -> ~str; }
26

37
impl int: ToStr {

src/libcore/tuple.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
//! Operations on tuples
26
37
trait TupleOps<T,U> {

src/libcore/unicode.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
mod general_category {
26
pure fn Cc(c: char) -> bool {
37
return match c {

src/libcore/util.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
/**
26
* Miscellaneous helpers for common patterns.
37
*/

0 commit comments

Comments
 (0)