XS causes error on 5.8.9, help!

Mark Fowler mark at twoshortplanks.com
Fri Jun 21 13:44:30 BST 2013


So I recently stole the guts of the Clone module, and modified it to allow it to create a copy of a data structure with all the strings in the data structure turned into the UTF-8 byte representation of the characters within it.  I released it to the CPAN as Clone::AsUTF8Bytes.

And then I got some test failures on 5.8.9 reported to me via the excellent people at CPAN Testers.  Inside the test report was:

  Attempt to free non-existent shared string 'foo', Perl interpreter: 0xe2a010.

Uh oh.  So, questions:

  a) What does this error message mean?  I *think* it means that the scalar that contains the string "foo" was attempted to be freed a second time, which is weird, because it's stored only in the original non-copied data structure after the copy takes place.  This is someone compounded by the fact that the cloned copy of the data structure is now all screwed up, as you can see by the subsequent test failure:


  b) Anyone seen this before?  Is this just a known problem with an ancient yet widely deployed version of perl (I must admit my knowledge of XS isn't great, and knowledge of XS on 5.8 even less so) or am I doing something stupid?  If it's the former, can it be (easily) fixed, or should I just bump the requirement to a working version of perl.

In the interests of those playing along at home, here's the source, failing tests, and a diff showing the changes I made on top of the original Clone code:

Source: https://github.com/2shortplanks/Clone-AsUTF8Bytes/blob/f6fa6d8cd130a80988609b17a680067022c128fa/AsUTF8Bytes.xs
Diff: https://github.com/2shortplanks/Clone-AsUTF8Bytes/commit/f6fa6d8cd130a80988609b17a680067022c128fa
Test: https://github.com/2shortplanks/Clone-AsUTF8Bytes/blob/06190ef6de970127d555e5ce3f577a9e6d821d01/t/utf8.t


Mark Fowler

More information about the london.pm mailing list