aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2009-12-10 10:21:55 +0100
committerBjörn Gustavsson <[email protected]>2009-12-13 15:42:36 +0100
commit7ab33f49185d5a416198f1e0bf5a2ca9f347bbac (patch)
tree80e5c93a0df2b1583601d2fcfff29071918715e7 /lib
parent9855ed863b58f7325f39b00c60813198ec41f528 (diff)
downloadotp-7ab33f49185d5a416198f1e0bf5a2ca9f347bbac.tar.gz
otp-7ab33f49185d5a416198f1e0bf5a2ca9f347bbac.tar.bz2
otp-7ab33f49185d5a416198f1e0bf5a2ca9f347bbac.zip
Change the expected return value for on_load functions
An on_load function is supposed to return 'true' to indicate that the module should be loaded, and 'false' if it should be unloaded. But returning any other term, as well as causing an exception, will also unload the module. Since we don't like boolean values mixed with other values, change the expected return value as follows: * If 'ok' is returned, the module will remain loaded and become callable. * If any other value is returned (or an exception is generated), the module will be unloaded. Also, if the returned value is not an atom, send a warning message to the error_logger (using error_logger:warning_msg/2). The new interpretation of the return value means that an on_load function can now directly return the return value from erlang:load_nif/2.
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler/test/compilation_SUITE_data/on_load.erl2
-rw-r--r--lib/kernel/src/code_server.erl27
-rw-r--r--lib/kernel/test/code_SUITE.erl2
-rw-r--r--lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl2
-rw-r--r--lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl2
-rw-r--r--lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl2
-rw-r--r--lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl2
7 files changed, 29 insertions, 10 deletions
diff --git a/lib/compiler/test/compilation_SUITE_data/on_load.erl b/lib/compiler/test/compilation_SUITE_data/on_load.erl
index 92bcf74624..e9b5ec7f34 100644
--- a/lib/compiler/test/compilation_SUITE_data/on_load.erl
+++ b/lib/compiler/test/compilation_SUITE_data/on_load.erl
@@ -12,7 +12,7 @@
do_on_load() ->
local_function(),
- true.
+ ok.
local_function() ->
ok.
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl
index 018f7f41d2..d4e3f0bcf8 100644
--- a/lib/kernel/src/code_server.erl
+++ b/lib/kernel/src/code_server.erl
@@ -1479,13 +1479,12 @@ finish_on_load(Ref, OnLoadRes, #state{on_load=OnLoad0,moddb=Db}=State) ->
end.
finish_on_load_1(Mod, File, OnLoadRes, WaitingPids, Db) ->
- Keep = if
- is_boolean(OnLoadRes) -> OnLoadRes;
- true -> false
- end,
+ Keep = OnLoadRes =:= ok,
erlang:finish_after_on_load(Mod, Keep),
Res = case Keep of
- false -> {error,on_load_failure};
+ false ->
+ finish_on_load_report(Mod, OnLoadRes),
+ {error,on_load_failure};
true ->
ets:insert(Db, {Mod,File}),
{module,Mod}
@@ -1493,6 +1492,24 @@ finish_on_load_1(Mod, File, OnLoadRes, WaitingPids, Db) ->
[reply(Pid, Res) || Pid <- WaitingPids],
ok.
+finish_on_load_report(_Mod, Atom) when is_atom(Atom) ->
+ %% No error reports for atoms.
+ ok;
+finish_on_load_report(Mod, Term) ->
+ %% Play it very safe here. The error_logger module and
+ %% modules it depend on may not be loaded yet and there
+ %% would be a dead-lock if we called it directly
+ %% from the code_server process.
+ spawn(fun() ->
+ F = "The on_load function for module "
+ "~s returned ~P\n",
+
+ %% Express the call as an apply to simplify
+ %% the ext_mod_dep/1 test case.
+ E = error_logger,
+ E:warning_msg(F, [Mod,Term,10])
+ end).
+
%% -------------------------------------------------------
%% Internal functions.
%% -------------------------------------------------------
diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl
index 9fda66711d..d4c32311e7 100644
--- a/lib/kernel/test/code_SUITE.erl
+++ b/lib/kernel/test/code_SUITE.erl
@@ -671,6 +671,8 @@ check_funs({'$M_EXPR','$F_EXPR',2},
check_funs({'$M_EXPR','$F_EXPR',1},
[{lists,foreach,2},
{hipe_unified_loader,patch_consts,3} | _]) -> 0;
+check_funs({'$M_EXPR',warning_msg,2},
+ [{code_server,finish_on_load_report,2} | _]) -> 0;
%% This is cheating! /raimo
%%
%% check_funs(This = {M,_,_}, Path) ->
diff --git a/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl b/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl
index 660000df46..f6bcb6570b 100644
--- a/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl
+++ b/lib/kernel/test/code_SUITE_data/on_load/on_load_a.erl
@@ -13,7 +13,7 @@ on_load() ->
LibDir = code:lib_dir(kernel),
?MASTER ! {?MODULE,LibDir},
- true.
+ ok.
data() ->
[a|on_load_b:data()].
diff --git a/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl b/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl
index 5c4d676e2d..947cbd5bcd 100644
--- a/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl
+++ b/lib/kernel/test/code_SUITE_data/on_load/on_load_b.erl
@@ -6,7 +6,7 @@ on_load() ->
?MASTER ! {?MODULE,start},
on_load_c:data(),
?MASTER ! {?MODULE,done},
- true.
+ ok.
data() ->
[b|on_load_c:data()].
diff --git a/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl b/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl
index 4b2edbfb5a..6ab7f6402f 100644
--- a/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl
+++ b/lib/kernel/test/code_SUITE_data/on_load/on_load_c.erl
@@ -7,7 +7,7 @@ on_load() ->
receive
go ->
?MASTER ! {?MODULE,done},
- true
+ ok
end.
data() ->
diff --git a/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl b/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl
index bfc26864d5..a39332f81d 100644
--- a/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl
+++ b/lib/kernel/test/code_SUITE_data/on_load_app-1.0/src/on_load_embedded.erl
@@ -9,7 +9,7 @@ run_me() ->
ok
end
end),
- true.
+ ok.
status() ->
case whereis(everything_is_fine) of