Test for valid ERL_NIF_TERM
Mon Sep 27 21:09:03 CEST 2021
On Mon, Sep 27, 2021 at 12:31 PM Robert Harris
> Hi Sverker,
> Many thanks for sharing your thoughts; the outcome is as I expected but it is
> useful to have checked. I will refrain from abusing the opacity.
> > On 27 Sep 2021, at 10:57, Sverker Eriksson <sverker.eriksson@REDACTED> wrote:
> > No there is no ERL_NIF_TERM_UNINITIALISED in the erl_nif API.
> > There is one erts internal called THE_NON_VALUE, which is what is returned by enif_raise_exception and makes enif_is_exception return true.
> > So it would be possible to introduce, but I'm not sure how to best make it fit in with the existing "exception" value.
> > If you just want to do something quick and dirty use the value zero. But don't complain if that stops working at some time.
> > /Sverker, Erlang/OTP
> > From: erlang-questions <erlang-questions-bounces@REDACTED> on behalf of Robert Harris <robert.harris@REDACTED>
> > Sent: Wednesday, September 22, 2021 12:50 PM
> > To: erlang-questions@REDACTED Questions <erlang-questions@REDACTED>
> > Subject: Test for valid ERL_NIF_TERM
> > Are any values of ERL_NIF_TERM reserved to mean "invalid"? I.e. is
> > there a blessed equivalent of
> > ERL_NIF_TERM optional = ERL_NIF_TERM_UNINITIALISED;
> > .
> > .
> > .
> > if (optional != ERL_NIF_TERM_UNINITIALISED)
> > do_something(optional)
Lest anyone gets "creative", THE_NON_VALUE MUST NOT occur in any
position where a valid Erlang term is required.
If you need something for a NIF, find a valid but out-of-band value
for your use case, or encode the "is initialized" condition
More information about the erlang-questions