Code changing

Luke Gorrie luke@REDACTED
Thu Sep 30 08:39:08 CEST 1999

G'day all,

A couple of questions about code changes in an erlang system. First,
we're having a problem changing code in etk-using modules. The module
itself is a gen_event and copes with code changes okay, but the
command functions given to tk objects don't seem to work
anymore. After a code change, I get:

tkfun error: 1 : {function_clause,{messaging_gui,

I've tried to fix this with:

code_change(OldVsn, State, Extra) ->
    etk:configure(State#state.button, [{command, fun view_message/0}]),
    {ok, State}.

But that didn't seem to do the trick - but then I don't really know
Tk, maybe I'm appending another command rather than replacing
it. How should I make etk callbacks update-safe, or am I wrong
about what the problem is?

The other issue is with gen_event and code_change. If I don't make
a code_change/3 function, my gen_event processes don't survive code
changes. I put this down to some code in gen_event:

{ok, NewState} = Module:code_change(OldVsn, H#handler.state, Extra),

Whereas gen_server and gen_fsm use a catch on this call, and
(gen_server at least) work with modules that don't declare
code_change. This seems to mean that it's not okay to omit
code_change/3 from gen_event modules, and so I've attached a patch to
erlang.el's gen_event skeleton to add code_change incase it's useful
to anyone else.

Is it actually ok to omit code_change from gen_servers? I had a little
trace through gen_server and sys but I'm still not clear on what
ultimately happens with the caught error from gen_server's call to a
non-existent code_change/3.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: elisp-gen_event.patch
Type: application/x-patch
Size: 880 bytes
Desc: Patch adding code_change/3 to gen_event skeleton
URL: <>
-------------- next part --------------

More information about the erlang-questions mailing list