[erlang-questions] [Q] erlang:check_process_code/2
Bjorn Gustavsson
bjorn@REDACTED
Fri Apr 18 11:15:46 CEST 2008
Ladislav Lenart <lenartlad@REDACTED> writes:
> I tried the above for `SomeFun = fun SomeMod:f/0' and also for `fun f/0'
> (using another function from `SomeMod'). But both return false.
My answer was slightly wrong. When I said "fun", I should have said "internal fun".
fun SomeMod:f/0 is an external fun, which is implemented differently from
an internal fun (fun f/0). External funs do not refer directly to the code
for the module, but use an additional level of indirection, so it is perfectly
safe to purge a module even if external funs reference the module. Therefore,
erlang:check_process_code/2 does not consider external funs at all.
> So I either misunderstood you or my above "test case" is wrong. Could you
> please shed some light on this for me?
I can't tell, because you didn't show the code for your test case.
Maybe your code didn't actually hold the fun.
Using my own code (below), everything works as expected:
Erlang (BEAM) emulator version 5.6.2 [async-threads:0] [kernel-poll:false]
Eshell V5.6.2 (abort with ^G)
1> P = fun_proc:start().
<0.32.0>
2> P ! {'fun',some_mod:some_fun()}.
{'fun',#Fun<some_mod.0.39827269>}
3> code:purge(some_mod).
false
4> code:delete(some_mod).
true
5> erlang:check_process_code(P, some_mod).
true
/Bjorn
-module(some_mod).
-compile(export_all).
some_fun() ->
fun() -> ok end.
-module(fun_proc).
-compile([export_all]).
start() ->
spawn_link(fun hold_fun/0).
hold_fun() ->
receive
{'fun',Fun} ->
hold_fun(Fun)
end.
hold_fun(Fun) ->
receive
{get_fun,Pid} ->
Pid ! Fun
end.
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list