Re: Test for valid ERL_NIF_TERM

Mikael Pettersson <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAM43=SOrrxRdMs=FGkT=1v2T5F8mjfDstJy5hdY9p09Tc3XpOg@mail.gmail.com>
On Mon, Sep 27, 2021 at 12:31 PM Robert Harris
<[email protected]> wrote:
>
> 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.
>
> Regards,
>
> Robert
>
>
> > On 27 Sep 2021, at 10:57, Sverker Eriksson <[email protected]> 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 <[email protected]> on behalf of Robert Harris <[email protected]>
> > Sent: Wednesday, September 22, 2021 12:50 PM
> > To: [email protected] Questions <[email protected]>
> > 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
separately.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.