RE: Am I checking for undef in the wrong way?

[email protected] ("Jan Dubois")
Newsgroups perl.xs
Message-ID <00d801ca0be5$400ab3e0$c0201ba0$@com>
On Thu, 23 Jul 2009, Erland Sommarskog wrote:
> 
> "Jan Dubois" ([email protected]) writes:
> > This can happen with other magical SVs too.  You must call SvGETMAGIC()
> > before you can trust the SVf_?OK flags.  SvIV() will do this as a side
> > effect.
> 
> Thus, in any place where I receive a value of which I don't know the
> origin, I should call SvGETMAGIC first. I could then just as well
> have
> 
>   BOOL sv_isdefined(SV *sv) {
>      SvGETMAGIC(sv);
>      return SvOK(sv);
>   }
>
>
> Or would this lead in my new problems?

You should pass in the Perl context so it works under MULTIPLICITY (and
by extension under USE_ITHREADS):


    #define sv_isdefined(sv) my_is_defined(aTHX_ sv)

    static BOOL
    my_sv_isdefined(pTHX_ SV *sv) {
        ...
    }

Drop the "static" and move the #define into a header file if you need to
call it from more than one source file.

Cheers,
-Jan
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.