[erlang-questions] Question on naming of NIF library function

Sverker Eriksson sverker.eriksson@REDACTED
Thu Jan 9 11:33:28 CET 2014


On 01/08/2014 05:54 AM, Jachym Holecek wrote:
> # Avinash Dhumane 2014-01-07:
>> 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.
> Sitting inside NIF code all Erlang values appear as values of opaque
> type ERL_NIF_TERM. While not directly accessible, these values are
> known to consist of two components -- type tag and payload.
>
> The enif_is_xxx() family of functions merely asses the type tag against
> your expectation and let you know of the outcome. The enif_get_xxx()
> family of functions do the same but additionally unpack the payload
> into a value of native C type which is fully under your management.
>
> Binaries involve additional considerations regarding access mode
> and ownership -- inspecting a binary (or iolist) gives you readonly
> capability valid only in current thread and only for the duration
> of this NIF call, it's a convenient view inside the value which
> nevertheless is fully owned by Erlang.
>
> So the difference in naming could be argued to make sense; even if I
> really think it's not a big deal and maybe kind of accidental. :-)
>
>

Yes, it was a deliberate naming choice to indicate that it is an 
inspection of a live Erlang term where you have to consider its 
"readonlyness" and lifetime.

/Sverker, Erlang/OTP




More information about the erlang-questions mailing list