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

Jachym Holecek freza@REDACTED
Wed Jan 8 05:54:34 CET 2014

# 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. :-)

	-- Jachym

More information about the erlang-questions mailing list