Add sv_force_normal() to sv_utf8_downgrade() as suggested
Jarkko Hietaniemi [Mon, 22 Jan 2001 15:37:17 +0000 (15:37 +0000)]
by Inaba Hiroto.

p4raw-id: //depot/perl@8517

sv.c

diff --git a/sv.c b/sv.c
index 0d1bc6c..93188df 100644 (file)
--- 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 {