in reply to Re: XS/Inline::C concat *any* two SVs.
in thread XS/Inline::C concat *any* two SVs.

Use SvOK(sv) to test for undef-ness -- then you can skip all those other tests.

Unfortunately,

if( !SvOK( sv ) )

is not equivalent to

if( !SvPOK( sv ) && ( SvNOK( sv ) || SvIOK( sv ) || SvUOK( sv ) ) +)

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: XS/Inline::C concat *any* two SVs.
by creamygoodness (Curate) on May 30, 2006 at 14:06 UTC

    It's not equivalent, but it does what you want it to do, doesn't it? You want to stringify the SV under all circumstances, but you don't want to see any undef warnings. SvOK tests for undef-ness. Check SvOK, and if the scalar is not defined, set its PV to an empty string. Doesn't that work?

    --
    Marvin Humphrey
    Rectangular Research ― http://www.rectangular.com

      Unfortunately not. If I substitute SvOK( sv ) for my more complex test, then I get this output from my testcases:

      c:\test>test billfred Use of uninitialized value in subroutine entry at c:\test\test.pl line + 30. fred billfred fred fred1

      Compare that with the output from the original

      c:\test>test billfred fred billfred 1fred 1fred1

      The problem is that it detects that (N|I|U)OK is true, but it doesn't cause the PV to be set to reflect their contents. So, when you call sv_catsv the value in the NV|IV|UV gets discarded. Or at least that's my best interpretation of what I am seeing.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        You're getting the undef warning via the SvPV_nolen macro. If you change that to use sv_setpvn you won't get that anymore. This...
        if (!SvOK(sv)) sv_setpvn(sv, "", 0);

        ... is the XS equivalent of this...

        $sv = "" unless defined $sv;
        --
        Marvin Humphrey
        Rectangular Research ― http://www.rectangular.com