This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
More SvPV consting
authorNicholas Clark <nick@ccl4.org>
Tue, 7 Jun 2005 22:22:34 +0000 (22:22 +0000)
committerNicholas Clark <nick@ccl4.org>
Tue, 7 Jun 2005 22:22:34 +0000 (22:22 +0000)
p4raw-id: //depot/perl@24744

doop.c
pp.c
pp_hot.c
pp_pack.c
pp_sort.c
pp_sys.c
regexec.c
sv.c
toke.c

diff --git a/doop.c b/doop.c
index 98876d3..a5dcc68 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -97,8 +97,8 @@ S_do_trans_simple(pTHX_ SV *sv)
 STATIC I32
 S_do_trans_count(pTHX_ SV *sv)
 {
-    U8 *s;
-    U8 *send;
+    const U8 *s;
+    const U8 *send;
     I32 matches = 0;
     STRLEN len;
     const I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT;
@@ -107,7 +107,7 @@ S_do_trans_count(pTHX_ SV *sv)
     if (!tbl)
        Perl_croak(aTHX_ "panic: do_trans_count line %d",__LINE__);
 
-    s = (U8*)SvPV(sv, len);
+    s = (const U8*)SvPV_const(sv, len);
     send = s + len;
 
     if (!SvUTF8(sv))
diff --git a/pp.c b/pp.c
index d2fcbea..8c50719 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -3011,7 +3011,7 @@ PP(pp_substr)
     if (num_args > 2) {
        if (num_args > 3) {
            repl_sv = POPs;
-           repl = SvPV(repl_sv, repl_len);
+           repl = SvPV_const(repl_sv, repl_len);
            repl_is_utf8 = DO_UTF8(repl_sv) && SvCUR(repl_sv);
        }
        len = POPi;
@@ -3275,7 +3275,7 @@ PP(pp_rindex)
        /* One needs to be upgraded.  */
        SV *bytes = little_utf8 ? big : little;
        STRLEN len;
-       char *p = SvPV(bytes, len);
+       const char *p = SvPV_const(bytes, len);
 
        temp = newSVpvn(p, len);
 
@@ -3412,7 +3412,6 @@ PP(pp_crypt)
 #ifdef HAS_CRYPT
     dSP; dTARGET;
     dPOPTOPssrl;
-    STRLEN n_a;
     STRLEN len;
     const char *tmps = SvPV_const(left, len);
 
@@ -3445,9 +3444,9 @@ PP(pp_crypt)
 #     endif /* HAS_CRYPT_R */
 #   endif /* USE_ITHREADS */
 #   ifdef FCRYPT
-    sv_setpv(TARG, fcrypt(tmps, SvPV(right, n_a)));
+    sv_setpv(TARG, fcrypt(tmps, SvPV_nolen_const(right)));
 #   else
-    sv_setpv(TARG, PerlProc_crypt(tmps, SvPV(right, n_a)));
+    sv_setpv(TARG, PerlProc_crypt(tmps, SvPV_nolen_const(right)));
 #   endif
     SETs(TARG);
     RETURN;
@@ -3461,12 +3460,12 @@ PP(pp_ucfirst)
 {
     dSP;
     SV *sv = TOPs;
-    register U8 *s;
+    const U8 *s;
     STRLEN slen;
 
     SvGETMAGIC(sv);
     if (DO_UTF8(sv) &&
-       (s = (U8*)SvPV_nomg(sv, slen)) && slen &&
+       (s = (const U8*)SvPV_nomg_const(sv, slen)) && slen &&
        UTF8_IS_START(*s)) {
        U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
        STRLEN ulen;
@@ -3497,6 +3496,7 @@ PP(pp_ucfirst)
        }
     }
     else {
+       U8 *s1;
        if (!SvPADTMP(sv) || SvREADONLY(sv)) {
            dTARGET;
            SvUTF8_off(TARG);                           /* decontaminate */
@@ -3504,15 +3504,15 @@ PP(pp_ucfirst)
            sv = TARG;
            SETs(sv);
        }
-       s = (U8*)SvPV_force_nomg(sv, slen);
-       if (*s) {
+       s1 = (U8*)SvPV_force_nomg(sv, slen);
+       if (*s1) {
            if (IN_LOCALE_RUNTIME) {
                TAINT;
                SvTAINTED_on(sv);
-               *s = toUPPER_LC(*s);
+               *s1 = toUPPER_LC(*s1);
            }
            else
-               *s = toUPPER(*s);
+               *s1 = toUPPER(*s1);
        }
     }
     SvSETMAGIC(sv);
@@ -3523,12 +3523,12 @@ PP(pp_lcfirst)
 {
     dSP;
     SV *sv = TOPs;
-    register U8 *s;
+    const U8 *s;
     STRLEN slen;
 
     SvGETMAGIC(sv);
     if (DO_UTF8(sv) &&
-       (s = (U8*)SvPV_nomg(sv, slen)) && slen &&
+       (s = (const U8*)SvPV_nomg_const(sv, slen)) && slen &&
        UTF8_IS_START(*s)) {
        STRLEN ulen;
        U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
@@ -3553,6 +3553,7 @@ PP(pp_lcfirst)
        }
     }
     else {
+       U8 *s1;
        if (!SvPADTMP(sv) || SvREADONLY(sv)) {
            dTARGET;
            SvUTF8_off(TARG);                           /* decontaminate */
@@ -3560,15 +3561,15 @@ PP(pp_lcfirst)
            sv = TARG;
            SETs(sv);
        }
-       s = (U8*)SvPV_force_nomg(sv, slen);
-       if (*s) {
+       s1 = (U8*)SvPV_force_nomg(sv, slen);
+       if (*s1) {
            if (IN_LOCALE_RUNTIME) {
                TAINT;
                SvTAINTED_on(sv);
-               *s = toLOWER_LC(*s);
+               *s1 = toLOWER_LC(*s1);
            }
            else
-               *s = toLOWER(*s);
+               *s1 = toLOWER(*s1);
        }
     }
     SvSETMAGIC(sv);
@@ -4663,8 +4664,7 @@ PP(pp_split)
 
        len = rx->minlen;
        if (len == 1 && !(rx->reganch & ROPT_UTF8) && !tail) {
-           STRLEN n_a;
-           char c = *SvPV(csv, n_a);
+           char c = *SvPV_nolen_const(csv);
            while (--limit) {
                /*SUPPRESS 530*/
                for (m = s; m < strend && *m != c; m++) ;
index 0e5fa70..1572818 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1819,7 +1819,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 */
index 5c600af..b0d3b29 100644 (file)
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -3513,7 +3513,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
            /* Fall through! */
        case 'p':
            while (len-- > 0) {
-               char *aptr;
+               const char *aptr;
 
                fromstr = NEXTFROM;
                SvGETMAGIC(fromstr);
@@ -3532,7 +3532,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
                                    "Attempt to pack pointer to temporary value");
                    }
                    if (SvPOK(fromstr) || SvNIOK(fromstr))
-                       aptr = SvPV_flags(fromstr, n_a, 0);
+                       aptr = SvPV_nomg_const(fromstr, n_a);
                    else
                        aptr = SvPV_force_flags(fromstr, n_a, 0);
                }
@@ -3552,7 +3552,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
                            "Field too wide in 'u' format in pack");
                len = 63;
            }
-           aptr = SvPV(fromstr, fromlen);
+           aptr = SvPV_const(fromstr, fromlen);
            from_utf8 = DO_UTF8(fromstr);
            if (from_utf8) {
                aend = aptr + fromlen;
index 203b55d..03ab0e5 100644 (file)
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1526,8 +1526,7 @@ PP(pp_sort)
        else {
            cv = sv_2cv(*++MARK, &stash, &gv, 0);
            if (cv && SvPOK(cv)) {
-               STRLEN n_a;
-               char *proto = SvPV((SV*)cv, n_a);
+               char *proto = SvPV_nolen((SV*)cv);
                if (proto && strEQ(proto, "$$")) {
                    hasargs = TRUE;
                }
@@ -1620,11 +1619,11 @@ PP(pp_sort)
                }
                else {
                    if (!SvPOK(*p1)) {
-                       STRLEN n_a;
                        if (SvAMAGIC(*p1))
                            overloading = 1;
                        else
-                           (void)sv_2pv(*p1, &n_a);
+                           (void)sv_2pv_flags(*p1, 0,
+                                              SV_GMAGIC|SV_CONST_RETURN);
                    }
                }
            }
index 208e0ee..3c0b56a 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1817,7 +1817,7 @@ PP(pp_send)
     GV *gv;
     IO *io;
     SV *bufsv;
-    char *buffer;
+    const char *buffer;
     Size_t length;
     SSize_t retval;
     STRLEN blen;
@@ -1866,7 +1866,7 @@ PP(pp_send)
            bufsv = sv_2mortal(newSVsv(bufsv));
            buffer = sv_2pvutf8(bufsv, &blen);
        } else
-           buffer = SvPV(bufsv, blen);
+           buffer = SvPV_const(bufsv, blen);
     }
     else {
         if (DO_UTF8(bufsv)) {
@@ -1874,7 +1874,7 @@ PP(pp_send)
              bufsv = sv_2mortal(newSVsv(bufsv));
              sv_utf8_downgrade(bufsv, FALSE);
         }
-        buffer = SvPV(bufsv, blen);
+        buffer = SvPV_const(bufsv, blen);
     }
 
     if (PL_op->op_type == OP_SYSWRITE) {
@@ -1896,7 +1896,7 @@ PP(pp_send)
        if (length > blen - offset)
            length = blen - offset;
        if (DO_UTF8(bufsv)) {
-           buffer = (char*)utf8_hop((U8 *)buffer, offset);
+           buffer = (const char*)utf8_hop((const U8 *)buffer, offset);
            length = utf8_hop((U8 *)buffer, length) - (U8 *)buffer;
        }
        else {
@@ -2142,8 +2142,7 @@ PP(pp_truncate)
        }
        else {
            SV *sv = POPs;
-           char *name;
-           STRLEN n_a;
+           const char *name;
 
            if (SvTYPE(sv) == SVt_PVGV) {
                tmpgv = (GV*)sv;                /* *main::FRED for example */
@@ -2158,7 +2157,7 @@ PP(pp_truncate)
                goto do_ftruncate_io;
            }
 
-           name = SvPV(sv, n_a);
+           name = SvPV_nolen_const(sv);
            TAINT_PROPER("truncate");
 #ifdef HAS_TRUNCATE
            if (truncate(name, len) < 0)
@@ -3689,8 +3688,8 @@ PP(pp_symlink)
 #ifdef HAS_SYMLINK
     dSP; dTARGET;
     STRLEN n_a;
-    char *tmps2 = POPpx;
-    char *tmps = SvPV(TOPs, n_a);
+    const char *tmps2 = POPpconstx;
+    const char *tmps = SvPV_nolen_const(TOPs);
     TAINT_PROPER("symlink");
     SETi( symlink(tmps, tmps2) >= 0 );
     RETURN;
index fae084e..e727ba9 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -3248,7 +3248,7 @@ S_regmatch(pTHX_ regnode *prog)
                    }
                    else {
                        STRLEN len;
-                       char *t = SvPV(ret, len);
+                       const char *t = SvPV_const(ret, len);
                        PMOP pm;
                        char * const oprecomp = PL_regprecomp;
                        const I32 osize = PL_regsize;
@@ -3256,7 +3256,7 @@ S_regmatch(pTHX_ regnode *prog)
 
                        Zero(&pm, 1, PMOP);
                         if (DO_UTF8(ret)) pm.op_pmdynflags |= PMdf_DYN_UTF8;
-                       re = CALLREGCOMP(aTHX_ t, t + len, &pm);
+                       re = CALLREGCOMP(aTHX_ (char*)t, (char*)t + len, &pm);
                        if (!(SvFLAGS(ret)
                              & (SVs_TEMP | SVs_PADTMP | SVf_READONLY
                                | SVs_GMG)))
diff --git a/sv.c b/sv.c
index 55de6d7..709b99d 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -2323,7 +2323,7 @@ Perl_looks_like_number(pTHX_ SV *sv)
        len = SvCUR(sv);
     }
     else if (SvPOKp(sv))
-       sbegin = SvPV(sv, len);
+       sbegin = SvPV_const(sv, len);
     else
        return SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK);
     return grok_number(sbegin, len, NULL);
@@ -6472,17 +6472,17 @@ Handles magic and type coercion.
 void
 Perl_sv_pos_b2u(pTHX_ register SV* sv, I32* offsetp)
 {
-    U8* s;
+    const U8* s;
     STRLEN len;
 
     if (!sv)
        return;
 
-    s = (U8*)SvPV(sv, len);
+    s = (const U8*)SvPV_const(sv, len);
     if ((I32)len < *offsetp)
        Perl_croak(aTHX_ "panic: sv_pos_b2u: bad byte offset");
     else {
-       U8* send = s + *offsetp;
+       const U8* send = s + *offsetp;
        MAGIC* mg = NULL;
        STRLEN *cache = NULL;
 
@@ -6514,7 +6514,7 @@ Perl_sv_pos_b2u(pTHX_ register SV* sv, I32* offsetp)
                    STRLEN backw = cache[1] - *offsetp;
 
                    if (!(forw < 2 * backw)) {
-                       U8 *p = s + cache[1];
+                       const U8 *p = s + cache[1];
                        STRLEN ubackw = 0;
                        
                        cache[1] -= backw;
diff --git a/toke.c b/toke.c
index ddaa0aa..6db4b83 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -2289,7 +2289,7 @@ S_find_in_my_stash(pTHX_ const char *pkgname, I32 len)
     if ((gv = gv_fetchpv(pkgname, FALSE, SVt_PVCV))) {
         SV *sv;
         if (GvCV(gv) && (sv = cv_const_sv(GvCV(gv)))) {
-            pkgname = SvPV_nolen(sv);
+            pkgname = SvPV_nolen_const(sv);
         }
     }