Skip to content

Commit eafbf88

Browse files
committed
---
yaml --- r: 41979 b: refs/heads/master c: c15facb h: refs/heads/master i: 41977: 1a46dc4 41975: 738b910 v: v3
1 parent 403b240 commit eafbf88

File tree

2 files changed

+69
-71
lines changed

2 files changed

+69
-71
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: e22d2bc4bc4ed84c72148bdd00c8da0eb4238c45
2+
refs/heads/master: c15facb5c092f5d1e5b687111f4dbcd117d567d7
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
55
refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650

trunk/src/libcore/run.rs

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -204,88 +204,86 @@ pub fn run_program(prog: &str, args: &[~str]) -> int {
204204
* A class with a <program> field
205205
*/
206206
pub fn start_program(prog: &str, args: &[~str]) -> Program {
207-
unsafe {
208-
let pipe_input = os::pipe();
209-
let pipe_output = os::pipe();
210-
let pipe_err = os::pipe();
211-
let pid =
212-
spawn_process(prog, args, &None, &None,
213-
pipe_input.in, pipe_output.out,
214-
pipe_err.out);
207+
let pipe_input = os::pipe();
208+
let pipe_output = os::pipe();
209+
let pipe_err = os::pipe();
210+
let pid =
211+
spawn_process(prog, args, &None, &None,
212+
pipe_input.in, pipe_output.out,
213+
pipe_err.out);
215214

216-
unsafe {
217-
if pid == -1 as pid_t { fail; }
218-
libc::close(pipe_input.in);
219-
libc::close(pipe_output.out);
220-
libc::close(pipe_err.out);
221-
}
215+
unsafe {
216+
if pid == -1 as pid_t { fail; }
217+
libc::close(pipe_input.in);
218+
libc::close(pipe_output.out);
219+
libc::close(pipe_err.out);
220+
}
222221

223-
struct ProgRepr {
224-
pid: pid_t,
225-
mut in_fd: c_int,
226-
out_file: *libc::FILE,
227-
err_file: *libc::FILE,
228-
mut finished: bool,
229-
}
222+
struct ProgRepr {
223+
pid: pid_t,
224+
mut in_fd: c_int,
225+
out_file: *libc::FILE,
226+
err_file: *libc::FILE,
227+
mut finished: bool,
228+
}
230229

231-
fn close_repr_input(r: &ProgRepr) {
232-
let invalid_fd = -1i32;
233-
if r.in_fd != invalid_fd {
234-
unsafe {
235-
libc::close(r.in_fd);
236-
}
237-
r.in_fd = invalid_fd;
238-
}
239-
}
240-
fn finish_repr(r: &ProgRepr) -> int {
241-
if r.finished { return 0; }
242-
r.finished = true;
243-
close_repr_input(r);
244-
return waitpid(r.pid);
245-
}
246-
fn destroy_repr(r: &ProgRepr) {
230+
fn close_repr_input(r: &ProgRepr) {
231+
let invalid_fd = -1i32;
232+
if r.in_fd != invalid_fd {
247233
unsafe {
248-
finish_repr(r);
249-
libc::fclose(r.out_file);
250-
libc::fclose(r.err_file);
234+
libc::close(r.in_fd);
251235
}
236+
r.in_fd = invalid_fd;
252237
}
253-
struct ProgRes {
254-
r: ProgRepr,
255-
drop { destroy_repr(&self.r); }
238+
}
239+
fn finish_repr(r: &ProgRepr) -> int {
240+
if r.finished { return 0; }
241+
r.finished = true;
242+
close_repr_input(r);
243+
return waitpid(r.pid);
244+
}
245+
fn destroy_repr(r: &ProgRepr) {
246+
unsafe {
247+
finish_repr(r);
248+
libc::fclose(r.out_file);
249+
libc::fclose(r.err_file);
256250
}
251+
}
252+
struct ProgRes {
253+
r: ProgRepr,
254+
drop { destroy_repr(&self.r); }
255+
}
257256

258-
fn ProgRes(r: ProgRepr) -> ProgRes {
259-
ProgRes {
260-
r: move r
261-
}
257+
fn ProgRes(r: ProgRepr) -> ProgRes {
258+
ProgRes {
259+
r: move r
262260
}
261+
}
263262

264-
impl ProgRes: Program {
265-
fn get_id() -> pid_t { return self.r.pid; }
266-
fn input() -> io::Writer {
267-
io::fd_writer(self.r.in_fd, false)
268-
}
269-
fn output() -> io::Reader {
270-
io::FILE_reader(self.r.out_file, false)
271-
}
272-
fn err() -> io::Reader {
273-
io::FILE_reader(self.r.err_file, false)
274-
}
275-
fn close_input() { close_repr_input(&self.r); }
276-
fn finish() -> int { finish_repr(&self.r) }
277-
fn destroy() { destroy_repr(&self.r); }
263+
impl ProgRes: Program {
264+
fn get_id() -> pid_t { return self.r.pid; }
265+
fn input() -> io::Writer {
266+
io::fd_writer(self.r.in_fd, false)
278267
}
279-
let repr = ProgRepr {
280-
pid: pid,
281-
in_fd: pipe_input.out,
282-
out_file: os::fdopen(pipe_output.in),
283-
err_file: os::fdopen(pipe_err.in),
284-
finished: false,
285-
};
286-
287-
ProgRes(repr) as Program
268+
fn output() -> io::Reader {
269+
io::FILE_reader(self.r.out_file, false)
270+
}
271+
fn err() -> io::Reader {
272+
io::FILE_reader(self.r.err_file, false)
273+
}
274+
fn close_input() { close_repr_input(&self.r); }
275+
fn finish() -> int { finish_repr(&self.r) }
276+
fn destroy() { destroy_repr(&self.r); }
288277
}
278+
let repr = ProgRepr {
279+
pid: pid,
280+
in_fd: pipe_input.out,
281+
out_file: os::fdopen(pipe_output.in),
282+
err_file: os::fdopen(pipe_err.in),
283+
finished: false,
284+
};
285+
286+
ProgRes(repr) as Program
289287
}
290288

291289
fn read_all(rd: io::Reader) -> ~str {

0 commit comments

Comments
 (0)