Skip to content

Commit

Permalink
Don't use process::exit as it is an unreachable on wasm32
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed Dec 26, 2017
1 parent 2cdd1c4 commit 5a4298b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
12 changes: 2 additions & 10 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,7 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) {
rust_main: ValueRef,
rust_main_def_id: DefId,
use_start_lang_item: bool) {
// The libstd lang_start function does not return anything, while user defined lang start
// returns a isize
let start_output_ty = if use_start_lang_item { Type::void(ccx) } else { Type::c_int(ccx) };
let llfty = Type::func(&[Type::c_int(ccx), Type::i8p(ccx).ptr_to()], &start_output_ty);
let llfty = Type::func(&[Type::c_int(ccx), Type::i8p(ccx).ptr_to()], &Type::c_int(ccx));

let main_ret_ty = ccx.tcx().fn_sig(rust_main_def_id).output();
// Given that `main()` has no arguments,
Expand Down Expand Up @@ -600,12 +597,7 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) {
};

let result = bld.call(start_fn, &args, None);

if use_start_lang_item {
bld.ret_void();
} else {
bld.ret(bld.intcast(result, Type::c_int(ccx), true));
}
bld.ret(bld.intcast(result, Type::c_int(ccx), true));
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/libstd/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,18 @@ pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};
// the real work.
#[cfg(not(any(test, stage0)))]
fn lang_start_internal(main: &(Fn() -> i32 + Sync + ::panic::RefUnwindSafe),
argc: isize, argv: *const *const u8) -> ! {
argc: isize, argv: *const *const u8) -> isize {
use panic;
use sys;
use sys_common;
use sys_common::thread_info;
use thread::Thread;
use process;
#[cfg(not(feature = "backtrace"))]
use mem;

sys::init();

process::exit(unsafe {
unsafe {
let main_guard = sys::thread::guard::init();
sys::stack_overflow::init();

Expand All @@ -65,14 +64,14 @@ fn lang_start_internal(main: &(Fn() -> i32 + Sync + ::panic::RefUnwindSafe),
let exit_code = panic::catch_unwind(move || main());

sys_common::cleanup();
exit_code.unwrap_or(101)
});
exit_code.unwrap_or(101) as isize
}
}

#[cfg(not(any(test, stage0)))]
#[lang = "start"]
fn lang_start<T: ::termination::Termination + 'static>
(main: fn() -> T, argc: isize, argv: *const *const u8) -> !
(main: fn() -> T, argc: isize, argv: *const *const u8) -> isize
{
lang_start_internal(&move || main().report(), argc, argv)
}
Expand Down

0 comments on commit 5a4298b

Please sign in to comment.