On output try to downgrade to bytes, croak if impossible,
Jarkko Hietaniemi [Tue, 17 Oct 2000 14:11:31 +0000 (14:11 +0000)]
from Simon Cozens.  This means that outputting >255 UTF8
is impossible.  Consider this as a strong incentive to get
the I/O disciplines implemented.

p4raw-id: //depot/perl@7355

doio.c
pod/perldiag.pod
sv.c

diff --git a/doio.c b/doio.c
index 2f78bc9..52dfd6d 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1186,6 +1186,9 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
        }
        /* FALL THROUGH */
     default:
+       /* XXX Fix this when the I/O disciplines arrive. XXX */
+       if (DO_UTF8(sv))
+           sv_utf8_downgrade(sv, FALSE);
        tmps = SvPV(sv, len);
        break;
     }
index c4d2654..480ab84 100644 (file)
@@ -3822,6 +3822,10 @@ but in actual fact, you got
 
 So put in parentheses to say what you really mean.
 
+=item Wide character in %s
+
+(F) Perl met a wide character (>255) when it wasn't expecting one.
+
 =item write() on closed filehandle %s
 
 (W closed) The filehandle you're writing to got itself closed sometime
diff --git a/sv.c b/sv.c
index 21b6758..b795b29 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -2448,8 +2448,13 @@ Perl_sv_utf8_downgrade(pTHX_ register SV* sv, bool fail_ok)
         if (!utf8_to_bytes((U8*)c, &len)) {
            if (fail_ok)
                return FALSE;
-           else
-               Perl_croak(aTHX_ "big byte");
+           else {
+               if (PL_op)
+                   Perl_croak(aTHX_ "Wide character in %s",
+                              PL_op_desc[PL_op->op_type]);
+               else
+                   Perl_croak(aTHX_ "Wide character");
+           }
        }
        SvCUR(sv) = len - 1;
        SvUTF8_off(sv);