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

[email protected] ("Jan Dubois")
Newsgroups perl.xs
Message-ID <003301ca0c33$2017b350$604719f0$@com>
On Fri, 24 Jul 2009, Bolhar-Nordenkampf Ferdinand wrote:
> > 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?
> >
> > Thanks a lot for your quick answer!
> 
> If a scalar has a type of MAGIC:
> 
> (SvTYPE(sv) == SVt_PVMG) and
> 
> has the SVs_GMG flag set in its SvFLAGS field:
> 
> ((SvFLAGS(sv) & SVs_GMG)
> 
> you should invoke SvGETMAGIC. Otherwise, it isn't required.

That doesn't make much sense; you would just duplicate the SvFLAGS test.
SvGETMAGIC(sv) already expands to

    if (SvFLAGS(sv) & SVs_GMG)
        mg_get(sv);

Likewise there is no point in checking SvTYPE(sv) because only
SVs with attached magic should have the SVs_GMG set.

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.