You make quite inconsistent thing in your C subroutine, at the very first step. You either replace SV *a with a new SV or do not, based on its constant-ness. Its a hole for scalar leaks.

I make a copy of the SV*a if it is readonly because otherwise I will get Modification of a read-only value attempted at c:\test\test.pl line 24. when I attempt to append to it. Otherwise, there is no need to copy rw scalars.

What will happen if you do not do "REFCNT_inc" exactly? Will the subroutine work for non-constant scalars?

If I do not increment the refcount, I get <c>

c:\test>test billfred fred billfred Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4 at c:\test\test.pl line 32. 1fred Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4 at c:\test\test.pl line 35. 1 Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4. Attempt to free unreferenced scalar: SV 0x182445c, Perl interpreter: 0 +x2240d4.
Why not write following way: ...

Using your version, which is close to where I started, I get the following results:

c:\test>test billfred Use of uninitialized value in subroutine entry at c:\test\test.pl line + 35. fred billfred 1fred 11

Note:


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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.