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

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.

Replies are listed 'Best First'.
Re^5: XS/Inline::C concat *any* two SVs.
by creamygoodness (Curate) on May 30, 2006 at 16:00 UTC
    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.

        All this emphasis on "*any*" yet you don't care about strings containing "\0" characters (if read-only), tied scalars, nor magic scalars. I'm also curious if SvPVX() can yield you some pointers to interesting things, not strings, for some kinds of scalars, but not enough to try to review the space of all possible scalar types.

        - tye