[erlang-questions] Question on naming of NIF library function
Avinash Dhumane
avinash_dhumane@REDACTED
Wed Jan 8 05:12:27 CET 2014
I am a student of whatever the name "Erlang" stands for - programming
language, operating system, database system, platform (whatever)!
I am in a (mental) process of making NIF, and the two objects in front of me
are: http://www.erlang.org/doc/tutorial/nif.html and
http://www.erlang.org/doc/man/erl_nif.html
The NIF is meant for the private consumption of my application, not to be
exported for public. So, the pre & post conditions for the NIF invocation
are controlled. The onward and return payload for the NIF is "binary".
By looking at the examples and the pattern of the set of library functions
in erl_nif, I (falsely) imagined that there would be something like
enif_get_binary() for receiving and enif_make_binary() for returning,
available in the library. While the latter was found and its semantics for
read-only (and memory release) understood from the documentation, the former
call, i.e. enif_get_binary(), was nowhere to be found.
Then, I found enif_get_string() - the progression of time in the mental
process is important here (at least, from a student's point of view). The
thought did rise that perhaps I needed to pass a list of bytes (instead of
binary) to the NIF, but the last parameter, i.e. ErlNifCharEncoding, of
enif_get_string() stopped that thought, for I didn't intend to encode the
bytes in ERL_NIF_LATIN1.
So, I searched more, and found enif_inspect_binary() and just below it the
enif_is_binary() library function. For a moment, I doubted why two calls for
apparently same purpose - which is "gathered" from the naming, only to find
that the former, i.e. enif_inspect_binary(), not only inspects but also
initializes the ErlNifBinary structure, from where I could pick up the
payload and do the needful before calling enif_make_binary() at the time of
returning from NIF. I am still in a mental process, here.
So, the question is: What considerations are needed, to have, specifically
for NIF and in general for Erlang, to appreciate the name
enif_inspect_binary() instead of enif_get_binary()? I suppose there are
several such "naming" places in Erlang, and I raised this particular one
only to give a play to the "why" urge in me.
Thanks
Avinash
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140108/6240a88e/attachment.htm>
More information about the erlang-questions
mailing list