diff options
author | Björn Gustavsson <[email protected]> | 2011-11-09 17:27:52 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-11-14 14:46:58 +0100 |
commit | b67d3e5447f4b2bca3ed92f3db84adb3f79f9b16 (patch) | |
tree | 8d8697d0cde6adb6680b64d2d424b739f5df99b2 /erts/emulator/beam/beam_bif_load.c | |
parent | 757a4720645366af1aace7469a6f5e7b9be7ab45 (diff) | |
download | otp-b67d3e5447f4b2bca3ed92f3db84adb3f79f9b16.tar.gz otp-b67d3e5447f4b2bca3ed92f3db84adb3f79f9b16.tar.bz2 otp-b67d3e5447f4b2bca3ed92f3db84adb3f79f9b16.zip |
BEAM loader: Clean up handling of error reasons
There is no reason to have erts_load_module() return integer values,
only to have the caller convert the values to atoms. Return the
appropriate atom directly from the place where the error is generated
instead. Return NIL if the module was successfully loaded.
Diffstat (limited to 'erts/emulator/beam/beam_bif_load.c')
-rw-r--r-- | erts/emulator/beam/beam_bif_load.c | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/erts/emulator/beam/beam_bif_load.c b/erts/emulator/beam/beam_bif_load.c index 9ee4bb6878..e57becbe9f 100644 --- a/erts/emulator/beam/beam_bif_load.c +++ b/erts/emulator/beam/beam_bif_load.c @@ -50,7 +50,6 @@ load_module_2(BIF_ALIST_2) { Eterm reason; Eterm* hp; - int i; int sz; byte* code; Eterm res; @@ -69,38 +68,15 @@ load_module_2(BIF_ALIST_2) hp = HAlloc(BIF_P, 3); sz = binary_size(BIF_ARG_2); - if ((i = erts_load_module(BIF_P, 0, - BIF_P->group_leader, &BIF_ARG_1, code, sz)) < 0) { - switch (i) { - case -1: reason = am_badfile; break; - case -2: reason = am_nofile; break; - case -3: reason = am_not_purged; break; - case -4: - reason = am_atom_put("native_code", sizeof("native_code")-1); - break; - case -5: - { - /* - * The module contains an on_load function. The loader - * has loaded the module as usual, except that the - * export entries does not point into the module, so it - * is not possible to call any code in the module. - */ - - ERTS_DECL_AM(on_load); - reason = AM_on_load; - break; - } - default: reason = am_badfile; break; - } + reason = erts_load_module(BIF_P, 0, BIF_P->group_leader, + &BIF_ARG_1, code, sz); + if (reason != NIL) { res = TUPLE2(hp, am_error, reason); - goto done; + } else { + set_default_trace_pattern(BIF_ARG_1); + res = TUPLE2(hp, am_module, BIF_ARG_1); } - set_default_trace_pattern(BIF_ARG_1); - res = TUPLE2(hp, am_module, BIF_ARG_1); - - done: erts_free_aligned_binary_bytes(temp_alloc); erts_smp_thr_progress_unblock(); erts_smp_proc_lock(BIF_P, ERTS_PROC_LOCK_MAIN); @@ -769,7 +745,7 @@ delete_export_references(Eterm module) } -int +Eterm beam_make_current_old(Process *c_p, ErtsProcLocks c_p_locks, Eterm module) { Module* modp = erts_put_module(module); @@ -780,12 +756,12 @@ beam_make_current_old(Process *c_p, ErtsProcLocks c_p_locks, Eterm module) */ if (modp->code != NULL && modp->old_code != NULL) { - return -3; + return am_not_purged; } else if (modp->old_code == NULL) { /* Make the current version old. */ delete_code(c_p, c_p_locks, modp); delete_export_references(module); } - return 0; + return NIL; } static int |