This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mro.c: Correct utf8 and bytes concatenation
authorFather Chrysostomos <sprout@cpan.org>
Thu, 29 Sep 2011 15:48:38 +0000 (08:48 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 6 Oct 2011 20:01:10 +0000 (13:01 -0700)
commitc682ebef862f40c7b7ed8a6175ecb457b9981787
tree1fd18653eeb152b22027bdae16c29d35e89022d0
parent204e6232679d0d412347fddd9e5bd0e529da73d5
mro.c: Correct utf8 and bytes concatenation

The previous commit introduced some code that concatenates a pv on to
an sv and then does SvUTF8_on on the sv if the pv was utf8.

That can’t work if the sv was in Latin-1 (or single-byte) encoding
and contained extra-ASCII characters.  Nor can it work if bytes are
appended to a utf8 sv.  Both produce mangled utf8.

There is apparently no function apart from sv_catsv that handle
this.  So I’ve modified sv_catpvn_flags to handle this if passed the
SV_CATUTF8 (concatenating a utf8 pv) or SV_CATBYTES (cancatenating a
byte pv) flag.

This avoids the overhead of creating a new sv (in fact, sv_catsv
even copies its rhs in some cases, so that would mean creating two
new svs).  It might even be worthwhile to redefine sv_catsv in terms
of this....
ext/XS-APItest/APItest.xs
ext/XS-APItest/t/hash.t
mro.c
sv.c
sv.h
utf8.c