Integrate perlio:
Jarkko Hietaniemi [Tue, 13 Mar 2001 00:29:00 +0000 (00:29 +0000)]
[  9110]
#ifdef'ed out code for 'USE_BYTES_DOWNGRADES' case.

p4raw-link: @9110 on //depot/perlio: 03cfe0aec1e921aae8754172fe1982455c07ce69

p4raw-id: //depot/perl@9112
p4raw-integrated: from //depot/perlio@9109 'copy in' utf8.h (@9096..)
sv.c (@9110..)

sv.c
utf8.h

diff --git a/sv.c b/sv.c
index 36735ae..b96cc45 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3013,15 +3013,37 @@ Perl_sv_utf8_downgrade(pTHX_ register SV* sv, bool fail_ok)
 {
     if (SvPOK(sv) && SvUTF8(sv)) {
         if (SvCUR(sv)) {
-           char *s;
+           U8 *s;
            STRLEN len;
 
            if (SvREADONLY(sv) && SvFAKE(sv))
                sv_force_normal(sv);
-           s = SvPV(sv, len);
-           if (!utf8_to_bytes((U8*)s, &len)) {
+           s = (U8 *) SvPV(sv, len);
+           if (!utf8_to_bytes(s, &len)) {
                if (fail_ok)
                    return FALSE;
+#ifdef USE_BYTES_DOWNGRADES
+               else if (IN_BYTE) {
+                   U8 *d = s;
+                   U8 *e = (U8 *) SvEND(sv);
+                   int first = 1;
+                   while (s < e) {
+                       UV ch = utf8n_to_uvchr(s,(e-s),&len,0);
+                       if (first && ch > 255) {
+                           if (PL_op)
+                               Perl_warner(aTHX_ WARN_UTF8, "Wide character in byte %s",
+                                          PL_op_desc[PL_op->op_type]);
+                           else
+                               Perl_warner(aTHX_ WARN_UTF8, "Wide character in byte");
+                           first = 0;
+                       }
+                       *d++ = ch;
+                       s += len;
+                   }
+                   *d = '\0';
+                   len = (d - (U8 *) SvPVX(sv));
+               }
+#endif
                else {
                    if (PL_op)
                        Perl_croak(aTHX_ "Wide character in %s",
diff --git a/utf8.h b/utf8.h
index 3f17578..160e5d2 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -31,7 +31,11 @@ END_EXTERN_C
 
 /* #define IN_UTF8 (PL_curcop->op_private & HINT_UTF8) */
 #define IN_BYTE (PL_curcop->op_private & HINT_BYTE)
+#ifdef USE_BYTES_DOWNGRADES
+#define DO_UTF8(sv) (SvUTF8(sv) && !(IN_BYTE && sv_utf8_downgrade(sv,0)))
+#else
 #define DO_UTF8(sv) (SvUTF8(sv) && !IN_BYTE)
+#endif
 
 #define UTF8_ALLOW_EMPTY               0x0001
 #define UTF8_ALLOW_CONTINUATION                0x0002