From a1131748c2e86bcbcbbbec81a83ca844e58073b4 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 8 Sep 2011 12:03:07 -0700 Subject: Add a waitpid wrapper to std::run that interprets the exit status on unix This makes the result of running a program a little more uniform between unix and windows --- src/lib/run_program.rs | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/run_program.rs b/src/lib/run_program.rs index a4adaace38a..6e65e5261d4 100644 --- a/src/lib/run_program.rs +++ b/src/lib/run_program.rs @@ -6,6 +6,7 @@ export run_program; export start_program; export program_output; export spawn_process; +export waitpid; native "rust" mod rustrt { fn rust_run_program(argv: *sbuf, in_fd: int, out_fd: int, err_fd: int) -> @@ -33,7 +34,7 @@ fn spawn_process(prog: &str, args: &[str], in_fd: int, out_fd: int, } fn run_program(prog: &str, args: &[str]) -> int { - ret os::waitpid(spawn_process(prog, args, 0, 0, 0)); + ret waitpid(spawn_process(prog, args, 0, 0, 0)); } type program = @@ -87,7 +88,7 @@ fn start_program(prog: &str, args: &[str]) -> @program_res { if finished { ret 0; } finished = true; self.close_input(); - ret os::waitpid(pid); + ret waitpid(pid); } fn destroy() { self.finish(); @@ -117,6 +118,44 @@ fn program_output(prog: &str, args: &[str]) -> out: read_all(pr.output()), err: read_all(pr.err())}; } + +/* Returns an exit status */ +#[cfg(target_os = "win32")] +fn waitpid(pid: int) -> int { + os::waitpid(pid) +} + +#[cfg(target_os = "linux")] +#[cfg(target_os = "macos")] +fn waitpid(pid: int) -> int { + #[cfg(target_os = "linux")] + fn WIFEXITED(status: int) -> bool { + (status & 0xff) == 0 + } + + #[cfg(target_os = "macos")] + fn WIFEXITED(status: int) -> bool { + (status & 0x7f) == 0 + } + + #[cfg(target_os = "linux")] + fn WEXITSTATUS(status: int) -> int { + (status >> 8) & 0xff + } + + #[cfg(target_os = "macos")] + fn WEXITSTATUS(status: int) -> int { + status >> 8 + } + + let status = os::waitpid(pid); + ret if WIFEXITED(status) { + WEXITSTATUS(status) + } else { + 1 + }; +} + // Local Variables: // mode: rust // fill-column: 78; -- cgit 1.4.1-3-g733a5 From 22001d1dcef5d2c40a242402f75d5acc540bee2b Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 8 Sep 2011 16:59:23 -0700 Subject: Remove hack_allow_leaks Happy to close the loop on this one. Issue #236 --- src/lib/test.rs | 7 ------- src/rt/memory_region.cpp | 11 +++-------- src/rt/memory_region.h | 5 ----- src/rt/rust_builtin.cpp | 7 ------- src/rt/rustrt.def.in | 1 - 5 files changed, 3 insertions(+), 28 deletions(-) (limited to 'src/lib') diff --git a/src/lib/test.rs b/src/lib/test.rs index 37fec12e9ce..cbee1f1f479 100644 --- a/src/lib/test.rs +++ b/src/lib/test.rs @@ -26,7 +26,6 @@ export configure_test_task; export joinable; native "rust" mod rustrt { - fn hack_allow_leaks(); fn sched_threads() -> uint; } @@ -325,12 +324,6 @@ fn configure_test_task() { // If this task fails we don't want that failure to propagate to the // test runner or else we couldn't keep running tests task::unsupervise(); - - // FIXME (236): Hack supreme - unwinding doesn't work yet so if this - // task fails memory will not be freed correctly. This turns off the - // sanity checks in the runtime's memory region for the task, so that - // the test runner can continue. - rustrt::hack_allow_leaks(); } // Local Variables: diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp index ef8a92b427f..a55d073543d 100644 --- a/src/rt/memory_region.cpp +++ b/src/rt/memory_region.cpp @@ -15,13 +15,13 @@ memory_region::alloc_header *memory_region::get_header(void *mem) { memory_region::memory_region(rust_srv *srv, bool synchronized) : _srv(srv), _parent(NULL), _live_allocations(0), _detailed_leaks(srv->env->detailed_leaks), - _synchronized(synchronized), _hack_allow_leaks(false) { + _synchronized(synchronized) { } memory_region::memory_region(memory_region *parent) : _srv(parent->_srv), _parent(parent), _live_allocations(0), _detailed_leaks(parent->_detailed_leaks), - _synchronized(parent->_synchronized), _hack_allow_leaks(false) { + _synchronized(parent->_synchronized) { } void memory_region::add_alloc() { @@ -127,18 +127,13 @@ memory_region::~memory_region() { assert(leak_count == _live_allocations); } #endif - if (!_hack_allow_leaks && _live_allocations > 0) { + if (_live_allocations > 0) { _srv->fatal(msg, __FILE__, __LINE__, "%d objects", _live_allocations); } if (_synchronized) { _lock.unlock(); } } -void -memory_region::hack_allow_leaks() { - _hack_allow_leaks = true; -} - void memory_region::release_alloc(void *mem) { alloc_header *alloc = get_header(mem); diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h index 0197057268c..9d2106c1eaf 100644 --- a/src/rt/memory_region.h +++ b/src/rt/memory_region.h @@ -32,7 +32,6 @@ private: const bool _detailed_leaks; const bool _synchronized; lock_and_signal _lock; - bool _hack_allow_leaks; void add_alloc(); void dec_alloc(); @@ -46,10 +45,6 @@ public: void *realloc(void *mem, size_t size); void free(void *mem); virtual ~memory_region(); - // FIXME (236: This is a temporary hack to allow failing tasks that leak - // to not kill the entire process, which the test runner needs. Please - // kill with prejudice once unwinding works. - void hack_allow_leaks(); void release_alloc(void *mem); void claim_alloc(void *mem); diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 5e0c9dbf4c2..2499dea0328 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -224,13 +224,6 @@ debug_opaque(rust_task *task, type_desc *t, uint8_t *front) } } -extern "C" CDECL void -hack_allow_leaks(rust_task *task) -{ - LOG(task, stdlib, "hack_allow_leaks"); - task->local_region.hack_allow_leaks(); -} - struct rust_box { RUST_REFCOUNTED(rust_box) diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index 246ac261f8f..bf8155b7998 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -28,7 +28,6 @@ get_task_id get_task_pointer get_task_trampoline get_time -hack_allow_leaks last_os_error leak migrate_alloc -- cgit 1.4.1-3-g733a5