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

Why, given that SV *a is created in the Perl code and is not going out of scope, do I have to increment the ref count when I return it to Perl

Not sure how to answer that question either ... hope the following helps:
use warnings; use Inline C => Config => CLEAN_AFTER_BUILD => 0, BUILD_NOISY => 1; use Inline C => <<'EOC'; SV * foo1(SV * a) { SV * c = newSVsv(a); return c; } SV * foo2(SV * a) { return SvREFCNT_inc(a); } EOC $x = 'hello'; print foo1($x); print foo1(" world\n"); print foo2($x); print foo2(" world\n"); __END__ D:\pscrpt\inline>perl try.pl hello world hello world

Cheers,
Rob

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

    This still doesn't answer the question as to why foo2() receives as pre-existing scalar makes no changes to it and returns it to the caller, and suddenly we have an unreferenced scalar message.

    Which scalar suddenly becomes mortal just by virtue of being passed into a subroutine and returned? As there is only one scalar involved in foo2(), it can only be SV *a, but that brings me back to the question of why?


    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.
      first of all, get rid of following concept:
      SV* test( SV *a, SV *b ) { if( SvREADONLY( a ) ) // Readonly? Take a copy. a = newSVpv( SvPVX( a ), 0 );
      What do you do here? Under some conditions you will creat new SV under other equivalent conditions it will not. What code below that should think of a - should it free it or not (in terms of refcounting - should it rely refcnt inc or not?)

      Hence your uncertainity on whether refcount it.