From: Nick Ing-Simmons Date: Wed, 4 Dec 2002 10:33:38 +0000 (+0000) Subject: Integrate mainline X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3e4a31ba50c4f768e53207843155793ca70b3ba1;p=p5sagit%2Fp5-mst-13.2.git Integrate mainline p4raw-id: //depot/perlio@18245 --- 3e4a31ba50c4f768e53207843155793ca70b3ba1 diff --cc ext/Encode/Encode.xs index d9e33bf,4d30914..d125cd0 --- a/ext/Encode/Encode.xs +++ b/ext/Encode/Encode.xs @@@ -238,13 -238,13 +238,13 @@@ encode_method(pTHX_ encode_t * enc, enc return dst; } -MODULE = Encode PACKAGE = Encode::utf8 PREFIX = Method_ +MODULE = Encode PACKAGE = Encode::utf8 PREFIX = Method_ void - Method_decode(obj,src,check = 0) - SV * obj - SV * src - int check + Method_decode_xs(obj,src,check = 0) + SV * obj + SV * src + int check CODE: { STRLEN slen; @@@ -330,26 -330,26 +330,26 @@@ CODE STRLEN slen; U8 *s = (U8 *) SvPV(src, slen); U8 *e = (U8 *) SvEND(src); - SV *dst = newSV(slen); + SV *dst = newSV(slen>0?slen:1); /* newSV() abhors 0 -- inaba */ if (SvUTF8(src)) { - /* Already encoded - trust it and just copy the octets */ - sv_setpvn(dst,(char *)s,(e-s)); + /* Already encoded - trust it and just copy the octets */ + sv_setpvn(dst,(char *)s,(e-s)); s = e; } else { - /* Native bytes - can always encode */ - U8 *d = (U8 *) SvGROW(dst,2*slen+1); - while (s < e) { - UV uv = NATIVE_TO_UNI((UV) *s++); - if (UNI_IS_INVARIANT(uv)) - *d++ = (U8)UTF_TO_NATIVE(uv); - else { - *d++ = (U8)UTF8_EIGHT_BIT_HI(uv); - *d++ = (U8)UTF8_EIGHT_BIT_LO(uv); - } + /* Native bytes - can always encode */ + U8 *d = (U8 *) SvGROW(dst, 2*slen+1); /* +1 or assertion will botch */ + while (s < e) { + UV uv = NATIVE_TO_UNI((UV) *s++); + if (UNI_IS_INVARIANT(uv)) + *d++ = (U8)UTF_TO_NATIVE(uv); + else { + *d++ = (U8)UTF8_EIGHT_BIT_HI(uv); + *d++ = (U8)UTF8_EIGHT_BIT_LO(uv); + } } - SvCUR_set(dst, d- (U8 *)SvPVX(dst)); - *SvEND(dst) = '\0'; + SvCUR_set(dst, d- (U8 *)SvPVX(dst)); + *SvEND(dst) = '\0'; } /* Clear out translated part of source unless asked not to */