[erlang-questions] NIF Problem

Sverker Eriksson sverker@REDACTED
Thu Apr 28 14:48:31 CEST 2011


Jachym Holecek wrote:
> # Travis Jensen 2011-04-28:
>   
>> [... This results in SIGBUS after returning to Erlang ...]
>>
>>  1. static ERL_NIF_TERM aes_ctr_encrypt_with_state(ErlNifEnv* env, int argc, const ERL_NIF_TERM
>>     argv[])
>>  2. {/* ({Key, IVec, ECount, Num}, Data) */    
>>  3.     ErlNifBinary key_bin, ivec_bin, text_bin, ecount_bin;
>>
>>     
:
>> 34.     new_state_term = enif_make_tuple4(env, key_bin, ivec2_term, ecount2_term, num2_term);
>> 35.     ret = enif_make_tuple2(env, new_state_term, cipher_term);
>> 36.     return ret;
>> 37. }
>>     
>
> Just a random guess really, but your key_bin doesn't seem to be a proper term
> suitable for returning to Erlang, shoudln't you run enif_make_binary() on it?
> The compiler should warn you about that too, unless ERL_NIF_TERM is something
> hopelessly vague like "void *"...
>
> Regards,
> 	-- Jachym
>
>   
Nicely spotted, Jachym.

The reason the compiler did not complain is that enif_make_tuple4 is a 
macro calling variadic function enif_make_tuple(ErlNifEnv*, ...).

A patch turning enif_make_tuple# and enif_make_list# into inline 
functions (if compiler supports it) would probably be a good idea. Any 
takers?


/Sverker, Erlang/OTP



More information about the erlang-questions mailing list