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

You can't concatenate onto a readonly scalar, in either Perl or XS.
#!/usr/bin/perl use strict; use warnings; use Inline C => <<'END_C'; void readonly(SV *sv) { SvREADONLY_on(sv); } END_C my $foo = "foo"; readonly($foo); # This dies with: # "Modification of a read-only value attempted at cat_readonly.plx lin +e 16." $foo .= "bar"; # unreachable: print "$foo\n";

So, if you have to deal with the possibility that your first scalar might be readonly, you have to do $a = $a . $b or its equivalent in XS rather than $a .= $b. It might be wasteful, but it's the only way.

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

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

    If you look at the OP, you'll see that is exactly what I do.


    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.
Re^6: XS/Inline::C concat *any* two SVs.
by BrowserUk (Patriarch) on May 28, 2006 at 15:22 UTC

    If you look at the OP, you'll see that is exactly what I do. But only for readonly scalars.


    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.

      Your original post is pretty messed up, so please forgive me if I used your more recent explanation, however imprecise, as a reference instead. I'm trying to help, here.

      --
      Marvin Humphrey
      Rectangular Research ― http://www.rectangular.com
        Your original post is pretty messed up,

        In what way? 1 short paragraph, 2 questions, 10 lines of code, 5 tests and the (correct) output from those tests.

        As you'll see, your help is much appreciated, but I wonder how you can say the original post is "messed up"?


        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.