This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make testing for PL_encoding into a macro
authorKarl Williamson <khw@cpan.org>
Wed, 12 Nov 2014 05:25:37 +0000 (22:25 -0700)
committerKarl Williamson <khw@cpan.org>
Fri, 21 Nov 2014 04:45:17 +0000 (21:45 -0700)
This is in preparation for making the test more complicated.

pad.c
perl.h
pp.c
pp_hot.c
pp_sys.c
regcomp.c
sv.c
toke.c

diff --git a/pad.c b/pad.c
index c9e16e5..0d37ddb 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -167,7 +167,7 @@ sv_eq_pvn_flags(pTHX_ const SV *sv, const char* pv, const STRLEN pvlen, const U3
         STRLEN cur1     = SvCUR(sv);
         const char *pv2 = pv;
         STRLEN cur2     = pvlen;
-       if (PL_encoding) {
+       if (IN_ENCODING) {
               SV* svrecode = NULL;
              if (SvUTF8(sv)) {
                   svrecode = newSVpvn(pv2, cur2);
diff --git a/perl.h b/perl.h
index 580ad6a..9056e0a 100644 (file)
--- a/perl.h
+++ b/perl.h
 #   endif
 #endif /* !NO_LOCALE && HAS_SETLOCALE */
 
+/* Are we under the encoding pragma? */
+#define IN_ENCODING UNLIKELY(PL_encoding)
+
 #include <setjmp.h>
 
 #ifdef I_SYS_PARAM
diff --git a/pp.c b/pp.c
index fc2714b..85ba951 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -809,7 +809,7 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping)
             Perl_croak_no_modify();
     }
 
-    if (PL_encoding) {
+    if (IN_ENCODING) {
        if (!SvUTF8(sv)) {
            /* XXX, here sv is utf8-ized as a side-effect!
               If encoding.pm is used properly, almost string-generating
@@ -861,7 +861,7 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, bool chomping)
                        }
                        rsptr = temp_buffer;
                    }
-                   else if (PL_encoding) {
+                   else if (IN_ENCODING) {
                        /* RS is 8 bit, encoding.pm is used.
                         * Do not recode PL_rs as a side-effect. */
                        svrecode = newSVpvn(rsptr, rslen);
@@ -3262,7 +3262,7 @@ PP(pp_index)
     little_utf8 = DO_UTF8(little);
     if (big_utf8 ^ little_utf8) {
        /* One needs to be upgraded.  */
-       if (little_utf8 && !PL_encoding) {
+       if (little_utf8 && !IN_ENCODING) {
            /* Well, maybe instead we might be able to downgrade the small
               string?  */
            char * const pv = (char*)bytes_from_utf8((U8 *)little_p, &llen,
@@ -3284,7 +3284,7 @@ PP(pp_index)
            temp = little_utf8
                ? newSVpvn(big_p, biglen) : newSVpvn(little_p, llen);
 
-           if (PL_encoding) {
+           if (IN_ENCODING) {
                sv_recode_to_utf8(temp, PL_encoding);
            } else {
                sv_utf8_upgrade(temp);
@@ -3370,7 +3370,7 @@ PP(pp_ord)
     STRLEN len;
     const U8 *s = (U8*)SvPV_const(argsv, len);
 
-    if (PL_encoding && SvPOK(argsv) && !DO_UTF8(argsv)) {
+    if (IN_ENCODING && SvPOK(argsv) && !DO_UTF8(argsv)) {
         SV * const tmpsv = sv_2mortal(newSVsv(argsv));
         s = (U8*)sv_recode_to_utf8(tmpsv, PL_encoding);
         len = UTF8SKIP(s);  /* Should be well-formed; so this is its length */
@@ -3435,7 +3435,7 @@ PP(pp_chr)
     *tmps = '\0';
     (void)SvPOK_only(TARG);
 
-    if (PL_encoding && !IN_BYTES) {
+    if (IN_ENCODING && !IN_BYTES) {
         sv_recode_to_utf8(TARG, PL_encoding);
        tmps = SvPVX(TARG);
        if (SvCUR(TARG) == 0
index 55e2c97..bf992e4 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2186,7 +2186,7 @@ PP(pp_subst)
        if (DO_UTF8(TARG) && !doutf8) {
             nsv = sv_newmortal();
             SvSetSV(nsv, dstr);
-            if (PL_encoding)
+            if (IN_ENCODING)
                  sv_recode_to_utf8(nsv, PL_encoding);
             else
                  sv_utf8_upgrade(nsv);
@@ -2367,7 +2367,7 @@ PP(pp_subst)
              first = FALSE;
            }
            else {
-               if (PL_encoding) {
+               if (IN_ENCODING) {
                    if (!nsv) nsv = sv_newmortal();
                    sv_copypv(nsv, repl);
                    if (!DO_UTF8(nsv)) sv_recode_to_utf8(nsv, PL_encoding);
index 831bf26..b371469 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1756,7 +1756,7 @@ PP(pp_sysread)
        bytes from a byte file handle into a UTF8 buffer, but it won't harm us
        unduly.
        (should be 2 * length + offset + 1, or possibly something longer if
-       PL_encoding is true) */
+       IN_ENCODING Is true) */
     buffer  = SvGROW(bufsv, (STRLEN)(length+offset+1));
     if (offset > 0 && offset > (SSize_t)orig_size) { /* Zero any newly allocated space */
        Zero(buffer+orig_size, offset-orig_size, char);
index 12c3678..787c1d1 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -12242,7 +12242,7 @@ tryagain:
                                vFAIL(error_msg);
                            }
                             ender = result;
-                           if (PL_encoding && ender < 0x100) {
+                           if (IN_ENCODING && ender < 0x100) {
                                goto recode_encoding;
                            }
                            if (ender > 0xff) {
@@ -12272,7 +12272,7 @@ tryagain:
                            }
                             ender = result;
 
-                           if (PL_encoding && ender < 0x100) {
+                           if (IN_ENCODING && ender < 0x100) {
                                goto recode_encoding;
                            }
                            if (ender > 0xff) {
@@ -12331,7 +12331,7 @@ tryagain:
                                          form_short_octal_warning(p, numlen));
                             }
                        }
-                       if (PL_encoding && ender < 0x100)
+                       if (IN_ENCODING && ender < 0x100)
                            goto recode_encoding;
                        break;
                    recode_encoding:
@@ -14147,7 +14147,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
                        vFAIL(error_msg);
                    }
                }
-               if (PL_encoding && value < 0x100) {
+               if (IN_ENCODING && value < 0x100) {
                    goto recode_encoding;
                }
                break;
@@ -14166,7 +14166,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
                        vFAIL(error_msg);
                    }
                }
-               if (PL_encoding && value < 0x100)
+               if (IN_ENCODING && value < 0x100)
                    goto recode_encoding;
                break;
            case 'c':
@@ -14198,7 +14198,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
                             (void)ReREFCNT_inc(RExC_rx_sv);
                         }
                     }
-                   if (PL_encoding && value < 0x100)
+                   if (IN_ENCODING && value < 0x100)
                        goto recode_encoding;
                    break;
                }
diff --git a/sv.c b/sv.c
index a82350f..60ca373 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3453,7 +3453,7 @@ Perl_sv_utf8_upgrade_flags_grow(pTHX_ SV *const sv, const I32 flags, STRLEN extr
         S_sv_uncow(aTHX_ sv, 0);
     }
 
-    if (PL_encoding && !(flags & SV_UTF8_NO_ENCODING)) {
+    if (IN_ENCODING && !(flags & SV_UTF8_NO_ENCODING)) {
         sv_recode_to_utf8(sv, PL_encoding);
        if (extra) SvGROW(sv, SvCUR(sv) + extra);
        return SvCUR(sv);
@@ -7744,7 +7744,7 @@ Perl_sv_eq_flags(pTHX_ SV *sv1, SV *sv2, const U32 flags)
     if (cur1 && cur2 && SvUTF8(sv1) != SvUTF8(sv2) && !IN_BYTES) {
         /* Differing utf8ness.
         * Do not UTF8size the comparands as a side-effect. */
-        if (PL_encoding) {
+        if (IN_ENCODING) {
              if (SvUTF8(sv1)) {
                   svrecode = newSVpvn(pv2, cur2);
                   sv_recode_to_utf8(svrecode, PL_encoding);
@@ -7835,7 +7835,7 @@ Perl_sv_cmp_flags(pTHX_ SV *const sv1, SV *const sv2,
         /* Differing utf8ness.
         * Do not UTF8size the comparands as a side-effect. */
        if (SvUTF8(sv1)) {
-           if (PL_encoding) {
+           if (IN_ENCODING) {
                 svrecode = newSVpvn(pv2, cur2);
                 sv_recode_to_utf8(svrecode, PL_encoding);
                 pv2 = SvPV_const(svrecode, cur2);
@@ -7847,7 +7847,7 @@ Perl_sv_cmp_flags(pTHX_ SV *const sv1, SV *const sv2,
            }
        }
        else {
-           if (PL_encoding) {
+           if (IN_ENCODING) {
                 svrecode = newSVpvn(pv1, cur1);
                 sv_recode_to_utf8(svrecode, PL_encoding);
                 pv1 = SvPV_const(svrecode, cur1);
diff --git a/toke.c b/toke.c
index b6da013..622ab49 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -3588,7 +3588,7 @@ S_scan_const(pTHX_ char *start)
                   " >= %"UVuf, (UV)SvCUR(sv), (UV)SvLEN(sv));
 
     SvPOK_on(sv);
-    if (PL_encoding && !has_utf8) {
+    if (IN_ENCODING && !has_utf8) {
        sv_recode_to_utf8(sv, PL_encoding);
        if (SvUTF8(sv))
            has_utf8 = TRUE;
@@ -6920,7 +6920,7 @@ Perl_yylex(pTHX)
                if (!IN_BYTES) {
                    if (UTF)
                        PerlIO_apply_layers(aTHX_ PL_rsfp, NULL, ":utf8");
-                   else if (PL_encoding) {
+                   else if (IN_ENCODING) {
                        SV *name;
                        dSP;
                        ENTER;
@@ -9334,7 +9334,7 @@ S_scan_heredoc(pTHX_ char *s)
     if (!IN_BYTES) {
        if (UTF && is_utf8_string((U8*)SvPVX_const(tmpstr), SvCUR(tmpstr)))
            SvUTF8_on(tmpstr);
-       else if (PL_encoding)
+       else if (IN_ENCODING)
            sv_recode_to_utf8(tmpstr, PL_encoding);
     }
     PL_lex_stuff = tmpstr;
@@ -9625,7 +9625,7 @@ S_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int re
        sv_catpvn(sv, s, termlen);
     s += termlen;
     for (;;) {
-       if (PL_encoding && !UTF && !re_reparse) {
+       if (IN_ENCODING && !UTF && !re_reparse) {
            bool cont = TRUE;
 
            while (cont) {
@@ -9843,13 +9843,13 @@ S_scan_str(pTHX_ char *start, int keep_bracketed_quoted, int keep_delims, int re
 
     /* at this point, we have successfully read the delimited string */
 
-    if (!PL_encoding || UTF || re_reparse) {
+    if (!IN_ENCODING || UTF || re_reparse) {
 
        if (keep_delims)
            sv_catpvn(sv, s, termlen);
        s += termlen;
     }
-    if (has_utf8 || (PL_encoding && !re_reparse))
+    if (has_utf8 || (IN_ENCODING && !re_reparse))
        SvUTF8_on(sv);
 
     PL_multi_end = CopLINE(PL_curcop);
@@ -10519,7 +10519,7 @@ S_scan_formline(pTHX_ char *s)
        if (!IN_BYTES) {
            if (UTF && is_utf8_string((U8*)SvPVX_const(stuff), SvCUR(stuff)))
                SvUTF8_on(stuff);
-           else if (PL_encoding)
+           else if (IN_ENCODING)
                sv_recode_to_utf8(stuff, PL_encoding);
        }
        NEXTVAL_NEXTTOKE.opval = (OP*)newSVOP(OP_CONST, 0, stuff);