NIF .so reload issues
David Buckley <[email protected]> Fri, 18 Dec 2015 14:19:45 +0000
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <[email protected]> |
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 _______________________________________________ erlang-bugs mailing list [email protected] http://erlang.org/mailman/listinfo/erlang-bugs