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

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
  • Comment on Re^3: XS/Inline::C concat *any* two SVs.

Replies are listed 'Best First'.
Re^4: XS/Inline::C concat *any* two SVs.
by BrowserUk (Patriarch) on May 30, 2006 at 15:25 UTC

    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

        Once again thankyou. That does greatly simplify the code and produce the desired results:

        SV* test( SV *a, SV *b ) { if( SvREADONLY( a ) ) a = newSVpv( SvPVX( a ), 0 ); else SvREFCNT_inc( a ); if( !SvOK( a ) ) sv_setpvn( a, "", 0 ); sv_catsv( a, b ); return a; } ... __END__ c:\test>test billfred fred billfred 1fred 1fred1

        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.