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 21:16:13 +0000 (21:16 +0000)
committerNicholas Clark <nick@ccl4.org>
Tue, 7 Jun 2005 21:16:13 +0000 (21:16 +0000)
p4raw-id: //depot/perl@24743

doop.c
mg.c
perl.c
pp.c
pp_ctl.c
pp_hot.c
pp_pack.c
pp_sys.c
sv.c

diff --git a/doop.c b/doop.c
index d7ab071..98876d3 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -605,7 +605,7 @@ Perl_do_trans(pTHX_ SV *sv)
         if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL))
             Perl_croak(aTHX_ PL_no_modify);
     }
-    (void)SvPV(sv, len);
+    (void)SvPV_const(sv, len);
     if (!len)
        return 0;
     if (!(PL_op->op_private & OPpTRANS_IDENTICAL)) {
@@ -717,7 +717,7 @@ UV
 Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
 {
     STRLEN srclen, len;
-    unsigned char *s = (unsigned char *) SvPV(sv, srclen);
+    const unsigned char *s = (const unsigned char *) SvPV_const(sv, srclen);
     UV retnum = 0;
 
     if (offset < 0)
diff --git a/mg.c b/mg.c
index e161847..819b012 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -263,11 +263,11 @@ Perl_mg_length(pTHX_ SV *sv)
     }
 
     if (DO_UTF8(sv)) {
-        U8 *s = (U8*)SvPV(sv, len);
+        const U8 *s = (U8*)SvPV_const(sv, len);
         len = Perl_utf8_length(aTHX_ s, s + len);
     }
     else
-        (void)SvPV(sv, len);
+        (void)SvPV_const(sv, len);
     return len;
 }
 
diff --git a/perl.c b/perl.c
index 2364a90..b4b68dc 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -4703,7 +4703,7 @@ Perl_call_list(pTHX_ I32 oldscope, AV *paramList)
        case 0:
            call_list_body(cv);
            atsv = ERRSV;
-           (void)SvPV(atsv, len);
+           (void)SvPV_const(atsv, len);
            if (len) {
                PL_curcop = &PL_compiling;
                CopLINE_set(PL_curcop, oldline);
diff --git a/pp.c b/pp.c
index 3299076..d2fcbea 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -2421,7 +2421,7 @@ PP(pp_complement)
        register I32 anum;
        STRLEN len;
 
-       (void)SvPV_nomg(sv,len); /* force check for uninit var */
+       (void)SvPV_nomg_const(sv,len); /* force check for uninit var */
        sv_setsv_nomg(TARG, sv);
        tmps = (U8*)SvPV_force(TARG, len);
        anum = len;
@@ -3194,8 +3194,8 @@ PP(pp_index)
     SV *temp = Nullsv;
     I32 offset;
     I32 retval;
-    char *tmps;
-    char *tmps2;
+    const char *tmps;
+    const char *tmps2;
     STRLEN biglen;
     I32 arybase = PL_curcop->cop_arybase;
     int big_utf8;
@@ -3213,7 +3213,7 @@ PP(pp_index)
        /* 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);
 
@@ -3231,7 +3231,7 @@ PP(pp_index)
     }
     if (big_utf8 && offset > 0)
        sv_pos_u2b(big, &offset, 0);
-    tmps = SvPV(big, biglen);
+    tmps = SvPV_const(big, biglen);
     if (offset < 0)
        offset = 0;
     else if (offset > (I32)biglen)
@@ -3259,8 +3259,8 @@ PP(pp_rindex)
     STRLEN llen;
     I32 offset;
     I32 retval;
-    char *tmps;
-    char *tmps2;
+    const char *tmps;
+    const char *tmps2;
     I32 arybase = PL_curcop->cop_arybase;
     int big_utf8;
     int little_utf8;
@@ -3291,8 +3291,8 @@ PP(pp_rindex)
            little = temp;
        }
     }
-    tmps2 = SvPV(little, llen);
-    tmps = SvPV(big, blen);
+    tmps2 = SvPV_const(little, llen);
+    tmps = SvPV_const(big, blen);
 
     if (MAXARG < 3)
        offset = blen;
@@ -3414,7 +3414,7 @@ PP(pp_crypt)
     dPOPTOPssrl;
     STRLEN n_a;
     STRLEN len;
-    char *tmps = SvPV(left, len);
+    const char *tmps = SvPV_const(left, len);
 
     if (DO_UTF8(left)) {
          /* If Unicode, try to downgrade.
@@ -3579,7 +3579,6 @@ PP(pp_uc)
 {
     dSP;
     SV *sv = TOPs;
-    register U8 *s;
     STRLEN len;
 
     SvGETMAGIC(sv);
@@ -3587,10 +3586,11 @@ PP(pp_uc)
        dTARGET;
        STRLEN ulen;
        register U8 *d;
-       U8 *send;
+       const U8 *s;
+       const U8 *send;
        U8 tmpbuf[UTF8_MAXBYTES+1];
 
-       s = (U8*)SvPV_nomg(sv,len);
+       s = (const U8*)SvPV_nomg_const(sv,len);
        if (!len) {
            SvUTF8_off(TARG);                           /* decontaminate */
            sv_setpvn(TARG, "", 0);
@@ -3631,6 +3631,7 @@ PP(pp_uc)
        }
     }
     else {
+       U8 *s;
        if (!SvPADTMP(sv) || SvREADONLY(sv)) {
            dTARGET;
            SvUTF8_off(TARG);                           /* decontaminate */
@@ -3640,7 +3641,7 @@ PP(pp_uc)
        }
        s = (U8*)SvPV_force_nomg(sv, len);
        if (len) {
-           register U8 *send = s + len;
+           const register U8 *send = s + len;
 
            if (IN_LOCALE_RUNTIME) {
                TAINT;
@@ -3662,18 +3663,18 @@ PP(pp_lc)
 {
     dSP;
     SV *sv = TOPs;
-    register U8 *s;
     STRLEN len;
 
     SvGETMAGIC(sv);
     if (DO_UTF8(sv)) {
        dTARGET;
+       const U8 *s;
        STRLEN ulen;
        register U8 *d;
-       U8 *send;
+       const U8 *send;
        U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
 
-       s = (U8*)SvPV_nomg(sv,len);
+       s = (const U8*)SvPV_nomg_const(sv,len);
        if (!len) {
            SvUTF8_off(TARG);                           /* decontaminate */
            sv_setpvn(TARG, "", 0);
@@ -3733,6 +3734,7 @@ PP(pp_lc)
        }
     }
     else {
+       U8 *s;
        if (!SvPADTMP(sv) || SvREADONLY(sv)) {
            dTARGET;
            SvUTF8_off(TARG);                           /* decontaminate */
index 406ad23..3dd92b7 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1835,7 +1835,7 @@ PP(pp_enteriter)
                STRLEN n_a;
                cx->blk_loop.iterlval = newSVsv(sv);
                (void) SvPV_force(cx->blk_loop.iterlval,n_a);
-               (void) SvPV(right,n_a);
+               (void) SvPV_nolen_const(right);
            }
        }
        else if (PL_op->op_private & OPpITER_REVERSED) {
index 5115e03..0e5fa70 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -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);
index b3c2f07..5c600af 100644 (file)
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -2005,8 +2005,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
                        continue;
                    }
                    if (++bytes >= sizeof(UV)) {        /* promote to string */
-                       char *t;
-                       STRLEN n_a;
+                       const char *t;
 
                        sv = Perl_newSVpvf(aTHX_ "%.*"UVf, (int)TYPE_DIGITS(UV), auv);
                        while (s < strend) {
@@ -2017,7 +2016,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
                                break;
                            }
                        }
-                       t = SvPV(sv, n_a);
+                       t = SvPV_nolen_const(sv);
                        while (*t == '0')
                            t++;
                        sv_chop(sv, t);
@@ -2904,14 +2903,14 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
        }
        case 'H':
        case 'h': {
-           char *str, *end;
+           const char *str, *end;
            I32 l, field_len;
            U8 bits;
            bool utf8_source;
            U32 utf8_flags;
 
            fromstr = NEXTFROM;
-           str = SvPV(fromstr, fromlen);
+           str = SvPV_const(fromstr, fromlen);
            end = str + fromlen;
            if (DO_UTF8(fromstr)) {
                utf8_source = TRUE;
index 0a25560..208e0ee 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -3704,7 +3704,7 @@ PP(pp_readlink)
     dSP;
 #ifdef HAS_SYMLINK
     dTARGET;
-    char *tmps;
+    const char *tmps;
     char buf[MAXPATHLEN];
     int len;
     STRLEN n_a;
@@ -3712,7 +3712,7 @@ PP(pp_readlink)
 #ifndef INCOMPLETE_TAINTS
     TAINT;
 #endif
-    tmps = POPpx;
+    tmps = POPpconstx;
     len = readlink(tmps, buf, sizeof(buf) - 1);
     EXTEND(SP, 1);
     if (len < 0)
@@ -3890,7 +3890,7 @@ PP(pp_open_dir)
 #if defined(Direntry_t) && defined(HAS_READDIR)
     dSP;
     STRLEN n_a;
-    char *dirname = POPpx;
+    const char *dirname = POPpconstx;
     GV *gv = (GV*)POPs;
     register IO *io = GvIOn(gv);
 
@@ -4181,7 +4181,7 @@ PP(pp_system)
     if (PL_tainting) {
        TAINT_ENV();
        while (++MARK <= SP) {
-           (void)SvPV_nolen(*MARK);      /* stringify for taint check */
+           (void)SvPV_nolen_const(*MARK);      /* stringify for taint check */
            if (PL_tainted)
                break;
        }
@@ -4310,7 +4310,7 @@ PP(pp_exec)
     if (PL_tainting) {
        TAINT_ENV();
        while (++MARK <= SP) {
-           (void)SvPV_nolen(*MARK);      /* stringify for taint check */
+           (void)SvPV_nolen_const(*MARK);      /* stringify for taint check */
            if (PL_tainted)
                break;
        }
diff --git a/sv.c b/sv.c
index 49de923..55de6d7 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -3410,6 +3410,8 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags)
            mg_get(sv);
        if (SvPOKp(sv)) {
            *lp = SvCUR(sv);
+           if (flags & SV_MUTABLE_RETURN)
+               return SvPVX_mutable(sv);
            if (flags & SV_CONST_RETURN)
                return (char *)SvPVX_const(sv);
            return SvPVX(sv);
@@ -3651,6 +3653,8 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags)
                          PTR2UV(sv),SvPVX_const(sv)));
     if (flags & SV_CONST_RETURN)
        return (char *)SvPVX_const(sv);
+    if (flags & SV_MUTABLE_RETURN)
+       return SvPVX_mutable(sv);
     return SvPVX(sv);
 
   tokensave: