aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/code_server.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2012-01-22 09:53:57 +0100
committerBjörn Gustavsson <[email protected]>2012-01-23 14:28:44 +0100
commit68731828019e14ef46ef6f2b8bd2c6eb87589a43 (patch)
tree430fda75786b9f1f1bdf2c1207943cc8736e0339 /lib/kernel/src/code_server.erl
parent4feb441edfe666ea926b11bb758d34c8b635466c (diff)
downloadotp-68731828019e14ef46ef6f2b8bd2c6eb87589a43.tar.gz
otp-68731828019e14ef46ef6f2b8bd2c6eb87589a43.tar.bz2
otp-68731828019e14ef46ef6f2b8bd2c6eb87589a43.zip
Fix on_load handling in modules loaded by code:load_binary/3
In "13.4 Running a function when a module is loaded" in the Reference Manual, it is said that: A process that calls any function in a module whose on_load function has not yet returned will be suspended until the on_load function has returned. That did not work if the module was loaded using code:load_binary/3. Instead, the callers would get an 'undef' exception.
Diffstat (limited to 'lib/kernel/src/code_server.erl')
-rw-r--r--lib/kernel/src/code_server.erl10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl
index 32a12e2b52..5d4f2eb70c 100644
--- a/lib/kernel/src/code_server.erl
+++ b/lib/kernel/src/code_server.erl
@@ -1317,15 +1317,21 @@ int_list([H|T]) when is_integer(H) -> int_list(T);
int_list([_|_]) -> false;
int_list([]) -> true.
+load_file(Mod0, {From,_}=Caller, St0) ->
+ Mod = to_atom(Mod0),
+ case pending_on_load(Mod, From, St0) of
+ no -> load_file_1(Mod, Caller, St0);
+ {yes,St} -> {noreply,St}
+ end.
-load_file(Mod, Caller, #state{path=Path,cache=no_cache}=St) ->
+load_file_1(Mod, Caller, #state{path=Path,cache=no_cache}=St) ->
case mod_to_bin(Path, Mod) of
error ->
{reply,{error,nofile},St};
{Mod,Binary,File} ->
try_load_module(File, Mod, Binary, Caller, St)
end;
-load_file(Mod, Caller, #state{cache=Cache}=St0) ->
+load_file_1(Mod, Caller, #state{cache=Cache}=St0) ->
Key = {obj,Mod},
case ets:lookup(Cache, Key) of
[] ->