[erlang-questions] funs versus code loading

Tony Rogvall <>
Fri May 13 10:58:27 CEST 2011


On 13 maj 2011, at 09.05, Sam Bobroff wrote:

> On 13 May 2011 16:08, Nahuel Greco <> wrote:
> Sam, check this thread:
> http://thread.gmane.org/gmane.comp.lang.erlang.general/47310
> Saludos,
> Nahuel Greco.
> Ah yes that seems to match exactly what I've observed!
> Thanks for that :-)
> I agree with your (and Matthias') comments in that it should be changed in accordance with the patch!
> In my opinion the current system is confusing and therefore dangerous.
If you change your example into this:
-export([start/0, loop/0]).
start() ->
        register(?MODULE, spawn(?MODULE, loop, [])).
loop() ->
        io:fwrite("loop version ~p\n", [?V]),
                _ ->
                        F = fun () -> ?V,loop() end,

The only difference is that I put a dummy version value inside the fun. This is enough to make the
fun handle unique (in this case). In one project I used a erlang:now value to (mostly) generate a new function reference.

> Hmm... from poking around in the emulator code it looks like the "hash" is made up of three components XOR'ed together:
> * the index
> * the module's name
> * a "uniq" value
> Since during code reloading, the module name and index could easily be the same... if the uniq were the same then the emulator would be fooled into thinking it was OK to use the new version of the code... when it was not OK.
I guess the new_unique (same as module:info) should/could be used some how.

> I couldn't see what system was used to set the uniq value ("old_uniq" in most of the code I saw)... does anyone know what it is?
> Even without knowing the algorithm, if I can control the Fun's index, and I can see it's uniq, I can probably cause a hash collision by setting the index to a specific value.
> The reason I ask is that I'm wondering if a hash collision is possible and if that has the potential to crash the emulator.
> Sam.
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions

"Have run Make so many times I dunno what's installed anymore"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110513/ab3059ad/attachment.html>

More information about the erlang-questions mailing list