[erlang-bugs] NIF .so reload issues

David Buckley isreal-erlang-bugs-at-erlang.org@REDACTED
Fri Dec 18 15:19:45 CET 2015


Hi! I was playing with writing a NIF, and found I couldn't reload.

I'm doing the sort-of accepted thing of loading the nif in an on_load
function, though if I just execute the function just after load, I get
the same behaviour, so I don't think that's at issue.

Basically, what seems to be the case is that while erlang will
re-initialise my nif code (with 'upgrade'), it won't load a /new/
version of the nif code unless I completely purge the (erlang) code from
the runtime, forcing erlang to recheck the module. I'm guessing erlang
is caching the nif. Changing the compiled (.so) filename each time fixes
the problem.


Example code here:

https://gist.github.com/bucko909/a3b5099c74bf267e65db

test_reload_post_purge and test_reload_post_reload_complete_purge work
fine (erts-7.1), but the other three don't reload the .so file as I
would expect.


Is this fixable, or must I manually add a purge() in my init() function
before load_nif? (And why does that work? Because at that point there's
no evidence that the new module will have a load_nif, so the old dlopen
can be discarded?)

Seems like in general if the .so file has changed and a module is
reloaded, the user probably wants the new .so file, too! It's at least
worth adding a note to the docs (or a new return value?) if it's an evil
dlopen restriction.

-- 
David Buckley



More information about the erlang-bugs mailing list