Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang, Is it possible to reload or upgrade a nif library without restart the shell?

I have a nif library and every time i recompile it, I must restart the shell to reload or upgrade this library.

Here is my erlang code:

-module(q4).
-export([init/0]).

-on_load(init/0).


init() ->
    erlang:load_nif("./q4_nif", reload).

Every time i compile the erlang module, this error occurs:

`The on_load function for module q4 returned {error,
                                         {upgrade,
                                          "Upgrade not supported by this NIF library."}}`

and when i call init/0 function, this error occurs: {error,{reload,"Reload not supported by this NIF library."}}

Is there anyway to fix this problem and load new nif library without restarting the shell?

like image 980
Amin Avatar asked Oct 30 '15 00:10

Amin


1 Answers

As the error message indicates, you need to provide an upgrade function in your NIF, which you specify in your call to ERL_NIF_INIT:

ERL_NIF_INIT(MODULE, ErlNifFunc funcs[], load, reload, upgrade, unload)

The upgrade function is documented in the erl_nif man page.

like image 141
Steve Vinoski Avatar answered Oct 07 '22 23:10

Steve Vinoski