[erlang-questions] Question about gen_event

Kostis Sagonas kostis@REDACTED
Wed Oct 1 18:17:42 CEST 2008


I've been staring at the code of 'gen_event' and I cannot make much 
sense of how the code for swapping handlers works.  In fact, I am quite 
convinced there is a bug in there but it is being silenced by the use of 
a catch.  Can somebody please confirm that this is a bug or enlighten me 
on what's happening?

The code of gen_event:do_swap/7 reads:

do_swap(Mod1,Handler1,Args1,State1,Handler2,Args2,SName) ->
     %% finalise the existing handler
     State2 = do_terminate(...),
     {Mod2,Handler} = new_handler(Handler2, Handler1),     %% <---
     case catch Mod2:init({Args2, State2}) of
         {ok, State2a} ->
             {ok, Handler#handler{state = State2a}};
         Other ->
             report_terminate(Handler2, crash, ...),       %% <---
             no
     end.

Is the use of Handler2 correct in the lines identified as %% <--- ?
At least one of them does not seem to be, but I cannot see which one.


Kostis


PS. This is not found by dialyzer - it requires very different analyses.



More information about the erlang-questions mailing list