[erlang-questions] dirty nif and enif_make_badarg()
Daniel Goertzen
daniel.goertzen@REDACTED
Wed May 28 21:19:11 CEST 2014
I am trying to write a dirty nif and am following the directions from
http://www.erlang.org/doc/man/erl_nif.html
Exceprt:
"A dirty NIF may not invoke the
enif_make_badarg<http://www.erlang.org/doc/man/erl_nif.html#enif_make_badarg>to
raise an exception. If it wishes to return an exception, the dirty NIF
should pass a regular result indicating the exception details to its
finalizer, and allow the finalizer to raise the exception on its behalf."
So I am doing this; here is my finalizer....
// cached atoms
ERL_NIF_TERM badarg;
static ERL_NIF_TERM badarg_finalizer(ErlNifEnv* env, ERL_NIF_TERM term)
{
if(term == badarg)
return enif_make_badarg(env);
else
return term;
}
... and I end up with the exception context of the finalizer and not the
nif as desired...
5> generate_rsa:generate_rsa_key(abc, 65537).
entering generate_rsa_key_nif
entering generate_rsa_key_nif_dirty
entering
badarg_finalizer
** exception error: bad argument
in function generate_rsa:generate_rsa_key_nif/2
called as
generate_rsa:generate_rsa_key_nif(badarg,18446744072346624528) *!!!
should be (abc,65537)*
in call from generate_rsa:generate_rsa_key/2 (src/generate_rsa.erl,
line 25)
The documentation implies I can provide the "exception details", but
enif_make_badarg() doesn't offer any extra parameters. Is there some other
way to set the "exception details"?
Thanks,
Dan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140528/279526da/attachment.htm>
More information about the erlang-questions
mailing list