This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / toke.c
diff --git a/toke.c b/toke.c
index d33d1ff..74acca1 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -27,6 +27,7 @@
 #define yylval PL_yylval
 
 static const char ident_too_long[] = "Identifier too long";
+static const char commaless_variable_list[] = "comma-less variable list";
 
 static void restore_rsfp(pTHX_ void *f);
 #ifndef PERL_NO_UTF16_FILTER
@@ -293,7 +294,7 @@ S_tokereport(pTHX_ I32 rv)
        const char *name = NULL;
        enum token_type type = TOKENTYPE_NONE;
        const struct debug_tokens *p;
-       SV* const report = newSVpvn("<== ", 4);
+       SV* const report = newSVpvs("<== ");
 
        for (p = debug_tokens; p->token; p++) {
            if (p->token == (int)rv) {
@@ -307,7 +308,7 @@ S_tokereport(pTHX_ I32 rv)
        else if ((char)rv > ' ' && (char)rv < '~')
            Perl_sv_catpvf(aTHX_ report, "'%c'", (char)rv);
        else if (!rv)
-           Perl_sv_catpvf(aTHX_ report, "EOF");
+           sv_catpvs(report, "EOF");
        else
            Perl_sv_catpvf(aTHX_ report, "?? %"IVdf, (IV)rv);
        switch (type) {
@@ -335,7 +336,7 @@ S_tokereport(pTHX_ I32 rv)
 
            }
            else
-               Perl_sv_catpv(aTHX_ report, "(opval=null)");
+               sv_catpvs(report, "(opval=null)");
            break;
        }
         PerlIO_printf(Perl_debug_log, "### %s\n\n", SvPV_nolen_const(report));
@@ -349,7 +350,7 @@ S_tokereport(pTHX_ I32 rv)
 STATIC void
 S_printbuf(pTHX_ const char* fmt, const char* s)
 {
-    SV* const tmp = newSVpvn("", 0);
+    SV* const tmp = newSVpvs("");
     PerlIO_printf(Perl_debug_log, fmt,
                  pv_display(tmp, (char *)s, strlen(s), 0, 60));
     SvREFCNT_dec(tmp);
@@ -491,17 +492,6 @@ Perl_deprecate_old(pTHX_ char *s)
 }
 
 /*
- * depcom
- * Deprecate a comma-less variable list.
- */
-
-STATIC void
-S_depcom(pTHX)
-{
-    deprecate_old("comma-less variable list");
-}
-
-/*
  * experimental text filters for win32 carriage-returns, utf16-to-utf8 and
  * utf16-to-utf8-reversed.
  */
@@ -608,7 +598,7 @@ Perl_lex_start(pTHX_ SV *line)
     if (!len || s[len-1] != ';') {
        if (!(SvFLAGS(PL_linestr) & SVs_TEMP))
            PL_linestr = sv_2mortal(newSVsv(PL_linestr));
-       sv_catpvn(PL_linestr, "\n;", 2);
+       sv_catpvs(PL_linestr, "\n;");
     }
     SvTEMP_off(PL_linestr);
     PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = SvPVX(PL_linestr);
@@ -834,13 +824,13 @@ S_skipspace(pTHX_ register char *s)
         * so store the line into the debugger's array of lines
         */
        if (PERLDB_LINE && PL_curstash != PL_debstash) {
-           SV * const sv = NEWSV(85,0);
+           SV * const sv = newSV(0);
 
            sv_upgrade(sv, SVt_PVMG);
            sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
             (void)SvIOK_on(sv);
             SvIV_set(sv, 0);
-           av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
+           av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
        }
     }
 }
@@ -867,6 +857,9 @@ S_check_uni(pTHX)
     for (s = PL_last_uni; isALNUM_lazy_if(s,UTF) || *s == '-'; s++) ;
     if ((t = strchr(s, '(')) && t < PL_bufptr)
        return;
+
+    /* XXX Things like this are just so nasty.  We shouldn't be modifying
+    source code, even if we realquick set it back. */
     if (ckWARN_d(WARN_AMBIGUOUS)){
        const char ch = *s;
         *s = '\0';
@@ -1284,7 +1277,7 @@ STATIC I32
 S_sublex_done(pTHX)
 {
     if (!PL_lex_starts++) {
-       SV * const sv = newSVpvn("",0);
+       SV * const sv = newSVpvs("");
        if (SvUTF8(PL_linestr))
            SvUTF8_on(sv);
        PL_expect = XOPERATOR;
@@ -1411,7 +1404,7 @@ STATIC char *
 S_scan_const(pTHX_ char *start)
 {
     register char *send = PL_bufend;           /* end of the constant */
-    SV *sv = NEWSV(93, send - start);          /* sv for the constant */
+    SV *sv = newSV(send - start);              /* sv for the constant */
     register char *s = start;                  /* start of the constant */
     register char *d = SvPVX(sv);              /* destination for copies */
     bool dorange = FALSE;                      /* are we in a translit range? */
@@ -2205,7 +2198,7 @@ Perl_filter_add(pTHX_ filter_t funcp, SV *datasv)
     if (!PL_rsfp_filters)
        PL_rsfp_filters = newAV();
     if (!datasv)
-       datasv = NEWSV(255,0);
+       datasv = newSV(0);
     (void)SvUPGRADE(datasv, SVt_PVIO);
     IoANY(datasv) = FPTR2DPTR(void *, funcp); /* stash funcp into spare field */
     IoFLAGS(datasv) |= IOf_FAKE_DIRP;
@@ -2435,7 +2428,7 @@ Perl_yylex(pTHX)
     bool bof = FALSE;
 
     DEBUG_T( {
-       SV* tmp = newSVpvn("", 0);
+       SV* tmp = newSVpvs("");
        PerlIO_printf(Perl_debug_log, "### %"IVdf":LEX_%s/X%s %s\n",
            (IV)CopLINE(PL_curcop),
            lex_state_names[PL_lex_state],
@@ -2679,21 +2672,21 @@ Perl_yylex(pTHX)
            PL_preambled = TRUE;
            sv_setpv(PL_linestr,incl_perldb());
            if (SvCUR(PL_linestr))
-               sv_catpvn(PL_linestr,";", 1);
+               sv_catpvs(PL_linestr,";");
            if (PL_preambleav){
                while(AvFILLp(PL_preambleav) >= 0) {
                    SV *tmpsv = av_shift(PL_preambleav);
                    sv_catsv(PL_linestr, tmpsv);
-                   sv_catpvn(PL_linestr, ";", 1);
+                   sv_catpvs(PL_linestr, ";");
                    sv_free(tmpsv);
                }
                sv_free((SV*)PL_preambleav);
                PL_preambleav = NULL;
            }
            if (PL_minus_n || PL_minus_p) {
-               sv_catpv(PL_linestr, "LINE: while (<>) {");
+               sv_catpvs(PL_linestr, "LINE: while (<>) {");
                if (PL_minus_l)
-                   sv_catpv(PL_linestr,"chomp;");
+                   sv_catpvs(PL_linestr,"chomp;");
                if (PL_minus_a) {
                    if (PL_minus_F) {
                        if ((*PL_splitstr == '/' || *PL_splitstr == '\''
@@ -2703,11 +2696,8 @@ Perl_yylex(pTHX)
                        else {
                            /* "q\0${splitstr}\0" is legal perl. Yes, even NUL
                               bytes can be used as quoting characters.  :-) */
-                           /* The count here deliberately includes the NUL
-                              that terminates the C string constant.  This
-                              embeds the opening NUL into the string.  */
                            const char *splits = PL_splitstr;
-                           sv_catpvn(PL_linestr, "our @F=split(q", 15);
+                           sv_catpvs(PL_linestr, "our @F=split(q\0");
                            do {
                                /* Need to \ \s  */
                                if (*splits == '\\')
@@ -2717,25 +2707,25 @@ Perl_yylex(pTHX)
                            /* This loop will embed the trailing NUL of
                               PL_linestr as the last thing it does before
                               terminating.  */
-                           sv_catpvn(PL_linestr, ");", 2);
+                           sv_catpvs(PL_linestr, ");");
                        }
                    }
                    else
-                       sv_catpv(PL_linestr,"our @F=split(' ');");
+                       sv_catpvs(PL_linestr,"our @F=split(' ');");
                }
            }
-           sv_catpvn(PL_linestr, "\n", 1);
+           sv_catpvs(PL_linestr, "\n");
            PL_oldoldbufptr = PL_oldbufptr = s = PL_linestart = SvPVX(PL_linestr);
            PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
            PL_last_lop = PL_last_uni = NULL;
            if (PERLDB_LINE && PL_curstash != PL_debstash) {
-               SV * const sv = NEWSV(85,0);
+               SV * const sv = newSV(0);
 
                sv_upgrade(sv, SVt_PVMG);
                sv_setsv(sv,PL_linestr);
                 (void)SvIOK_on(sv);
                 SvIV_set(sv, 0);
-               av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
+               av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
            }
            goto retry;
        }
@@ -2816,13 +2806,13 @@ Perl_yylex(pTHX)
        } while (PL_doextract);
        PL_oldoldbufptr = PL_oldbufptr = PL_bufptr = PL_linestart = s;
        if (PERLDB_LINE && PL_curstash != PL_debstash) {
-           SV * const sv = NEWSV(85,0);
+           SV * const sv = newSV(0);
 
            sv_upgrade(sv, SVt_PVMG);
            sv_setsv(sv,PL_linestr);
             (void)SvIOK_on(sv);
             SvIV_set(sv, 0);
-           av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
+           av_store(CopFILEAVx(PL_curcop),(I32)CopLINE(PL_curcop),sv);
        }
        PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
        PL_last_lop = PL_last_uni = NULL;
@@ -2862,8 +2852,8 @@ Perl_yylex(pTHX)
                     * at least, set argv[0] to the basename of the Perl
                     * interpreter. So, having found "#!", we'll set it right.
                     */
-                   SV * const x
-                       = GvSV(gv_fetchpv("\030", GV_ADD, SVt_PV)); /* $^X */
+                   SV * const x = GvSV(gv_fetchpvs("\030", GV_ADD|GV_NOTQUAL,
+                                                   SVt_PV)); /* $^X */
                    assert(SvPOK(x) || SvGMAGICAL(x));
                    if (sv_eq(x, CopFILESV(PL_curcop))) {
                        sv_setpvn(x, ipath, ipathend - ipath);
@@ -2960,15 +2950,15 @@ Perl_yylex(pTHX)
                }
 #endif
                if (d) {
-                   const U32 oldpdb = PL_perldb;
-                   const bool oldn = PL_minus_n;
-                   const bool oldp = PL_minus_p;
-
                    while (*d && !isSPACE(*d)) d++;
                    while (SPACE_OR_TAB(*d)) d++;
 
                    if (*d++ == '-') {
                        const bool switches_done = PL_doswitches;
+                       const U32 oldpdb = PL_perldb;
+                       const bool oldn = PL_minus_n;
+                       const bool oldp = PL_minus_p;
+
                        do {
                            if (*d == 'M' || *d == 'm') {
                                const char * const m = d;
@@ -3095,7 +3085,7 @@ Perl_yylex(pTHX)
            case 'T': ftst = OP_FTTEXT;         break;
            case 'B': ftst = OP_FTBINARY;       break;
            case 'M': case 'A': case 'C':
-               gv_fetchpv("\024",GV_ADD, SVt_PV);
+               gv_fetchpvs("\024", GV_ADD|GV_NOTQUAL, SVt_PV);
                switch (tmp) {
                case 'M': ftst = OP_FTMTIME;    break;
                case 'A': ftst = OP_FTATIME;    break;
@@ -3716,7 +3706,7 @@ Perl_yylex(pTHX)
        if (PL_expect == XOPERATOR) {
            if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
                PL_expect = XTERM;
-               depcom();
+               deprecate_old((char *)commaless_variable_list);
                return REPORT(','); /* grandfather non-comma-format format */
            }
        }
@@ -3774,7 +3764,7 @@ Perl_yylex(pTHX)
                                t++;
                            Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
                                        "Multidimensional syntax %.*s not supported",
-                                       (t - PL_bufptr) + 1, PL_bufptr);
+                                   (int)((t - PL_bufptr) + 1), PL_bufptr);
                        }
                    }
                }
@@ -3874,7 +3864,8 @@ Perl_yylex(pTHX)
                        PL_bufptr = skipspace(PL_bufptr);
                        Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
                            "Scalar value %.*s better written as $%.*s",
-                           t-PL_bufptr, PL_bufptr, t-PL_bufptr-1, PL_bufptr+1);
+                           (int)(t-PL_bufptr), PL_bufptr,
+                           (int)(t-PL_bufptr-1), PL_bufptr+1);
                    }
                }
            }
@@ -3945,7 +3936,7 @@ Perl_yylex(pTHX)
        if (PL_expect == XOPERATOR) {
            if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
                PL_expect = XTERM;
-               depcom();
+               deprecate_old((char *)commaless_variable_list);
                return REPORT(','); /* grandfather non-comma-format format */
            }
            else
@@ -3962,7 +3953,7 @@ Perl_yylex(pTHX)
        if (PL_expect == XOPERATOR) {
            if (PL_lex_formbrack && PL_lex_brackets == PL_lex_formbrack) {
                PL_expect = XTERM;
-               depcom();
+               deprecate_old((char *)commaless_variable_list);
                return REPORT(','); /* grandfather non-comma-format format */
            }
            else
@@ -4062,8 +4053,8 @@ Perl_yylex(pTHX)
       keylookup: {
        I32 tmp;
        I32 orig_keyword = 0;
-       GV *gv = Nullgv;
-       GV **gvp = 0;
+       GV *gv = NULL;
+       GV **gvp = NULL;
 
        PL_bufptr = s;
        s = scan_word(s, PL_tokenbuf, sizeof PL_tokenbuf, FALSE, &len);
@@ -4105,8 +4096,8 @@ Perl_yylex(pTHX)
        }
 
        if (tmp < 0) {                  /* second-class keyword? */
-           GV *ogv = Nullgv;   /* override (winner) */
-           GV *hgv = Nullgv;   /* hidden (loser) */
+           GV *ogv = NULL;     /* override (winner) */
+           GV *hgv = NULL;     /* hidden (loser) */
            if (PL_expect != XOPERATOR && (*s != ':' || s[1] != ':')) {
                CV *cv;
                if ((gv = gv_fetchpv(PL_tokenbuf, 0, SVt_PVCV)) &&
@@ -4132,7 +4123,7 @@ Perl_yylex(pTHX)
            else if (gv && !gvp
                     && -tmp==KEY_lock  /* XXX generalizable kludge */
                     && GvCVu(gv)
-                    && !hv_fetch(GvHVn(PL_incgv), "Thread.pm", 9, FALSE))
+                    && !hv_fetchs(GvHVn(PL_incgv), "Thread.pm", FALSE))
            {
                tmp = 0;                /* any sub overrides "weak" keyword */
            }
@@ -4164,6 +4155,7 @@ Perl_yylex(pTHX)
            just_a_word_zero_gv:
                gv = NULL;
                gvp = NULL;
+               orig_keyword = 0;
            }
          just_a_word: {
                SV *sv;
@@ -4226,7 +4218,7 @@ Perl_yylex(pTHX)
                /* if we saw a global override before, get the right name */
 
                if (gvp) {
-                   sv = newSVpvn("CORE::GLOBAL::",14);
+                   sv = newSVpvs("CORE::GLOBAL::");
                    sv_catpv(sv,PL_tokenbuf);
                }
                else {
@@ -4585,7 +4577,8 @@ Perl_yylex(pTHX)
            PREBLOCK(CONTINUE);
 
        case KEY_chdir:
-           (void)gv_fetchpv("ENV", GV_ADD, SVt_PVHV);  /* may use HOME */
+           /* may use HOME */
+           (void)gv_fetchpvs("ENV", GV_ADD|GV_NOTQUAL, SVt_PVHV);
            UNI(OP_CHDIR);
 
        case KEY_close:
@@ -4652,7 +4645,7 @@ Perl_yylex(pTHX)
            UNI(OP_DELETE);
 
        case KEY_dbmopen:
-           gv_fetchpv("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
+           gv_fetchpvs("AnyDBM_File::ISA", GV_ADDMULTI, SVt_PVAV);
            LOP(OP_DBMOPEN,XTERM);
 
        case KEY_dbmclose:
@@ -5348,7 +5341,7 @@ Perl_yylex(pTHX)
                        sv_setpv(PL_subname, tmpbuf);
                    else {
                        sv_setsv(PL_subname,PL_curstname);
-                       sv_catpvn(PL_subname,"::",2);
+                       sv_catpvs(PL_subname,"::");
                        sv_catpvn(PL_subname,tmpbuf,len);
                    }
                    s = skipspace(d);
@@ -5545,10 +5538,11 @@ Perl_yylex(pTHX)
            char ctl_l[2];
            ctl_l[0] = toCTRL('L');
            ctl_l[1] = '\0';
-           gv_fetchpv(ctl_l, GV_ADD, SVt_PV);
+           gv_fetchpvn_flags(ctl_l, 1, GV_ADD|GV_NOTQUAL, SVt_PV);
        }
 #else
-           gv_fetchpv("\f", GV_ADD, SVt_PV);    /* Make sure $^L is defined */
+           /* Make sure $^L is defined */
+           gv_fetchpvs("\f", GV_ADD|GV_NOTQUAL, SVt_PV);
 #endif
            UNI(OP_ENTERWRITE);
 
@@ -5640,7 +5634,7 @@ S_pending_ident(pTHX)
                 /* build ops for a bareword */
                 SV * const sym
                  = newSVpv(HvNAME_get(PAD_COMPNAME_OURSTASH(tmp)), 0);
-                sv_catpvn(sym, "::", 2);
+                sv_catpvs(sym, "::");
                 sv_catpv(sym, PL_tokenbuf+1);
                 yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
                 yylval.opval->op_private = OPpCONST_ENTERED;
@@ -9118,7 +9112,7 @@ S_new_constant(pTHX_ const char *s, STRLEN len, const char *key, SV *sv, SV *pv,
 
     /* Check the eval first */
     if (!PL_in_eval && SvTRUE(ERRSV)) {
-       sv_catpv(ERRSV, "Propagated");
+       sv_catpvs(ERRSV, "Propagated");
        yyerror((char *)SvPV_nolen_const(ERRSV)); /* Duplicates the message inside eval */
        (void)POPs;
        res = SvREFCNT_inc_simple(sv);
@@ -9187,15 +9181,13 @@ S_scan_word(pTHX_ register char *s, char *dest, STRLEN destlen, int allow_packag
 STATIC char *
 S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRLEN destlen, I32 ck_uni)
 {
-    register char *d;
-    register char *e;
-    char *bracket = Nullch;
+    char *bracket = NULL;
     char funny = *s++;
+    register char *d = dest;
+    register char * const e = d + destlen + 3;    /* two-character token, ending NUL */
 
     if (isSPACE(*s))
        s = skipspace(s);
-    d = dest;
-    e = d + destlen - 3;       /* two-character token, ending NUL */
     if (isDIGIT(*s)) {
        while (isDIGIT(*s)) {
            if (d >= e)
@@ -9270,15 +9262,15 @@ S_scan_ident(pTHX_ register char *s, register const char *send, char *dest, STRL
        if (isIDFIRST_lazy_if(d,UTF)) {
            d++;
            if (UTF) {
-               e = s;
-               while ((e < send && isALNUM_lazy_if(e,UTF)) || *e == ':') {
-                   e += UTF8SKIP(e);
-                   while (e < send && UTF8_IS_CONTINUED(*e) && is_utf8_mark((U8*)e))
-                       e += UTF8SKIP(e);
+               char *end = s;
+               while ((end < send && isALNUM_lazy_if(end,UTF)) || *end == ':') {
+                   end += UTF8SKIP(end);
+                   while (end < send && UTF8_IS_CONTINUED(*end) && is_utf8_mark((U8*)end))
+                       end += UTF8SKIP(end);
                }
-               Copy(s, d, e - s, char);
-               d += e - s;
-               s = e;
+               Copy(s, d, end - s, char);
+               d += end - s;
+               s = end;
            }
            else {
                while ((isALNUM(*s) || *s == ':') && d < e)
@@ -9365,9 +9357,10 @@ S_scan_pat(pTHX_ char *start, I32 type)
 {
     PMOP *pm;
     char *s = scan_str(start,FALSE,FALSE);
+    const char * const valid_flags = (type == OP_QR) ? "iomsx" : "iogcmsx";
 
     if (!s) {
-       char * const delimiter = skipspace(start);
+       const char * const delimiter = skipspace(start);
        Perl_croak(aTHX_ *delimiter == '?'
                   ? "Search pattern not terminated or ternary operator parsed as search pattern"
                   : "Search pattern not terminated" );
@@ -9376,14 +9369,8 @@ S_scan_pat(pTHX_ char *start, I32 type)
     pm = (PMOP*)newPMOP(type, 0);
     if (PL_multi_open == '?')
        pm->op_pmflags |= PMf_ONCE;
-    if(type == OP_QR) {
-       while (*s && strchr("iomsx", *s))
-           pmflag(&pm->op_pmflags,*s++);
-    }
-    else {
-       while (*s && strchr("iogcmsx", *s))
-           pmflag(&pm->op_pmflags,*s++);
-    }
+    while (*s && strchr(valid_flags, *s))
+       pmflag(&pm->op_pmflags,*s++);
     /* issue a warning if /c is specified,but /g is not */
     if ((pm->op_pmflags & PMf_CONTINUE) && !(pm->op_pmflags & PMf_GLOBAL)
            && ckWARN(WARN_REGEXP))
@@ -9444,17 +9431,17 @@ S_scan_subst(pTHX_ char *start)
     }
 
     if (es) {
-       SV *repl;
+       SV * const repl = newSVpvs("");
+
        PL_sublex_info.super_bufptr = s;
        PL_sublex_info.super_bufend = PL_bufend;
        PL_multi_end = 0;
        pm->op_pmflags |= PMf_EVAL;
-       repl = newSVpvn("",0);
        while (es-- > 0)
            sv_catpv(repl, es ? "eval " : "do ");
-       sv_catpvn(repl, "{ ", 2);
+       sv_catpvs(repl, "{ ");
        sv_catsv(repl, PL_lex_repl);
-       sv_catpvn(repl, " };", 2);
+       sv_catpvs(repl, " }");
        SvEVALED_on(repl);
        SvREFCNT_dec(PL_lex_repl);
        PL_lex_repl = repl;
@@ -9531,7 +9518,6 @@ S_scan_heredoc(pTHX_ register char *s)
     I32 len;
     SV *tmpstr;
     char term;
-    const char newline[] = "\n";
     const char *found_newline;
     register char *d;
     register char *e;
@@ -9593,7 +9579,7 @@ S_scan_heredoc(pTHX_ register char *s)
        s = olds;
     }
 #endif
-    if ( outer || !(found_newline = ninstr(s,PL_bufend,newline,newline+1)) ) {
+    if ( outer || !(found_newline = memchr(s, '\n', PL_bufend - s)) ) {
         herewas = newSVpvn(s,PL_bufend-s);
     }
     else {
@@ -9602,7 +9588,7 @@ S_scan_heredoc(pTHX_ register char *s)
     }
     s += SvCUR(herewas);
 
-    tmpstr = NEWSV(87,79);
+    tmpstr = newSV(79);
     sv_upgrade(tmpstr, SVt_PVIV);
     if (term == '\'') {
        op_type = OP_CONST;
@@ -9618,8 +9604,8 @@ S_scan_heredoc(pTHX_ register char *s)
     PL_multi_open = PL_multi_close = '<';
     term = *PL_tokenbuf;
     if (PL_lex_inwhat == OP_SUBST && PL_in_eval && !PL_rsfp) {
-       char *bufptr = PL_sublex_info.super_bufptr;
-       char *bufend = PL_sublex_info.super_bufend;
+       char * const bufptr = PL_sublex_info.super_bufptr;
+       char * const bufend = PL_sublex_info.super_bufend;
        char * const olds = s - SvCUR(herewas);
        s = strchr(bufptr, '\n');
        if (!s)
@@ -9691,13 +9677,13 @@ S_scan_heredoc(pTHX_ register char *s)
            PL_bufend[-1] = '\n';
 #endif
        if (PERLDB_LINE && PL_curstash != PL_debstash) {
-           SV *sv = NEWSV(88,0);
+           SV * const sv = newSV(0);
 
            sv_upgrade(sv, SVt_PVMG);
            sv_setsv(sv,PL_linestr);
             (void)SvIOK_on(sv);
             SvIV_set(sv, 0);
-           av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv);
+           av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop),sv);
        }
        if (*s == term && memEQ(s,PL_tokenbuf,len)) {
            STRLEN off = PL_bufend - 1 - SvPVX_const(PL_linestr);
@@ -9749,13 +9735,12 @@ STATIC char *
 S_scan_inputsymbol(pTHX_ char *start)
 {
     register char *s = start;          /* current position in buffer */
-    register char *d;
-    const char *e;
     char *end;
     I32 len;
 
-    d = PL_tokenbuf;                   /* start of temp holding space */
-    e = PL_tokenbuf + sizeof PL_tokenbuf;      /* end of temp holding space */
+    char *d = PL_tokenbuf;                                     /* start of temp holding space */
+    const char * const e = PL_tokenbuf + sizeof PL_tokenbuf;   /* end of temp holding space */
+
     end = strchr(s, '\n');
     if (!end)
        end = PL_bufend;
@@ -9801,7 +9786,7 @@ S_scan_inputsymbol(pTHX_ char *start)
     }
     else {
        bool readline_overriden = FALSE;
-       GV *gv_readline = Nullgv;
+       GV *gv_readline;
        GV **gvp;
        /* we're in a filehandle read situation */
        d = PL_tokenbuf;
@@ -9811,10 +9796,11 @@ S_scan_inputsymbol(pTHX_ char *start)
            Copy("ARGV",d,5,char);
 
        /* Check whether readline() is overriden */
-       if (((gv_readline = gv_fetchpv("readline", 0, SVt_PVCV))
+       gv_readline = gv_fetchpvs("readline", GV_NOTQUAL, SVt_PVCV);
+       if ((gv_readline
                && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline))
                ||
-               ((gvp = (GV**)hv_fetch(PL_globalstash, "readline", 8, FALSE))
+               ((gvp = (GV**)hv_fetchs(PL_globalstash, "readline", FALSE))
                && (gv_readline = *gvp) != (GV*)&PL_sv_undef
                && GvCVu(gv_readline) && GvIMPORTED_CV(gv_readline)))
            readline_overriden = TRUE;
@@ -9830,15 +9816,15 @@ S_scan_inputsymbol(pTHX_ char *start)
            */
            if ((tmp = pad_findmy(d)) != NOT_IN_PAD) {
                if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
-                   SV *sym = sv_2mortal(
+                   SV * const sym = sv_2mortal(
                            newSVpv(HvNAME_get(PAD_COMPNAME_OURSTASH(tmp)),0));
-                   sv_catpvn(sym, "::", 2);
+                   sv_catpvs(sym, "::");
                    sv_catpv(sym, d+1);
                    d = SvPVX(sym);
                    goto intro_sym;
                }
                else {
-                   OP *o = newOP(OP_PADSV, 0);
+                   OP * const o = newOP(OP_PADSV, 0);
                    o->op_targ = tmp;
                    PL_lex_op = readline_overriden
                        ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
@@ -9874,7 +9860,7 @@ intro_sym:
        /* If it's none of the above, it must be a literal filehandle
           (<Foo::BAR> or <FOO>) so build a simple readline OP */
        else {
-           GV *gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
+           GV * const gv = gv_fetchpv(d, GV_ADD, SVt_PVIO);
            PL_lex_op = readline_overriden
                ? (OP*)newUNOP(OP_ENTERSUB, OPf_STACKED,
                        append_elem(OP_LIST,
@@ -9977,9 +9963,9 @@ S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
 
     PL_multi_close = term;
 
-    /* create a new SV to hold the contents.  87 is leak category, I'm
-       assuming.  79 is the SV's initial length.  What a random number. */
-    sv = NEWSV(87,79);
+    /* create a new SV to hold the contents.  79 is the SV's initial length.
+       What a random number. */
+    sv = newSV(79);
     sv_upgrade(sv, SVt_PVIV);
     SvIV_set(sv, termcode);
     (void)SvPOK_only(sv);              /* validate pointer */
@@ -9996,8 +9982,8 @@ S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
                int offset = s - SvPVX_const(PL_linestr);
                const bool found = sv_cat_decode(sv, PL_encoding, PL_linestr,
                                           &offset, (char*)termstr, termlen);
-               const char *ns = SvPVX_const(PL_linestr) + offset;
-               char *svlast = SvEND(sv) - 1;
+               const char * const ns = SvPVX_const(PL_linestr) + offset;
+               char * const svlast = SvEND(sv) - 1;
 
                for (; s < ns; s++) {
                    if (*s == '\n' && !PL_rsfp)
@@ -10163,13 +10149,13 @@ S_scan_str(pTHX_ char *start, int keep_quoted, int keep_delims)
 
        /* update debugger info */
        if (PERLDB_LINE && PL_curstash != PL_debstash) {
-           SV *sv = NEWSV(88,0);
+           SV * const sv = newSV(0);
 
            sv_upgrade(sv, SVt_PVMG);
            sv_setsv(sv,PL_linestr);
             (void)SvIOK_on(sv);
             SvIV_set(sv, 0);
-           av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop), sv);
+           av_store(CopFILEAVx(PL_curcop), (I32)CopLINE(PL_curcop), sv);
        }
 
        /* having changed the buffer, we must update PL_bufend */
@@ -10237,7 +10223,7 @@ Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
     NV nv;                             /* number read, as a double */
     SV *sv = NULL;                     /* place to put the converted number */
     bool floatit;                      /* boolean: int or float? */
-    const char *lastub = 0;            /* position of last underbar */
+    const char *lastub = NULL;         /* position of last underbar */
     static char const number_too_long[] = "Number too long";
 
     /* We use the first character to decide what type of number this is */
@@ -10400,7 +10386,7 @@ Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
                    Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Misplaced _ in number");
            }
 
-           sv = NEWSV(92,0);
+           sv = newSV(0);
            if (overflowed) {
                if (n > 4294967295.0 && ckWARN(WARN_PORTABLE))
                    Perl_warner(aTHX_ packWARN(WARN_PORTABLE),
@@ -10553,7 +10539,7 @@ Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
 
 
        /* make an sv from the string */
-       sv = NEWSV(92,0);
+       sv = newSV(0);
 
        /*
            We try to do an integer conversion first if no characters
@@ -10562,7 +10548,7 @@ Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
 
        if (!floatit) {
            UV uv;
-            int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
+           const int flags = grok_number (PL_tokenbuf, d - PL_tokenbuf, &uv);
 
             if (flags == IS_NUMBER_IN_UV) {
               if (uv <= IV_MAX)
@@ -10594,7 +10580,7 @@ Perl_scan_num(pTHX_ char *start, YYSTYPE* lvalp)
     /* if it starts with a v, it could be a v-string */
     case 'v':
 vstring:
-               sv = NEWSV(92,5); /* preallocate storage space */
+               sv = newSV(5); /* preallocate storage space */
                s = scan_vstring((char *)s,sv);
                DEBUG_T( { PerlIO_printf(Perl_debug_log,
                  "### Saw v-string before '%s'\n", s);
@@ -10617,7 +10603,7 @@ S_scan_formline(pTHX_ register char *s)
 {
     register char *eol;
     register char *t;
-    SV *stuff = newSVpvn("",0);
+    SV * const stuff = newSVpvs("");
     bool needargs = FALSE;
     bool eofmt = FALSE;
 
@@ -10719,7 +10705,7 @@ I32
 Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
 {
     const I32 oldsavestack_ix = PL_savestack_ix;
-    CV* outsidecv = PL_compcv;
+    CV* const outsidecv = PL_compcv;
 
     if (PL_compcv) {
        assert(SvTYPE(PL_compcv) == SVt_PVCV);
@@ -10728,7 +10714,7 @@ Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
     save_item(PL_subname);
     SAVESPTR(PL_compcv);
 
-    PL_compcv = (CV*)NEWSV(1104,0);
+    PL_compcv = (CV*)newSV(0);
     sv_upgrade((SV *)PL_compcv, is_format ? SVt_PVFM : SVt_PVCV);
     CvFLAGS(PL_compcv) |= flags;
 
@@ -10817,7 +10803,7 @@ Perl_yyerror(pTHX_ char *s)
            where = "within string";
     }
     else {
-       SV *where_sv = sv_2mortal(newSVpvn("next char ", 10));
+       SV * const where_sv = sv_2mortal(newSVpvs("next char "));
        if (yychar < 32)
            Perl_sv_catpvf(aTHX_ where_sv, "^%c", toCTRL(yychar));
        else if (isPRINT_LC(yychar))
@@ -11020,7 +11006,7 @@ vstring, as well as updating the passed in sv.
 
 Function must be called like
 
-       sv = NEWSV(92,5);
+       sv = newSV(5);
        s = scan_vstring(s,sv);
 
 The sv should already be large enough to store the vstring