in reply to Help with XS and anonymous arrays

Either make a copy of the array that was passed to new or simply increase its reference count. Otherwise perl tries to free it, as you see. That doesn't happen if you pass a named reference because the array is still in the same scope and won't get destroyed therefor.

For example it should also work with with an anonymous reference if you store it in another lexical variable:

my @array = 1 .. 3; my $ref = [@array] Test->new($ref);

Cheers, Flo

Replies are listed 'Best First'.
Re^2: Help with XS and anonymous arrays
by Anonymous Monk on Mar 29, 2006 at 00:17 UTC
    Thanks! That did the trick. I added:
    if (SvREFCNT(avref) == 0) SvREFCNT_inc(avref);

      That's wrong as well. Don't conditionally increment the reference count. Incement it when you create a new reference to it and decrement it when you're not referencing to it anymore.

      Cheers, Flo