This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
missed one PAD_SET_CUR
[perl5.git] / pp_hot.c
index c9bfc46..6d66beb 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -58,7 +58,7 @@ PP(pp_gvsv)
     if (PL_op->op_private & OPpLVAL_INTRO)
        PUSHs(save_scalar(cGVOP_gv));
     else
-       PUSHs(GvSV(cGVOP_gv));
+       PUSHs(GvSVn(cGVOP_gv));
     RETURN;
 }
 
@@ -147,19 +147,19 @@ PP(pp_concat)
     dPOPTOPssrl;
     bool lbyte;
     STRLEN rlen;
-    const char *rpv = SvPV(right, rlen);       /* mg_get(right) happens here */
+    const char *rpv = SvPV_const(right, rlen); /* mg_get(right) happens here */
     const bool rbyte = !DO_UTF8(right);
     bool rcopied = FALSE;
 
     if (TARG == right && right != left) {
        right = sv_2mortal(newSVpvn(rpv, rlen));
-       rpv = SvPV(right, rlen);        /* no point setting UTF-8 here */
+       rpv = SvPV_const(right, rlen);  /* no point setting UTF-8 here */
        rcopied = TRUE;
     }
 
     if (TARG != left) {
         STRLEN llen;
-        const char* const lpv = SvPV(left, llen);      /* mg_get(left) may happen here */
+        const char* const lpv = SvPV_const(left, llen);        /* mg_get(left) may happen here */
        lbyte = !DO_UTF8(left);
        sv_setpvn(TARG, lpv, llen);
        if (!lbyte)
@@ -173,7 +173,7 @@ PP(pp_concat)
            mg_get(left);               /* or mg_get(left) may happen here */
        if (!SvOK(TARG))
            sv_setpvn(left, "", 0);
-       (void)SvPV_nomg(left, llen);    /* Needed to set UTF8 flag */
+       (void)SvPV_nomg_const(left, llen);    /* Needed to set UTF8 flag */
        lbyte = !DO_UTF8(left);
        if (IN_BYTES)
            SvUTF8_off(TARG);
@@ -186,7 +186,7 @@ PP(pp_concat)
            if (!rcopied)
                right = sv_2mortal(newSVpvn(rpv, rlen));
            sv_utf8_upgrade_nomg(right);
-           rpv = SvPV(right, rlen);
+           rpv = SvPV_const(right, rlen);
        }
     }
     sv_catpvn_nomg(TARG, rpv, rlen);
@@ -911,7 +911,7 @@ S_do_oddball(pTHX_ HV *hash, SV **relem, SV **firstrelem)
 {
     if (*relem) {
        SV *tmpstr;
-        HE *didstore;
+        const HE *didstore;
 
         if (ckWARN(WARN_MISC)) {
            const char *err;
@@ -971,7 +971,6 @@ PP(pp_aassign)
     if (PL_op->op_private & (OPpASSIGN_COMMON)) {
        EXTEND_MORTAL(lastrelem - firstrelem + 1);
        for (relem = firstrelem; relem <= lastrelem; relem++) {
-           /*SUPPRESS 560*/
            if ((sv = *relem)) {
                TAINT_NOT;      /* Each item is independent */
                *relem = sv_mortalcopy(sv);
@@ -1176,12 +1175,12 @@ PP(pp_match)
     dSP; dTARG;
     register PMOP *pm = cPMOP;
     PMOP *dynpm = pm;
-    register char *t;
-    register char *s;
-    char *strend;
+    const register char *t;
+    const register char *s;
+    const char *strend;
     I32 global;
     I32 r_flags = REXEC_CHECKED;
-    char *truebase;                    /* Start of string  */
+    const char *truebase;                      /* Start of string  */
     register REGEXP *rx = PM_GETRE(pm);
     bool rxtainted;
     const I32 gimme = GIMME;
@@ -1201,7 +1200,7 @@ PP(pp_match)
     }
 
     PUTBACK;                           /* EVAL blocks need stack_sp. */
-    s = SvPV(TARG, len);
+    s = SvPV_const(TARG, len);
     strend = s + len;
     if (!s)
        DIE(aTHX_ "panic: pp_match");
@@ -1263,8 +1262,9 @@ play_it_again:
     }
     if (rx->reganch & RE_USE_INTUIT &&
        DO_UTF8(TARG) == ((rx->reganch & ROPT_UTF8) != 0)) {
-       PL_bostr = truebase;
-       s = CALLREG_INTUIT_START(aTHX_ rx, TARG, s, strend, r_flags, NULL);
+       /* FIXME - can PL_bostr be made const char *?  */
+       PL_bostr = (char *)truebase;
+       s = CALLREG_INTUIT_START(aTHX_ rx, TARG, (char *)s, (char *)strend, r_flags, NULL);
 
        if (!s)
            goto nope;
@@ -1276,7 +1276,7 @@ play_it_again:
             && !SvROK(TARG))   /* Cannot trust since INTUIT cannot guess ^ */
            goto yup;
     }
-    if (CALLREGEXEC(aTHX_ rx, s, strend, truebase, minmatch, TARG, NULL, r_flags))
+    if (CALLREGEXEC(aTHX_ rx, (char*)s, (char *)strend, (char*)truebase, minmatch, TARG, NULL, r_flags))
     {
        PL_curpm = pm;
        if (dynpm->op_pmflags & PMf_ONCE)
@@ -1294,16 +1294,14 @@ play_it_again:
     if (gimme == G_ARRAY) {
        const I32 nparens = rx->nparens;
        I32 i = (global && !nparens) ? 1 : 0;
-       I32 len;
 
        SPAGAIN;                        /* EVAL blocks could move the stack. */
        EXTEND(SP, nparens + i);
        EXTEND_MORTAL(nparens + i);
        for (i = !i; i <= nparens; i++) {
            PUSHs(sv_newmortal());
-           /*SUPPRESS 560*/
            if ((rx->startp[i] != -1) && rx->endp[i] != -1 ) {
-               len = rx->endp[i] - rx->startp[i];
+               const I32 len = rx->endp[i] - rx->startp[i];
                s = rx->startp[i] + truebase;
                if (rx->endp[i] < 0 || rx->startp[i] < 0 ||
                    len < 0 || len > strend - s)
@@ -1374,7 +1372,8 @@ yup:                                      /* Confirmed by INTUIT */
     RX_MATCH_COPIED_off(rx);
     rx->subbeg = Nullch;
     if (global) {
-       rx->subbeg = truebase;
+       /* FIXME - should rx->subbeg be const char *?  */
+       rx->subbeg = (char *) truebase;
        rx->startp[0] = s - truebase;
        if (RX_MATCH_UTF8(rx)) {
            char *t = (char*)utf8_hop((U8*)s, rx->minlen);
@@ -1388,7 +1387,7 @@ yup:                                      /* Confirmed by INTUIT */
     }
     if (PL_sawampersand) {
        I32 off;
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
        if (SvIsCOW(TARG) || (SvFLAGS(TARG) & CAN_COW_MASK) == CAN_COW_FLAGS) {
            if (DEBUG_C_TEST) {
                PerlIO_printf(Perl_debug_log,
@@ -1397,14 +1396,14 @@ yup:                                    /* Confirmed by INTUIT */
                              (int)(t-truebase));
            }
            rx->saved_copy = sv_setsv_cow(rx->saved_copy, TARG);
-           rx->subbeg = SvPVX_const(rx->saved_copy) + (t - truebase);
+           rx->subbeg = (char *) SvPVX_const(rx->saved_copy) + (t - truebase);
            assert (SvPOKp(rx->saved_copy));
        } else
 #endif
        {
 
            rx->subbeg = savepvn(t, strend - t);
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
            rx->saved_copy = Nullsv;
 #endif
        }
@@ -1474,7 +1473,7 @@ Perl_do_readline(pTHX)
                    if (av_len(GvAVn(PL_last_in_gv)) < 0) {
                        IoFLAGS(io) &= ~IOf_START;
                        do_open(PL_last_in_gv,"-",1,FALSE,O_RDONLY,0,Nullfp);
-                       sv_setpvn(GvSV(PL_last_in_gv), "-", 1);
+                       sv_setpvn(GvSVn(PL_last_in_gv), "-", 1);
                        SvSETMAGIC(GvSV(PL_last_in_gv));
                        fp = IoIFP(io);
                        goto have_fp;
@@ -1519,15 +1518,14 @@ Perl_do_readline(pTHX)
        sv = TARG;
        if (SvROK(sv))
            sv_unref(sv);
-       (void)SvUPGRADE(sv, SVt_PV);
+       SvUPGRADE(sv, SVt_PV);
        tmplen = SvLEN(sv);     /* remember if already alloced */
        if (!tmplen && !SvREADONLY(sv))
            Sv_Grow(sv, 80);    /* try short-buffering it */
        offset = 0;
        if (type == OP_RCATLINE && SvOK(sv)) {
            if (!SvPOK(sv)) {
-               STRLEN n_a;
-               (void)SvPV_force(sv, n_a);
+               SvPV_force_nolen(sv);
            }
            offset = SvCUR(sv);
        }
@@ -1590,6 +1588,7 @@ Perl_do_readline(pTHX)
        XPUSHs(sv);
        if (type == OP_GLOB) {
            char *tmps;
+           const char *t1;
 
            if (SvCUR(sv) > 0 && SvCUR(PL_rs) > 0) {
                tmps = SvEND(sv) - 1;
@@ -1598,16 +1597,16 @@ Perl_do_readline(pTHX)
                    SvCUR_set(sv, SvCUR(sv) - 1);
                }
            }
-           for (tmps = SvPVX(sv); *tmps; tmps++)
-               if (!isALPHA(*tmps) && !isDIGIT(*tmps) &&
-                   strchr("$&*(){}[]'\";\\|?<>~`", *tmps))
+           for (t1 = SvPVX_const(sv); *t1; t1++)
+               if (!isALPHA(*t1) && !isDIGIT(*t1) &&
+                   strchr("$&*(){}[]'\";\\|?<>~`", *t1))
                        break;
-           if (*tmps && PerlLIO_lstat(SvPVX_const(sv), &PL_statbuf) < 0) {
+           if (*t1 && PerlLIO_lstat(SvPVX_const(sv), &PL_statbuf) < 0) {
                (void)POPs;             /* Unmatched wildcard?  Chuck it... */
                continue;
            }
        } else if (SvUTF8(sv)) { /* OP_READLINE, OP_RCATLINE */
-            const U8 *s = (U8*)SvPVX(sv) + offset;
+            const U8 *s = (const U8*)SvPVX_const(sv) + offset;
             const STRLEN len = SvCUR(sv) - offset;
             const U8 *f;
             
@@ -1666,11 +1665,7 @@ PP(pp_helem)
     const U32 lval = PL_op->op_flags & OPf_MOD || LVRET;
     const U32 defer = PL_op->op_private & OPpLVAL_DEFER;
     SV *sv;
-#ifdef PERL_COPY_ON_WRITE
-    const U32 hash = (SvIsCOW_shared_hash(keysv)) ? SvUVX(keysv) : 0;
-#else
-    const U32 hash = (SvFAKE(keysv) && SvREADONLY(keysv)) ? SvUVX(keysv) : 0;
-#endif
+    const U32 hash = (SvIsCOW_shared_hash(keysv)) ? SvSHARED_HASH(keysv) : 0;
     I32 preeminent = 0;
 
     if (SvTYPE(hv) == SVt_PVHV) {
@@ -1722,7 +1717,7 @@ PP(pp_helem)
            else {
                if (!preeminent) {
                    STRLEN keylen;
-                   const char * const key = SvPV(keysv, keylen);
+                   const char * const key = SvPV_const(keysv, keylen);
                    SAVEDELETE(hv, savepvn(key,keylen), keylen);
                } else
                    save_helem(hv, keysv, svp);
@@ -1822,7 +1817,7 @@ PP(pp_iter)
            /* string increment */
            register SV* cur = cx->blk_loop.iterlval;
            STRLEN maxlen = 0;
-           const char *max = SvOK((SV*)av) ? SvPV((SV*)av, maxlen) : "";
+           const char *max = SvOK((SV*)av) ? SvPV_const((SV*)av, maxlen) : "";
            if (!SvNIOK(cur) && SvCUR(cur) <= maxlen) {
                if (SvREFCNT(*itersvp) == 1 && !SvMAGICAL(*itersvp)) {
                    /* safe to reuse old SV */
@@ -1945,7 +1940,7 @@ PP(pp_subst)
     register char *s;
     char *strend;
     register char *m;
-    char *c;
+    const char *c;
     register char *d;
     STRLEN clen;
     I32 iters = 0;
@@ -1961,7 +1956,7 @@ PP(pp_subst)
     I32 oldsave = PL_savestack_ix;
     STRLEN slen;
     bool doutf8 = FALSE;
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
     bool is_cow;
 #endif
     SV *nsv = Nullsv;
@@ -1977,7 +1972,7 @@ PP(pp_subst)
        EXTEND(SP,1);
     }
 
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
     /* Awooga. Awooga. "bool" types that are actually char are dangerous,
        because they make integers such as 256 "false".  */
     is_cow = SvIsCOW(TARG) ? TRUE : FALSE;
@@ -1986,7 +1981,7 @@ PP(pp_subst)
        sv_force_normal_flags(TARG,0);
 #endif
     if (
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
        !is_cow &&
 #endif
        (SvREADONLY(TARG)
@@ -1995,7 +1990,7 @@ PP(pp_subst)
        DIE(aTHX_ PL_no_modify);
     PUTBACK;
 
-    s = SvPV(TARG, len);
+    s = SvPV_mutable(TARG, len);
     if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV)
        force_on_match = 1;
     rxtainted = ((pm->op_pmdynflags & PMdf_TAINTED) ||
@@ -2055,11 +2050,11 @@ PP(pp_subst)
                  sv_recode_to_utf8(nsv, PL_encoding);
             else
                  sv_utf8_upgrade(nsv);
-            c = SvPV(nsv, clen);
+            c = SvPV_const(nsv, clen);
             doutf8 = TRUE;
        }
        else {
-           c = SvPV(dstr, clen);
+           c = SvPV_const(dstr, clen);
            doutf8 = DO_UTF8(dstr);
        }
     }
@@ -2070,7 +2065,7 @@ PP(pp_subst)
     
     /* can do inplace substitution? */
     if (c
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
        && !is_cow
 #endif
        && (I32)clen <= rx->minlen && (once || !(r_flags & REXEC_COPY_STR))
@@ -2084,7 +2079,7 @@ PP(pp_subst)
            LEAVE_SCOPE(oldsave);
            RETURN;
        }
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
        if (SvIsCOW(TARG)) {
            assert (!force_on_match);
            goto have_a_cow;
@@ -2116,7 +2111,6 @@ PP(pp_subst)
                *m = '\0';
                SvCUR_set(TARG, m - s);
            }
-           /*SUPPRESS 560*/
            else if ((i = m - s)) {     /* faster from front */
                d -= clen;
                m = d;
@@ -2145,7 +2139,6 @@ PP(pp_subst)
                    DIE(aTHX_ "Substitution loop");
                rxtainted |= RX_MATCH_TAINTED(rx);
                m = rx->startp[0] + orig;
-               /*SUPPRESS 560*/
                if ((i = m - s)) {
                    if (s != d)
                        Move(s, d, i, char);
@@ -2191,7 +2184,7 @@ PP(pp_subst)
            s = SvPV_force(TARG, len);
            goto force_it;
        }
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
       have_a_cow:
 #endif
        rxtainted |= RX_MATCH_TAINTED(rx);
@@ -2202,7 +2195,7 @@ PP(pp_subst)
        if (!c) {
            register PERL_CONTEXT *cx;
            SPAGAIN;
-           ReREFCNT_inc(rx);
+           (void)ReREFCNT_inc(rx);
            PUSHSUBST(cx);
            RETURNOP(cPMOP->op_pmreplroot);
        }
@@ -2235,7 +2228,7 @@ PP(pp_subst)
        else
            sv_catpvn(dstr, s, strend - s);
 
-#ifdef PERL_COPY_ON_WRITE
+#ifdef PERL_OLD_COPY_ON_WRITE
        /* The match may make the string COW. If so, brilliant, because that's
           just saved us one malloc, copy and free - the regexp has donated
           the old buffer, and we malloc an entirely new one, rather than the
@@ -2549,7 +2542,7 @@ PP(pp_leavesublv)
 STATIC CV *
 S_get_db_sub(pTHX_ SV **svp, CV *cv)
 {
-    SV *dbsv = GvSV(PL_DBsub);
+    SV *dbsv = GvSVn(PL_DBsub);
 
     save_item(dbsv);
     if (!PERLDB_SUB_NN) {
@@ -2622,8 +2615,7 @@ PP(pp_entersub)
                sym = SvPOKp(sv) ? SvPVX_const(sv) : Nullch;
            }
            else {
-                STRLEN n_a;
-               sym = SvPV(sv, n_a);
+               sym = SvPV_nolen_const(sv);
             }
            if (!sym)
                DIE(aTHX_ PL_no_usym, "a subroutine");
@@ -2686,7 +2678,8 @@ PP(pp_entersub)
            PERL_STACK_OVERFLOW_CHECK();
            pad_push(padlist, CvDEPTH(cv));
        }
-       PAD_SET_CUR(padlist, CvDEPTH(cv));
+       SAVECOMPPAD();
+       PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv));
        if (hasargs)
        {
            AV* av;
@@ -2805,6 +2798,7 @@ PP(pp_entersub)
        return NORMAL;
     }
 
+    /*NOTREACHED*/
     assert (0); /* Cannot get here.  */
     /* This is deliberately moved here as spaghetti code to keep it out of the
        hot path.  */
@@ -2965,7 +2959,7 @@ PP(pp_method_named)
 {
     dSP;
     SV* sv = cSVOP_sv;
-    U32 hash = SvUVX(sv);
+    U32 hash = SvSHARED_HASH(sv);
 
     XPUSHs(method_common(sv, &hash));
     RETURN;
@@ -2982,7 +2976,7 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
     const char* packname = 0;
     SV *packsv = Nullsv;
     STRLEN packlen;
-    const char *name = SvPV(meth, namelen);
+    const char *name = SvPV_const(meth, namelen);
 
     sv = *(PL_stack_base + TOPMARK + 1);
 
@@ -2999,9 +2993,8 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
        /* this isn't a reference */
        packname = Nullch;
 
-        if(SvOK(sv) && (packname = SvPV(sv, packlen))) {
-          HE* he;
-         he = hv_fetch_ent(PL_stashcache, sv, 0, 0);
+        if(SvOK(sv) && (packname = SvPV_const(sv, packlen))) {
+          const HE* const he = hv_fetch_ent(PL_stashcache, sv, 0, 0);
           if (he) { 
             stash = INT2PTR(HV*,SvIV(HeVAL(he)));
             goto fetch;
@@ -3055,7 +3048,7 @@ S_method_common(pTHX_ SV* meth, U32* hashp)
 
     /* shortcut for simple names */
     if (hashp) {
-       HE* he = hv_fetch_ent(stash, meth, 0, *hashp);
+       const HE* const he = hv_fetch_ent(stash, meth, 0, *hashp);
        if (he) {
            gv = (GV*)HeVAL(he);
            if (isGV(gv) && GvCV(gv) &&