Amin
Amin

Reputation: 755

Erlang nif does not upgrades

I write a nif library in erlang. Also i write load, upgrade and unload functions.

This is my code:

#include "erl_nif.h"


int checksum(char *s)
{
    return 123;
}


/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////


static ERL_NIF_TERM
checksum_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    return enif_make_int(env, checksum(""));
}


/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////


static int
load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
    *priv_data = enif_open_resource_type(env,
                                         NULL,
                                         "cwm_utils_buf",
                                         NULL,
                                         ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER,
                                         NULL);
    return 0;
}


static int
upgrade(ErlNifEnv* env, void** priv_data, void** old_priv_data, ERL_NIF_TERM load_info)
{
    *priv_data = enif_open_resource_type(env,
                                         NULL,
                                         "cwm_utils_buf",
                                         NULL,
                                         ERL_NIF_RT_TAKEOVER,
                                         NULL);
    return 0;
}


static void
unload(ErlNifEnv* env, void* priv_data)
{
    return ;
}


static ErlNifFunc nif_funcs[] = {
    {"checksum", 1, checksum_nif}
};



ERL_NIF_INIT(mynif, nif_funcs, &load, NULL, &upgrade, &unload);

In erlang shell i load this nif and run checksum function and it returns 123 and everything is fine!

After that i change return value of checksum to 123456 and compile and load the nif to erlang vm using l(mynif) command.

Here is the problem! If i run checksum function, the return value must be 123445 but it is still 123 and nif have not been upgraded.

What is the problem? I search a lot and tested some examples and libraries like jiffy but didn`t work.

Upvotes: 0

Views: 182

Answers (1)

Elwin Arens
Elwin Arens

Reputation: 1602

Try:

code:purge(mynif).
code:delete(mynif).
l(mynif).

Upvotes: 1

Related Questions