From: Jarkko Hietaniemi Date: Mon, 22 Jan 2001 15:37:17 +0000 (+0000) Subject: Add sv_force_normal() to sv_utf8_downgrade() as suggested X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=652088fc08273e36aaeda0e9cea8c66eb6a0bb2b;p=p5sagit%2Fp5-mst-13.2.git Add sv_force_normal() to sv_utf8_downgrade() as suggested by Inaba Hiroto. p4raw-id: //depot/perl@8517 --- diff --git a/sv.c b/sv.c index 0d1bc6c..93188df 100644 --- a/sv.c +++ b/sv.c @@ -2957,6 +2957,7 @@ Perl_sv_utf8_upgrade(pTHX_ register SV *sv) if (hibit) { STRLEN len; + if (SvREADONLY(sv) && SvFAKE(sv)) { sv_force_normal(sv); s = SvPVX(sv); @@ -2987,10 +2988,13 @@ Perl_sv_utf8_downgrade(pTHX_ register SV* sv, bool fail_ok) { if (SvPOK(sv) && SvUTF8(sv)) { if (SvCUR(sv)) { - char *c = SvPVX(sv); - STRLEN len = SvCUR(sv); + char *s; + STRLEN len; - if (!utf8_to_bytes((U8*)c, &len)) { + if (SvREADONLY(sv) && SvFAKE(sv)) + sv_force_normal(sv); + s = SvPV(sv, len); + if (!utf8_to_bytes((U8*)s, &len)) { if (fail_ok) return FALSE; else {