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

[email protected] ("Jan Dubois")
Newsgroups perl.xs
Message-ID <005e01ca0b0f$e7826d60$b6874820$@com>
On Wed, 22 Jul 2009, Erland Sommarskog wrote:
> I have an issue with an XS module of mine. I lean towards that it is a
> bug in threads::shared, but maybe I am doing something wrong?
>
> To show the issue, I have this silly XS routine:
> 
>    void
>    arraytest(arrayref)
>          SV * arrayref
>    CODE:
>    {
>      AV *  av = (AV *) SvRV(arrayref);
>      SV ** svp = av_fetch(av, 0, 0);
>      SV *  sv  = *svp;

       SvGETMAGIC(sv);
 
>      warn ("SvOK = %d\n", SvOK(sv));
>      warn ("SvIV = %d\n", SvIV(sv));
>      warn ("SvOK = %d\n", SvOK(sv));
>    }
> 
 
> That is, when I send in a regular array reference, results are as
> expected. But when the reference is a shared object, SvOK first
> returns 0. When I retrieve the value with SvIV I get the correct
> value nevertheless, and next time SvOK returns a true value!
> 
> Am I doing somethinug wrong? Or should I file a bug for threads::shared?

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.

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.