[PATCH] SvPVX_readonly() - patch #1
[email protected] (Steve Peters) Thu, 5 May 2005 06:54:17 -0500
| Newsgroups | perl.perl5.porters,perl.ponie.dev |
|---|---|
| Message-ID | <[email protected]> |
--tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline For your reading pleasure, attached is the first in a series of patches to read-only uses of SvPVX() to SvPVX_readonly(), a new macro which returns a const char * from a PV. This first patch concentrates on the core .c files and takes care of the probably 95% where a read-only is needed. Many cases where I didn't convert to SvPVX_readonly() in the pp_*.c files deserve further study, since some interesting code smells were coming from those files. Also, sv.h, one of the main users of SvPVX() was mostly untouched. My feeling is that some of the other macros using SvPVX() might need read-only versions of their own, but more study is needed. Finally, there are many opportunities to convert to SvPVX_readonly in the modules, but several of the modules have maintainers, so if you are one of them, expect some patches coming your way soon. Steve Peters [email protected] --tThc/1wpZn/ma/RB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="readonly.patch" --- doio.c.old 2005-04-21 11:05:30.000000000 -0500 +++ doio.c 2005-05-05 00:19:22.577672296 -0500 @@ -822,7 +822,7 @@ sv_catpv(sv,PL_inplace); } #ifndef FLEXFILENAMES - if ((PerlLIO_stat(SvPVX(sv),&PL_statbuf) >= 0 + if ((PerlLIO_stat(SvPVX_readonly(sv),&PL_statbuf) >= 0 && PL_statbuf.st_dev == filedev && PL_statbuf.st_ino == fileino) #ifdef DJGPP @@ -840,7 +840,7 @@ #endif #ifdef HAS_RENAME #if !defined(DOSISH) && !defined(__CYGWIN__) && !defined(EPOC) - if (PerlLIO_rename(PL_oldname,SvPVX(sv)) < 0) { + if (PerlLIO_rename(PL_oldname,SvPVX_readonly(sv)) < 0) { if (ckWARN_d(WARN_INPLACE)) Perl_warner(aTHX_ packWARN(WARN_INPLACE), "Can't rename %s to %"SVf": %s, skipping file", @@ -850,13 +850,13 @@ } #else do_close(gv,FALSE); - (void)PerlLIO_unlink(SvPVX(sv)); - (void)PerlLIO_rename(PL_oldname,SvPVX(sv)); - do_open(gv,SvPVX(sv),SvCUR(sv),PL_inplace!=0,O_RDONLY,0,Nullfp); + (void)PerlLIO_unlink(SvPVX_readonly(sv)); + (void)PerlLIO_rename(PL_oldname,SvPVX_readonly(sv)); + do_open(gv,SvPVX_readonly(sv),SvCUR(sv),PL_inplace!=0,O_RDONLY,0,Nullfp); #endif /* DOSISH */ #else - (void)UNLINK(SvPVX(sv)); - if (link(PL_oldname,SvPVX(sv)) < 0) { + (void)UNLINK(SvPVX_readonly(sv)); + if (link(PL_oldname,SvPVX_readonly(sv)) < 0) { if (ckWARN_d(WARN_INPLACE)) Perl_warner(aTHX_ packWARN(WARN_INPLACE), "Can't rename %s to %"SVf": %s, skipping file", @@ -888,7 +888,7 @@ sv_catpvn(sv,PL_oldname,oldlen); SETERRNO(0,0); /* in case sprintf set errno */ #ifdef VMS - if (!do_open(PL_argvoutgv,SvPVX(sv),SvCUR(sv),PL_inplace!=0, + if (!do_open(PL_argvoutgv,SvPVX_readonly(sv),SvCUR(sv),PL_inplace!=0, O_WRONLY|O_CREAT|O_TRUNC,0,Nullfp)) #else if (!do_open(PL_argvoutgv,SvPVX(sv),SvCUR(sv),PL_inplace!=0, @@ -1393,7 +1393,7 @@ } else { SV* sv = POPs; - char *s; + const char *s; STRLEN len; PUTBACK; if (SvTYPE(sv) == SVt_PVGV) { @@ -1408,7 +1408,7 @@ s = SvPV(sv, len); PL_statgv = Nullgv; sv_setpvn(PL_statname, s, len); - s = SvPVX(PL_statname); /* s now NUL-terminated */ + s = SvPVX_readonly(PL_statname); /* s now NUL-terminated */ PL_laststype = OP_STAT; PL_laststatval = PerlLIO_stat(s, &PL_statcache); if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(s, '\n')) @@ -2354,9 +2354,9 @@ } if ((tmpfp = PerlIO_tmpfile()) != NULL) { Stat_t st; - if (!PerlLIO_stat(SvPVX(tmpglob),&st) && S_ISDIR(st.st_mode)) - ok = ((wilddsc.dsc$a_pointer = tovmspath(SvPVX(tmpglob),vmsspec)) != NULL); - else ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL); + if (!PerlLIO_stat(SvPVX_readonly(tmpglob),&st) && S_ISDIR(st.st_mode)) + ok = ((wilddsc.dsc$a_pointer = tovmspath(SvPVX_readonly(tmpglob),vmsspec)) != NULL); + else ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX_readonly(tmpglob),vmsspec)) != NULL); if (ok) wilddsc.dsc$w_length = (unsigned short int) strlen(wilddsc.dsc$a_pointer); for (cp=wilddsc.dsc$a_pointer; ok && cp && *cp; cp++) if (*cp == '?') *cp = '%'; /* VMS style single-char wildcard */ @@ -2368,7 +2368,7 @@ *(end++) = '\n'; *end = '\0'; for (cp = rstr; *cp; cp++) *cp = _tolower(*cp); if (hasdir) { - if (isunix) trim_unixpath(rstr,SvPVX(tmpglob),1); + if (isunix) trim_unixpath(rstr,SvPVX_readonly(tmpglob),1); begin = rstr; } else { --- dump.c.old 2005-04-21 11:05:30.000000000 -0500 +++ dump.c 2005-05-05 00:19:22.577672296 -0500 @@ -83,7 +83,7 @@ SV *sv = sv_newmortal(); gv_fullname3(sv, gv, Nullch); - Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX(sv)); + Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX_readonly(sv)); if (CvXSUB(GvCV(gv))) Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n", PTR2UV(CvXSUB(GvCV(gv))), @@ -100,7 +100,7 @@ SV *sv = sv_newmortal(); gv_fullname3(sv, gv, Nullch); - Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX(sv)); + Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX_readonly(sv)); if (CvROOT(GvFORM(gv))) op_dump(CvROOT(GvFORM(gv))); else @@ -193,7 +193,7 @@ !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY| SVp_POK|SVp_NOK)) && SvCUR(sv) == 1 && - SvPVX(sv) && *SvPVX(sv) == '1' && + SvPVX_readonly(sv) && *SvPVX_readonly(sv) == '1' && SvNVX(sv) == 1.0) goto finish; } @@ -297,14 +297,14 @@ } if (SvPOKp(sv)) { - if (!SvPVX(sv)) + if (!SvPVX_readonly(sv)) sv_catpv(t, "(null)"); else { SV *tmp = newSVpvn("", 0); sv_catpv(t, "("); if (SvOOK(sv)) - Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127)); - Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127)); + Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX_readonly(sv)-SvIVX(sv), SvIVX(sv), 0, 127)); + Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX_readonly(sv), SvCUR(sv), SvLEN(sv), 127)); if (SvUTF8(sv)) Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]", sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv), @@ -387,7 +387,7 @@ sv_catpv(tmpsv, ",RETAINT"); if (pm->op_pmflags & PMf_EVAL) sv_catpv(tmpsv, ",EVAL"); - Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); + Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_readonly(tmpsv) + 1 : ""); SvREFCNT_dec(tmpsv); } @@ -583,7 +583,7 @@ sv_catpv(tmpsv, ",MOD"); if (o->op_flags & OPf_SPECIAL) sv_catpv(tmpsv, ",SPECIAL"); - Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); + Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_readonly(tmpsv) + 1 : ""); SvREFCNT_dec(tmpsv); } if (o->op_private) { @@ -753,7 +753,7 @@ if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO) sv_catpv(tmpsv, ",INTRO"); if (SvCUR(tmpsv)) - Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1); + Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_readonly(tmpsv) + 1); SvREFCNT_dec(tmpsv); } @@ -873,10 +873,10 @@ sv = sv_newmortal(); PerlIO_printf(Perl_debug_log, "{\n"); gv_fullname3(sv, gv, Nullch); - Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX(sv)); + Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_readonly(sv)); if (gv != GvEGV(gv)) { gv_efullname3(sv, GvEGV(gv), Nullch); - Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX(sv)); + Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_readonly(sv)); } PerlIO_putc(Perl_debug_log, '\n'); Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n"); @@ -1205,7 +1205,7 @@ SvPVX(d)[SvCUR(d)] = '\0'; } sv_catpv(d, ")"); - s = SvPVX(d); + s = SvPVX_readonly(d); #ifdef DEBUG_LEAKING_SCALARS Perl_dump_indent(aTHX_ level, file, "ALLOCATED at %s:%d %s %s%s\n", @@ -1310,11 +1310,11 @@ return; } if (type <= SVt_PVLV && type != SVt_PVGV) { - if (SvPVX(sv)) { - Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX(sv))); + if (SvPVX_readonly(sv)) { + Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX_readonly(sv))); if (SvOOK(sv)) - PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim)); - PerlIO_printf(file, "%s", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim)); + PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX_readonly(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim)); + PerlIO_printf(file, "%s", pv_display(d, SvPVX_readonly(sv), SvCUR(sv), SvLEN(sv), pvlim)); if (SvUTF8(sv)) /* the 8? \x{....} */ PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ)); PerlIO_printf(file, "\n"); @@ -1347,7 +1347,7 @@ if (flags & AVf_REAL) sv_catpv(d, ",REAL"); if (flags & AVf_REIFY) sv_catpv(d, ",REIFY"); if (flags & AVf_REUSED) sv_catpv(d, ",REUSED"); - Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : ""); + Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX_readonly(d) + 1 : ""); if (nest < maxnest && av_len((AV*)sv) >= 0) { int count; for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) { --- embed.fnc.old 2005-05-04 22:46:54.401123336 -0500 +++ embed.fnc 2005-05-05 00:12:11.515203752 -0500 @@ -357,7 +357,7 @@ Ap |bool |is_utf8_xdigit |const U8 *p Ap |bool |is_utf8_mark |const U8 *p p |OP* |jmaybe |OP* arg -p |I32 |keyword |char* d|I32 len +p |I32 |keyword |const char* d|I32 len Ap |void |leave_scope |I32 base p |void |lex_end p |void |lex_start |SV* line --- gv.c.old 2005-05-02 11:14:23.000000000 -0500 +++ gv.c 2005-05-05 00:19:22.577672296 -0500 @@ -108,7 +108,7 @@ dVAR; register GP *gp; const bool doproto = SvTYPE(gv) > SVt_NULL; - char *proto = (doproto && SvPOK(gv)) ? SvPVX(gv) : NULL; + const char *proto = (doproto && SvPOK(gv)) ? SvPVX_readonly(gv) : NULL; sv_upgrade((SV*)gv, SVt_PVGV); if (SvLEN(gv)) { @@ -117,7 +117,7 @@ SvLEN_set(gv, 0); SvPOK_off(gv); } else - Safefree(SvPVX(gv)); + Safefree(SvPVX_readonly(gv)); } Newz(602, gp, 1, GP); GvGP(gv) = gp_ref(gp); @@ -432,7 +432,7 @@ SV *tmpstr = sv_2mortal(Perl_newSVpvf(aTHX_ "%s::SUPER", CopSTASHPV(PL_curcop))); /* __PACKAGE__::SUPER stash should be autovivified */ - stash = gv_stashpvn(SvPVX(tmpstr), SvCUR(tmpstr), TRUE); + stash = gv_stashpvn(SvPVX_readonly(tmpstr), SvCUR(tmpstr), TRUE); DEBUG_o( Perl_deb(aTHX_ "Treating %s as %s::%s\n", origname, HvNAME(stash), name) ); } @@ -1412,12 +1412,12 @@ "' for overloaded `%s' in package `%.256s'\n", GvSV(gv), cp, HvNAME(stash)) ); if (!SvPOK(GvSV(gv)) - || !(ngv = gv_fetchmethod_autoload(stash, SvPVX(GvSV(gv)), + || !(ngv = gv_fetchmethod_autoload(stash, SvPVX_readonly(GvSV(gv)), FALSE))) { /* Can be an import stub (created by `can'). */ SV *gvsv = GvSV(gv); - const char *name = SvPOK(gvsv) ? SvPVX(gvsv) : "???"; + const char *name = SvPOK(gvsv) ? SvPVX_readonly(gvsv) : "???"; Perl_croak(aTHX_ "%s method `%.256s' overloading `%s' "\ "in package `%.256s'", (GvCVGEN(gv) ? "Stub found while resolving" @@ -1704,7 +1704,7 @@ HvNAME(SvSTASH(SvRV(right))): "")); if (amtp && amtp->fallback >= AMGfallYES) { - DEBUG_o( Perl_deb(aTHX_ "%s", SvPVX(msg)) ); + DEBUG_o( Perl_deb(aTHX_ "%s", SvPVX_readonly(msg)) ); } else { Perl_croak(aTHX_ "%"SVf, msg); } --- hv.c.old 2005-04-21 11:05:30.000000000 -0500 +++ hv.c 2005-05-05 00:19:22.577672296 -0500 @@ -176,7 +176,7 @@ SvUTF8_on(sv); } Perl_sv_setpvf(aTHX_ esv, "Attempt to %s a restricted hash", msg); - Perl_croak(aTHX_ SvPVX(esv), sv); + Perl_croak(aTHX_ SvPVX_readonly(esv), sv); } /* (klen == HEf_SVKEY) is special for MAGICAL hv entries, meaning key slot @@ -934,7 +934,7 @@ if (k_flags & HVhek_FREEKEY) { Safefree(key); } - key = strupr(SvPVX(keysv)); + key = strupr(SvPVX_readonly(keysv)); is_utf8 = 0; k_flags = 0; hash = 0; --- op.c.old 2005-04-21 11:05:30.000000000 -0500 +++ op.c 2005-05-05 00:19:22.577672296 -0500 @@ -782,9 +782,9 @@ built upon these three nroff macros being used in void context. The pink camel has the details in the script wrapman near page 319. */ - if (strnEQ(SvPVX(sv), "di", 2) || - strnEQ(SvPVX(sv), "ds", 2) || - strnEQ(SvPVX(sv), "ig", 2)) + if (strnEQ(SvPVX_readonly(sv), "di", 2) || + strnEQ(SvPVX_readonly(sv), "ds", 2) || + strnEQ(SvPVX_readonly(sv), "ig", 2)) useless = 0; } } @@ -1604,7 +1604,7 @@ (void)SvIOK_on(meth); { U32 hash; - PERL_HASH(hash, SvPVX(meth), SvCUR(meth)); + PERL_HASH(hash, SvPVX_readonly(meth), SvCUR(meth)); SvUV_set(meth, hash); } imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL|OPf_WANT_VOID, @@ -2495,7 +2495,7 @@ t = uvuni_to_utf8_flags(tmpbuf, 0x7fffffff, UNICODE_ALLOW_SUPER); sv_catpvn(transv, (char*)tmpbuf, t - tmpbuf); - t = (U8*)SvPVX(transv); + t = (U8*)SvPVX_readonly(transv); tlen = SvCUR(transv); tend = t + tlen; Safefree(cp); @@ -3038,7 +3038,7 @@ (void)SvIOK_on(meth); { U32 hash; - PERL_HASH(hash, SvPVX(meth), SvCUR(meth)); + PERL_HASH(hash, SvPVX_readonly(meth), SvCUR(meth)); SvUV_set(meth, hash); } veop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL, @@ -3066,7 +3066,7 @@ (void)SvIOK_on(meth); { U32 hash; - PERL_HASH(hash, SvPVX(meth), SvCUR(meth)); + PERL_HASH(hash, SvPVX_readonly(meth), SvCUR(meth)); SvUV_set(meth, hash); } imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL, @@ -4081,7 +4081,7 @@ void Perl_cv_ckproto(pTHX_ const CV *cv, const GV *gv, const char *p) { - if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) { + if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX_readonly(cv)))) && ckWARN_d(WARN_PROTOTYPE)) { SV* msg = sv_newmortal(); SV* name = Nullsv; @@ -4250,7 +4250,7 @@ Perl_sv_setpvf(aTHX_ sv, "%s[%s:%"IVdf"]", PL_curstash ? "__ANON__" : "__ANON__::__ANON__", CopFILE(PL_curcop), (IV)CopLINE(PL_curcop)); - aname = SvPVX(sv); + aname = SvPVX_readonly(sv); } else aname = Nullch; @@ -4500,9 +4500,9 @@ CopFILE(PL_curcop), (long)PL_subline, (long)CopLINE(PL_curcop)); gv_efullname3(tmpstr, gv, Nullch); - hv_store(GvHV(PL_DBsub), SvPVX(tmpstr), SvCUR(tmpstr), sv, 0); + hv_store(GvHV(PL_DBsub), SvPVX_readonly(tmpstr), SvCUR(tmpstr), sv, 0); hv = GvHVn(db_postponed); - if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX(tmpstr), SvCUR(tmpstr)) + if (HvFILL(hv) > 0 && hv_exists(hv, SvPVX_readonly(tmpstr), SvCUR(tmpstr)) && (pcv = GvCV(db_postponed))) { dSP; @@ -5836,10 +5836,10 @@ OP *kid = cUNOPo->op_first; if (kid->op_type == OP_CONST) { SV* sv = kSVOP->op_sv; - if (!(strchr(SvPVX(sv), ':') || strchr(SvPVX(sv), '\''))) { + if (!(strchr(SvPVX_readonly(sv), ':') || strchr(SvPVX_readonly(sv), '\''))) { OP *cmop; if (!SvREADONLY(sv) || !SvFAKE(sv)) { - sv = newSVpvn_share(SvPVX(sv), SvCUR(sv), 0); + sv = newSVpvn_share(SvPVX_readonly(sv), SvCUR(sv), 0); } else { kSVOP->op_sv = Nullsv; @@ -5891,7 +5891,7 @@ OP *first = cLISTOPx(o)->op_first; /* The pushmark. */ OP *last = cLISTOPx(o)->op_last; /* The bareword. */ OP *oa; - char *mode; + const char *mode; if ((last->op_type == OP_CONST) && /* The bareword. */ (last->op_private & OPpCONST_BARE) && @@ -5899,7 +5899,7 @@ (oa = first->op_sibling) && /* The fh. */ (oa = oa->op_sibling) && /* The mode. */ SvPOK(((SVOP*)oa)->op_sv) && - (mode = SvPVX(((SVOP*)oa)->op_sv)) && + (mode = SvPVX_readonly(((SVOP*)oa)->op_sv)) && mode[0] == '>' && mode[1] == '&' && /* A dup open. */ (last == oa->op_sibling)) /* The bareword. */ last->op_private &= ~OPpCONST_STRICT; @@ -6674,7 +6674,7 @@ } else if ((o->op_private & OPpEARLY_CV) && ckWARN(WARN_PROTOTYPE)) { GV *gv = cGVOPo_gv; - if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX(GvCV(gv))) { + if (SvTYPE(gv) == SVt_PVGV && GvCV(gv) && SvPVX_readonly(GvCV(gv))) { /* XXX could check prototype here instead of just carping */ SV *sv = sv_newmortal(); gv_efullname3(sv, gv, Nullch); --- pad.c.old 2005-05-02 11:14:23.000000000 -0500 +++ pad.c 2005-05-05 00:19:22.577672296 -0500 @@ -257,7 +257,7 @@ for (ix = AvFILLp(comppad_name); ix > 0; ix--) { SV *namesv = namepad[ix]; if (namesv && namesv != &PL_sv_undef - && *SvPVX(namesv) == '&') + && *SvPVX_readonly(namesv) == '&') { CV * const innercv = (CV*)curpad[ix]; namepad[ix] = Nullsv; @@ -514,7 +514,7 @@ && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0) && (!is_our || ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)) - && strEQ(name, SvPVX(sv))) + && strEQ(name, SvPVX_readonly(sv))) { Perl_warner(aTHX_ packWARN(WARN_MISC), "\"%s\" variable %s masks earlier declaration in same %s", @@ -533,7 +533,7 @@ && !SvFAKE(sv) && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0) && ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash) - && strEQ(name, SvPVX(sv))) + && strEQ(name, SvPVX_readonly(sv))) { Perl_warner(aTHX_ packWARN(WARN_MISC), "\"our\" variable %s redeclared", name); @@ -583,7 +583,7 @@ if (namesv && namesv != &PL_sv_undef && !SvFAKE(namesv) && (SvFLAGS(namesv) & SVpad_OUR) - && strEQ(SvPVX(namesv), name) + && strEQ(SvPVX_readonly(namesv), name) && U_32(SvNVX(namesv)) == PAD_MAX /* min */ ) return offset; @@ -666,7 +666,7 @@ for (offset = AvFILLp(nameav); offset > 0; offset--) { const SV *namesv = name_svp[offset]; if (namesv && namesv != &PL_sv_undef - && strEQ(SvPVX(namesv), name)) + && strEQ(SvPVX_readonly(namesv), name)) { if (SvFAKE(namesv)) fake_offset = offset; /* in case we don't find a real one */ @@ -813,7 +813,7 @@ PL_curpad = AvARRAY(PL_comppad); new_offset = pad_add_name( - SvPVX(*out_name_sv), + SvPVX_readonly(*out_name_sv), (SvFLAGS(*out_name_sv) & SVpad_TYPED) ? SvSTASH(*out_name_sv) : Nullhv, (SvFLAGS(*out_name_sv) & SVpad_OUR) @@ -963,7 +963,7 @@ SvNV_set(sv, (NV)PL_cop_seqmax); DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad intromy: %ld \"%s\", (%ld,%ld)\n", - (long)i, SvPVX(sv), + (long)i, SvPVX_readonly(sv), (long)U_32(SvNVX(sv)), (long)SvIVX(sv)) ); } @@ -1012,7 +1012,7 @@ SvIV_set(sv, PL_cop_seqmax); DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad leavemy: %ld \"%s\", (%ld,%ld)\n", - (long)off, SvPVX(sv), + (long)off, SvPVX_readonly(sv), (long)U_32(SvNVX(sv)), (long)SvIVX(sv)) ); } @@ -1165,7 +1165,7 @@ */ if (!((namesv = namep[ix]) != Nullsv && namesv != &PL_sv_undef && - *SvPVX(namesv) == '&')) + *SvPVX_readonly(namesv) == '&')) { SvREFCNT_dec(PL_curpad[ix]); PL_curpad[ix] = Nullsv; @@ -1286,7 +1286,7 @@ (int) ix, PTR2UV(ppad[ix]), (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0), - SvPVX(namesv), + SvPVX_readonly(namesv), (unsigned long)SvIVX(namesv), (unsigned long)SvNVX(namesv) @@ -1299,7 +1299,7 @@ (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0), (long)U_32(SvNVX(namesv)), (long)SvIVX(namesv), - SvPVX(namesv) + SvPVX_readonly(namesv) ); } else if (full) { @@ -1422,7 +1422,7 @@ CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(proto); if (SvPOK(proto)) - sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto)); + sv_setpvn((SV*)cv, SvPVX_readonly(proto), SvCUR(proto)); CvPADLIST(cv) = pad_new(padnew_CLONE|padnew_SAVE); @@ -1445,7 +1445,7 @@ if (SvTYPE(proto) == SVt_PVFM && SvPADSTALE(sv)) { if (ckWARN(WARN_CLOSURE)) Perl_warner(aTHX_ packWARN(WARN_CLOSURE), - "Variable \"%s\" is not available", SvPVX(namesv)); + "Variable \"%s\" is not available", SvPVX_readonly(namesv)); sv = Nullsv; } else { @@ -1526,7 +1526,7 @@ for (ix = AvFILLp(comppad_name); ix > 0; ix--) { const SV *namesv = namepad[ix]; if (namesv && namesv != &PL_sv_undef - && *SvPVX(namesv) == '&') + && *SvPVX_readonly(namesv) == '&') { CV *innercv = (CV*)curpad[ix]; assert(CvWEAKOUTSIDE(innercv)); --- perl.c.old 2005-05-03 04:16:06.000000000 -0500 +++ perl.c 2005-05-05 00:19:22.577672296 -0500 @@ -2575,7 +2575,7 @@ } PL_rs = newSVpvn("", 0); SvGROW(PL_rs, (STRLEN)(UNISKIP(rschar) + 1)); - tmps = (U8*)SvPVX(PL_rs); + tmps = (U8*)SvPVX_readonly(PL_rs); uvchr_to_utf8(tmps, rschar); SvCUR_set(PL_rs, UNISKIP(rschar)); SvUTF8_on(PL_rs); @@ -2994,7 +2994,7 @@ file = newSVpv(PL_origfilename, 0); sv_catpv(file, ".perldump"); - unexec(SvPVX(file), SvPVX(prog), &etext, sbrk(0), 0); + unexec(SvPVX_readonly(file), SvPVX_readonly(prog), &etext, sbrk(0), 0); /* unexec prints msg to stderr in case of failure */ PerlProc_exit(status); #else @@ -3186,7 +3186,7 @@ DEBUG_P(PerlIO_printf(Perl_debug_log, "PL_preprocess: scriptname=\"%s\", cpp=\"%s\", sv=\"%s\", CPPMINUS=\"%s\"\n", - scriptname, SvPVX (cpp), SvPVX (sv), CPPMINUS)); + scriptname, SvPVX_readonly (cpp), SvPVX_readonly (sv), CPPMINUS)); # if defined(MSDOS) || defined(WIN32) || defined(VMS) quote = "\""; @@ -3227,7 +3227,7 @@ DEBUG_P(PerlIO_printf(Perl_debug_log, "PL_preprocess: cmd=\"%s\"\n", - SvPVX(cmd))); + SvPVX_readonly(cmd))); PL_rsfp = PerlProc_popen(SvPVX(cmd), (char *)"r"); SvREFCNT_dec(cmd); @@ -4271,11 +4271,11 @@ macperl = ""; Perl_sv_setpvf(aTHX_ privdir, "%slib:", macperl); - if (PerlLIO_stat(SvPVX(privdir), &tmpstatbuf) >= 0 && S_ISDIR(tmpstatbuf.st_mode)) - incpush(SvPVX(privdir), TRUE, FALSE, TRUE, FALSE); + if (PerlLIO_stat(SvPVX_readonly(privdir), &tmpstatbuf) >= 0 && S_ISDIR(tmpstatbuf.st_mode)) + incpush(SvPVX_readonly(privdir), TRUE, FALSE, TRUE, FALSE); Perl_sv_setpvf(aTHX_ privdir, "%ssite_perl:", macperl); - if (PerlLIO_stat(SvPVX(privdir), &tmpstatbuf) >= 0 && S_ISDIR(tmpstatbuf.st_mode)) - incpush(SvPVX(privdir), TRUE, FALSE, TRUE, FALSE); + if (PerlLIO_stat(SvPVX_readonly(privdir), &tmpstatbuf) >= 0 && S_ISDIR(tmpstatbuf.st_mode)) + incpush(SvPVX_readonly(privdir), TRUE, FALSE, TRUE, FALSE); SvREFCNT_dec(privdir); } @@ -4365,7 +4365,7 @@ S_incpush_if_exists(pTHX_ SV *dir) { Stat_t tmpstatbuf; - if (PerlLIO_stat(SvPVX(dir), &tmpstatbuf) >= 0 && + if (PerlLIO_stat(SvPVX_readonly(dir), &tmpstatbuf) >= 0 && S_ISDIR(tmpstatbuf.st_mode)) { av_push(GvAVn(PL_incgv), dir); dir = NEWSV(0,0); @@ -4411,12 +4411,12 @@ p = Nullch; /* break out */ } #ifdef MACOS_TRADITIONAL - if (!strchr(SvPVX(libdir), ':')) { + if (!strchr(SvPVX_readonly(libdir), ':')) { char buf[256]; - sv_setpv(libdir, MacPerl_CanonDir(SvPVX(libdir), buf, 0)); + sv_setpv(libdir, MacPerl_CanonDir(SvPVX_readonly(libdir), buf, 0)); } - if (SvPVX(libdir)[SvCUR(libdir)-1] != ':') + if (SvPVX_readonly(libdir)[SvCUR(libdir)-1] != ':') sv_catpv(libdir, ":"); #endif @@ -4440,7 +4440,7 @@ * The intent is that /usr/local/bin/perl and .../../lib/perl5 * generates /usr/local/lib/perl5 */ - char *libpath = SvPVX(libdir); + char *libpath = SvPVX_readonly(libdir); STRLEN libpath_len = SvCUR(libdir); if (libpath_len >= 4 && memEQ (libpath, ".../", 4)) { /* Game on! */ @@ -4455,7 +4455,7 @@ SvPOK() won't be true. */ assert(caret_X); assert(SvPOKp(caret_X)); - prefix_sv = newSVpvn(SvPVX(caret_X), SvCUR(caret_X)); + prefix_sv = newSVpvn(SvPVX_readonly(caret_X), SvCUR(caret_X)); /* Firstly take off the leading .../ If all else fail we'll do the paths relative to the current directory. */ @@ -4464,14 +4464,14 @@ mortal copies that the mg_get of tainting creates, and corruption that seems to come via the save stack. I guess that the save stack isn't correctly set up yet. */ - libpath = SvPVX(libdir); + libpath = SvPVX_readonly(libdir); libpath_len = SvCUR(libdir); /* This would work more efficiently with memrchr, but as it's only a GNU extension we'd need to probe for it and implement our own. Not hard, but maybe not worth it? */ - prefix = SvPVX(prefix_sv); + prefix = SvPVX_readonly(prefix_sv); lastslash = strrchr(prefix, '/'); /* First time in with the *lastslash = '\0' we just wipe off @@ -4843,11 +4843,12 @@ static I32 read_e_script(pTHX_ int idx, SV *buf_sv, int maxlen) { - char *p, *nl; + const char *p; + char *nl; (void)idx; (void)maxlen; - p = SvPVX(PL_e_script); + p = SvPVX_readonly(PL_e_script); nl = strchr(p, '\n'); nl = (nl) ? nl+1 : SvEND(PL_e_script); if (nl-p == 0) { --- perlio.c.old 2005-05-02 11:14:24.000000000 -0500 +++ perlio.c 2005-05-05 00:19:22.577672296 -0500 @@ -4891,7 +4891,7 @@ f = PerlIO_fdopen(fd, "w+"); if (f) PerlIOBase(f)->flags |= PERLIO_F_TEMP; - PerlLIO_unlink(SvPVX(sv)); + PerlLIO_unlink(SvPVX_readonly(sv)); SvREFCNT_dec(sv); } # else /* !HAS_MKSTEMP, fallback to stdio tmpfile(). */ --- perl_keyword.pl.old 2005-02-14 11:52:06.000000000 -0600 +++ perl_keyword.pl 2005-05-04 22:48:52.772128208 -0500 @@ -52,7 +52,7 @@ */ I32 -Perl_keyword (pTHX_ char *name, I32 len) +Perl_keyword (pTHX_ const char *name, I32 len) { $switch unknown: --- perly.c.old 2005-04-13 10:36:37.000000000 -0500 +++ perly.c 2005-05-05 00:19:22.577672296 -0500 @@ -278,7 +278,7 @@ register YYSTYPE *yyvsp; /* for ease of re-allocation and automatic freeing, have two SVs whose - * SvPVX points to the stacks */ + * SvPVX_readonly points to the stacks */ SV *yyss_sv, *yyvs_sv; #ifdef DEBUGGING @@ -314,15 +314,15 @@ yyvs_sv = NEWSV(73, YYINITDEPTH * sizeof(YYSTYPE)); SAVEFREESV(yyss_sv); SAVEFREESV(yyvs_sv); - yyss = (short *) SvPVX(yyss_sv); - yyvs = (YYSTYPE *) SvPVX(yyvs_sv); + yyss = (short *) SvPVX_readonly(yyss_sv); + yyvs = (YYSTYPE *) SvPVX_readonly(yyvs_sv); /* note that elements zero of yyvs and yyns are not used */ yyssp = yyss; yyvsp = yyvs; #ifdef DEBUGGING yyns_sv = NEWSV(73, YYINITDEPTH * sizeof(char *)); SAVEFREESV(yyns_sv); - yyns = (const char **) SvPVX(yyns_sv); + yyns = (const char **) SvPVX_readonly(yyns_sv); yynsp = yyns; #endif @@ -362,11 +362,11 @@ SvGROW(yyss_sv, yystacksize * sizeof(short)); SvGROW(yyvs_sv, yystacksize * sizeof(YYSTYPE)); - yyss = (short *) SvPVX(yyss_sv); - yyvs = (YYSTYPE *) SvPVX(yyvs_sv); + yyss = (short *) SvPVX_readonly(yyss_sv); + yyvs = (YYSTYPE *) SvPVX_readonly(yyvs_sv); #ifdef DEBUGGING SvGROW(yyns_sv, yystacksize * sizeof(char *)); - yyns = (const char **) SvPVX(yyns_sv); + yyns = (const char **) SvPVX_readonly(yyns_sv); if (! yyns) goto yyoverflowlab; yynsp = yyns + yysize - 1; --- pp_ctl.c.old 2005-05-04 09:28:00.000000000 -0500 +++ pp_ctl.c 2005-05-05 00:19:22.577672296 -0500 @@ -475,14 +475,14 @@ case FF_LITERAL: arg = *fpc++; if (targ_is_utf8 && !SvUTF8(tmpForm)) { - SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, t - SvPVX_readonly(PL_formtarget)); *t = '\0'; sv_catpvn_utf8_upgrade(PL_formtarget, f, arg, nsv); t = SvEND(PL_formtarget); break; } if (!targ_is_utf8 && DO_UTF8(tmpForm)) { - SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, t - SvPVX_readonly(PL_formtarget)); *t = '\0'; sv_utf8_upgrade(PL_formtarget); SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1); @@ -658,7 +658,7 @@ s = item; if (item_is_utf8) { if (!targ_is_utf8) { - SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, t - SvPVX_readonly(PL_formtarget)); *t = '\0'; sv_utf8_upgrade(PL_formtarget); SvGROW(PL_formtarget, SvCUR(PL_formtarget) + fudge + 1); @@ -691,7 +691,7 @@ break; } if (targ_is_utf8 && !item_is_utf8) { - SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, t - SvPVX_readonly(PL_formtarget)); *t = '\0'; sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv); for (; t < SvEND(PL_formtarget); t++) { @@ -757,7 +757,7 @@ } } } - SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, t - SvPVX_readonly(PL_formtarget)); if (targ_is_utf8) SvUTF8_on(PL_formtarget); if (oneline) { @@ -829,7 +829,7 @@ if (gotsome) { if (arg) { /* repeat until fields exhausted? */ *t = '\0'; - SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, t - SvPVX_readonly(PL_formtarget)); lines += FmLINES(PL_formtarget); if (lines == 200) { arg = t - linemark; @@ -865,7 +865,7 @@ } s = t - 3; if (strnEQ(s," ",3)) { - while (s > SvPVX(PL_formtarget) && isSPACE(s[-1])) + while (s > SvPVX_readonly(PL_formtarget) && isSPACE(s[-1])) s--; } *s++ = '.'; @@ -876,7 +876,7 @@ case FF_END: *t = '\0'; - SvCUR_set(PL_formtarget, t - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, t - SvPVX_readonly(PL_formtarget)); if (targ_is_utf8) SvUTF8_on(PL_formtarget); FmLINES(PL_formtarget) += lines; @@ -1099,7 +1099,7 @@ SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \ SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \ (((!SvOK(left) && SvOK(right)) || ((!SvOK(left) || \ - looks_like_number(left)) && SvPOKp(left) && *SvPVX(left) != '0')) \ + looks_like_number(left)) && SvPOKp(left) && *SvPVX_readonly(left) != '0')) \ && (!SvOK(right) || looks_like_number(right)))) PP(pp_flop) @@ -1144,7 +1144,7 @@ SvPV_force(sv,n_a); while (!SvNIOKp(sv) && SvCUR(sv) <= len) { XPUSHs(sv); - if (strEQ(SvPVX(sv),tmps)) + if (strEQ(SvPVX_readonly(sv),tmps)) break; sv = sv_2mortal(newSVsv(sv)); sv_inc(sv); @@ -1410,7 +1410,7 @@ sv_catpvn(err, message, msglen); if (ckWARN(WARN_MISC)) { STRLEN start = SvCUR(err)-msglen-sizeof(prefix)+1; - Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX(err)+start); + Perl_warner(aTHX_ packWARN(WARN_MISC), SvPVX_readonly(err)+start); } } } @@ -1458,7 +1458,7 @@ if (optype == OP_REQUIRE) { const char* msg = SvPVx(ERRSV, n_a); SV *nsv = cx->blk_eval.old_namesv; - (void)hv_store(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), + (void)hv_store(GvHVn(PL_incgv), SvPVX_readonly(nsv), SvCUR(nsv), &PL_sv_undef, 0); DIE(aTHX_ "%sCompilation failed in require", *msg ? msg : "Unknown error\n"); @@ -1973,7 +1973,7 @@ { /* Unassume the success we assumed earlier. */ SV *nsv = cx->blk_eval.old_namesv; - (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD); + (void)hv_delete(GvHVn(PL_incgv), SvPVX_readonly(nsv), SvCUR(nsv), G_DISCARD); DIE(aTHX_ "%"SVf" did not return a true value", nsv); } break; @@ -2651,8 +2651,8 @@ STATIC void S_save_lines(pTHX_ AV *array, SV *sv) { - register const char *s = SvPVX(sv); - register const char *send = SvPVX(sv) + SvCUR(sv); + register const char *s = SvPVX_readonly(sv); + register const char *send = SvPVX_readonly(sv) + SvCUR(sv); register const char *t; register I32 line = 1; @@ -2935,7 +2935,7 @@ if (optype == OP_REQUIRE) { const char* msg = SvPVx(ERRSV, n_a); SV *nsv = cx->blk_eval.old_namesv; - (void)hv_store(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), + (void)hv_store(GvHVn(PL_incgv), SvPVX_readonly(nsv), SvCUR(nsv), &PL_sv_undef, 0); DIE(aTHX_ "%sCompilation failed in require", *msg ? msg : "Unknown error\n"); @@ -3044,7 +3044,7 @@ SV *sv; char *name; STRLEN len; - char *tryname = Nullch; + const char *tryname = Nullch; SV *namesv = Nullsv; SV** svp; I32 gimme = GIMME_V; @@ -3126,7 +3126,7 @@ Perl_sv_setpvf(aTHX_ namesv, "/loader/0x%"UVxf"/%s", PTR2UV(SvRV(dirsv)), name); - tryname = SvPVX(namesv); + tryname = SvPVX_readonly(namesv); tryrsfp = 0; ENTER; @@ -3267,7 +3267,7 @@ # endif #endif TAINT_PROPER("require"); - tryname = SvPVX(namesv); + tryname = SvPVX_readonly(namesv); tryrsfp = doopen_pm(tryname, PERL_SCRIPT_MODE); if (tryrsfp) { if (tryname[0] == '.' && tryname[1] == '/') @@ -3291,9 +3291,9 @@ AV *ar = GvAVn(PL_incgv); I32 i; sv_catpvn(msg, " in @INC", 8); - if (instr(SvPVX(msg), ".h ")) + if (instr(SvPVX_readonly(msg), ".h ")) sv_catpv(msg, " (change .h to .ph maybe?)"); - if (instr(SvPVX(msg), ".ph ")) + if (instr(SvPVX_readonly(msg), ".ph ")) sv_catpv(msg, " (did you run h2ph?)"); sv_catpv(msg, " (@INC contains:"); for (i = 0; i <= AvFILL(ar); i++) { @@ -3518,7 +3518,7 @@ { /* Unassume the success we assumed earlier. */ SV *nsv = cx->blk_eval.old_namesv; - (void)hv_delete(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), G_DISCARD); + (void)hv_delete(GvHVn(PL_incgv), SvPVX_readonly(nsv), SvCUR(nsv), G_DISCARD); retop = Perl_die(aTHX_ "%"SVf" did not return a true value", nsv); /* die_where() did LEAVE, or we won't be here */ } --- pp.c.old 2005-05-03 11:11:55.000000000 -0500 +++ pp.c 2005-05-05 00:19:22.577672296 -0500 @@ -182,7 +182,7 @@ } if (SvTYPE(sv) < SVt_RV) sv_upgrade(sv, SVt_RV); - if (SvPVX(sv)) { + if (SvPVX_readonly(sv)) { SvPV_free(sv); SvLEN_set(sv, 0); SvCUR_set(sv, 0); @@ -377,7 +377,7 @@ ret = &PL_sv_undef; if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) { - char *s = SvPVX(TOPs); + const char *s = SvPVX_readonly(TOPs); if (strnEQ(s, "CORE::", 6)) { int code; @@ -430,7 +430,7 @@ } cv = sv_2cv(TOPs, &stash, &gv, FALSE); if (cv && SvPOK(cv)) - ret = sv_2mortal(newSVpvn(SvPVX(cv), SvCUR(cv))); + ret = sv_2mortal(newSVpvn(SvPVX_readonly(cv), SvCUR(cv))); set: SETs(ret); RETURN; @@ -829,7 +829,7 @@ } break; default: - if (SvTYPE(sv) >= SVt_PV && SvPVX(sv) && SvLEN(sv)) { + if (SvTYPE(sv) >= SVt_PV && SvPVX_readonly(sv) && SvLEN(sv)) { SvPV_free(sv); SvPV_set(sv, Nullch); SvLEN_set(sv, 0); @@ -1498,7 +1498,7 @@ Perl_croak(aTHX_ oom_string_extend); MEM_WRAP_CHECK_1(max, char, oom_string_extend); SvGROW(TARG, max + 1); - repeatcpy(SvPVX(TARG) + len, SvPVX(TARG), len, count - 1); + repeatcpy(SvPVX(TARG) + len, SvPVX_readonly(TARG), len, count - 1); SvCUR_set(TARG, SvCUR(TARG) * count); } *SvEND(TARG) = '\0'; @@ -2909,7 +2909,7 @@ PP(pp_hex) { dSP; dTARGET; - char *tmps; + const char *tmps; I32 flags = PERL_SCAN_ALLOW_UNDERSCORES; STRLEN len; NV result_nv; @@ -2924,7 +2924,7 @@ SvUTF8_on(tsv); sv_utf8_downgrade(tsv, FALSE); - tmps = SvPVX(tsv); + tmps = SvPVX_readonly(tsv); } result_uv = grok_hex (tmps, &len, &flags, &result_nv); if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) { @@ -2939,7 +2939,7 @@ PP(pp_oct) { dSP; dTARGET; - char *tmps; + const char *tmps; I32 flags = PERL_SCAN_ALLOW_UNDERSCORES; STRLEN len; NV result_nv; @@ -2954,7 +2954,7 @@ SvUTF8_on(tsv); sv_utf8_downgrade(tsv, FALSE); - tmps = SvPVX(tsv); + tmps = SvPVX_readonly(tsv); } while (*tmps && len && isSPACE(*tmps)) tmps++, len--; @@ -3365,8 +3365,8 @@ if (value > 255 && !IN_BYTES) { SvGROW(TARG, (STRLEN)UNISKIP(value)+1); - tmps = (char*)uvchr_to_utf8_flags((U8*)SvPVX(TARG), value, 0); - SvCUR_set(TARG, tmps - SvPVX(TARG)); + tmps = (char*)uvchr_to_utf8_flags((U8*)SvPVX_readonly(TARG), value, 0); + SvCUR_set(TARG, tmps - SvPVX_readonly(TARG)); *tmps = '\0'; (void)SvPOK_only(TARG); SvUTF8_on(TARG); @@ -3405,7 +3405,7 @@ dPOPTOPssrl; STRLEN n_a; STRLEN len; - char *tmps = SvPV(left, len); + const char *tmps = SvPV(left, len); if (DO_UTF8(left)) { /* If Unicode, try to downgrade. @@ -3415,7 +3415,7 @@ SvUTF8_on(tsv); sv_utf8_downgrade(tsv, FALSE); - tmps = SvPVX(tsv); + tmps = SvPVX_readonly(tsv); } # ifdef USE_ITHREADS # ifdef HAS_CRYPT_R @@ -3593,7 +3593,7 @@ (void)SvUPGRADE(TARG, SVt_PV); SvGROW(TARG, min); (void)SvPOK_only(TARG); - d = (U8*)SvPVX(TARG); + d = (U8*)SvPVX_readonly(TARG); send = s + len; while (s < send) { STRLEN u = UTF8SKIP(s); @@ -3602,14 +3602,14 @@ if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) { /* If the eventually required minimum size outgrows * the available space, we need to grow. */ - UV o = d - (U8*)SvPVX(TARG); + UV o = d - (U8*)SvPVX_readonly(TARG); /* If someone uppercases one million U+03B0s we * SvGROW() one million times. Or we could try * guessing how much to allocate without allocating * too much. Such is life. */ SvGROW(TARG, min); - d = (U8*)SvPVX(TARG) + o; + d = (U8*)SvPVX_readonly(TARG) + o; } Copy(tmpbuf, d, ulen, U8); d += ulen; @@ -3617,7 +3617,7 @@ } *d = '\0'; SvUTF8_on(TARG); - SvCUR_set(TARG, d - (U8*)SvPVX(TARG)); + SvCUR_set(TARG, d - (U8*)SvPVX_readonly(TARG)); SETs(TARG); } } @@ -3676,7 +3676,7 @@ (void)SvUPGRADE(TARG, SVt_PV); SvGROW(TARG, min); (void)SvPOK_only(TARG); - d = (U8*)SvPVX(TARG); + d = (U8*)SvPVX_readonly(TARG); send = s + len; while (s < send) { STRLEN u = UTF8SKIP(s); @@ -3704,14 +3704,14 @@ if (ulen > u && (SvLEN(TARG) < (min += ulen - u))) { /* If the eventually required minimum size outgrows * the available space, we need to grow. */ - UV o = d - (U8*)SvPVX(TARG); + UV o = d - (U8*)SvPVX_readonly(TARG); /* If someone lowercases one million U+0130s we * SvGROW() one million times. Or we could try * guessing how much to allocate without allocating. * too much. Such is life. */ SvGROW(TARG, min); - d = (U8*)SvPVX(TARG) + o; + d = (U8*)SvPVX_readonly(TARG) + o; } Copy(tmpbuf, d, ulen, U8); d += ulen; @@ -3719,7 +3719,7 @@ } *d = '\0'; SvUTF8_on(TARG); - SvCUR_set(TARG, d - (U8*)SvPVX(TARG)); + SvCUR_set(TARG, d - (U8*)SvPVX_readonly(TARG)); SETs(TARG); } } @@ -3792,7 +3792,7 @@ } } *d = '\0'; - SvCUR_set(TARG, d - SvPVX(TARG)); + SvCUR_set(TARG, d - SvPVX_readonly(TARG)); (void)SvPOK_only_UTF8(TARG); } else @@ -4474,7 +4474,7 @@ up = SvPV_force(TARG, len); if (len > 1) { if (DO_UTF8(TARG)) { /* first reverse each character */ - U8* s = (U8*)SvPVX(TARG); + U8* s = (U8*)SvPVX_readonly(TARG); U8* send = (U8*)(s + len); while (s < send) { if (UTF8_IS_INVARIANT(*s)) { --- pp_hot.c.old 2005-04-28 06:50:18.000000000 -0500 +++ pp_hot.c 2005-05-05 00:19:22.577672296 -0500 @@ -1402,7 +1402,7 @@ (int)(t-truebase)); } rx->saved_copy = sv_setsv_cow(rx->saved_copy, TARG); - rx->subbeg = SvPVX(rx->saved_copy) + (t - truebase); + rx->subbeg = SvPVX_readonly(rx->saved_copy) + (t - truebase); assert (SvPOKp(rx->saved_copy)); } else #endif @@ -1598,7 +1598,7 @@ if (SvCUR(sv) > 0 && SvCUR(PL_rs) > 0) { tmps = SvEND(sv) - 1; - if (*tmps == *SvPVX(PL_rs)) { + if (*tmps == *SvPVX_readonly(PL_rs)) { *tmps = '\0'; SvCUR_set(sv, SvCUR(sv) - 1); } @@ -1607,12 +1607,12 @@ if (!isALPHA(*tmps) && !isDIGIT(*tmps) && strchr("$&*(){}[]'\";\\|?<>~`", *tmps)) break; - if (*tmps && PerlLIO_lstat(SvPVX(sv), &PL_statbuf) < 0) { + if (*tmps && PerlLIO_lstat(SvPVX_readonly(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 = (U8*)SvPVX_readonly(sv) + offset; const STRLEN len = SvCUR(sv) - offset; const U8 *f; @@ -1842,7 +1842,7 @@ *itersvp = newSVsv(cur); SvREFCNT_dec(oldsv); } - if (strEQ(SvPVX(cur), max)) + if (strEQ(SvPVX_readonly(cur), max)) sv_setiv(cur, 0); /* terminate next time */ else sv_inc(cur); @@ -2167,7 +2167,7 @@ REXEC_NOT_FIRST|REXEC_IGNOREPOS)); if (s != d) { i = strend - s; - SvCUR_set(TARG, d - SvPVX(TARG) + i); + SvCUR_set(TARG, d - SvPVX_readonly(TARG) + i); Move(s, d, i+1, char); /* include the NUL */ } TAINT_IF(rxtainted & 1); @@ -2624,7 +2624,7 @@ mg_get(sv); if (SvROK(sv)) goto got_rv; - sym = SvPOKp(sv) ? SvPVX(sv) : Nullch; + sym = SvPOKp(sv) ? SvPVX_readonly(sv) : Nullch; } else { STRLEN n_a; --- pp_pack.c.old 2005-05-02 11:14:24.000000000 -0500 +++ pp_pack.c 2005-05-05 00:19:22.577672296 -0500 @@ -1558,7 +1558,7 @@ } } *str = '\0'; - SvCUR_set(sv, str - SvPVX(sv)); + SvCUR_set(sv, str - SvPVX_readonly(sv)); XPUSHs(sv); break; } @@ -1595,7 +1595,7 @@ } } *str = '\0'; - SvCUR_set(sv, str - SvPVX(sv)); + SvCUR_set(sv, str - SvPVX_readonly(sv)); XPUSHs(sv); break; } @@ -2427,7 +2427,7 @@ TEMPSYM_INIT(&sym, pat, patend, FLAG_PACK); - /* We're going to do changes through SvPVX(cat). Make sure it's valid. + /* We're going to do changes through SvPVX_readonly(cat). Make sure it's valid. Also make sure any UTF8 flag is loaded */ SvPV_force(cat, no_len); if (DO_UTF8(cat)) sym.flags |= FLAG_PARSE_UTF8 | FLAG_DO_UTF8; @@ -2445,7 +2445,7 @@ if (SvUTF8(sv)) return; - from_start = SvPVX(sv); + from_start = SvPVX_readonly(sv); from_end = from_start + SvCUR(sv); for (from_ptr = from_start; from_ptr < from_end; from_ptr++) if (!NATIVE_IS_INVARIANT(*from_ptr)) break; --- pp_sys.c.old 2005-05-02 12:39:50.000000000 -0500 +++ pp_sys.c 2005-05-05 00:19:22.577672296 -0500 @@ -414,7 +414,7 @@ PL_rs = sv_2mortal(newSVpvn("\000", 1)); #ifndef DOSISH #ifndef CSH - *SvPVX(PL_rs) = '\n'; + *SvPVX_readonly(PL_rs) = '\n'; #endif /* !CSH */ #endif /* !DOSISH */ @@ -1092,7 +1092,7 @@ } #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678 - s = SvPVX(sv); + s = SvPVX_readonly(sv); New(403, fd_sets[i], growsize, char); for (offset = 0; offset < growsize; offset += masksize) { for (j = 0, k=ORDERBYTE; j < masksize; j++, (k >>= 4)) @@ -1124,7 +1124,7 @@ if (fd_sets[i]) { sv = SP[i]; #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678 - s = SvPVX(sv); + s = SvPVX_readonly(sv); for (offset = 0; offset < growsize; offset += masksize) { for (j = 0, k=ORDERBYTE; j < masksize; j++, (k >>= 4)) s[(k % masksize) + offset] = fd_sets[i][j+offset]; @@ -1234,7 +1234,7 @@ *SvPVX(TARG) = PerlIO_getc(IoIFP(GvIOp(gv))); /* should never be EOF */ if (PerlIO_isutf8(IoIFP(GvIOp(gv)))) { /* Find out how many bytes the char needs */ - Size_t len = UTF8SKIP(SvPVX(TARG)); + Size_t len = UTF8SKIP(SvPVX_readonly(TARG)); if (len > 1) { SvGROW(TARG,len+1); len = PerlIO_read(IoIFP(GvIOp(gv)),SvPVX(TARG)+1,len-1); @@ -1369,7 +1369,7 @@ } if (s) { STRLEN save = SvCUR(PL_formtarget); - SvCUR_set(PL_formtarget, s - SvPVX(PL_formtarget)); + SvCUR_set(PL_formtarget, s - SvPVX_readonly(PL_formtarget)); do_print(PL_formtarget, ofp); SvCUR_set(PL_formtarget, save); sv_chop(PL_formtarget, s); @@ -1744,7 +1744,7 @@ report_evil_fh(gv, io, OP_phoney_OUTPUT_ONLY); goto say_undef; } - SvCUR_set(read_target, count+(buffer - SvPVX(read_target))); + SvCUR_set(read_target, count+(buffer - SvPVX_readonly(read_target))); *SvEND(read_target) = '\0'; (void)SvPOK_only(read_target); if (fp_utf8 && !IN_BYTES) { @@ -1758,7 +1758,7 @@ if (buffer - charskip + skip > bend) { /* partial character - try for rest of it */ length = skip - (bend-buffer); - offset = bend - SvPVX(bufsv); + offset = bend - SvPVX_readonly(bufsv); charstart = FALSE; charskip += count; goto more_bytes; @@ -1775,7 +1775,7 @@ */ if (got < wanted && count == length) { length = wanted - got; - offset = bend - SvPVX(bufsv); + offset = bend - SvPVX_readonly(bufsv); goto more_bytes; } /* return value is character count */ @@ -2750,18 +2750,18 @@ fd = PerlIO_fileno(IoIFP(io)); switch (optype) { case OP_GETSOCKNAME: - if (PerlSock_getsockname(fd, (struct sockaddr *)SvPVX(sv), &len) < 0) + if (PerlSock_getsockname(fd, (struct sockaddr *)SvPVX_readonly(sv), &len) < 0) goto nuts2; break; case OP_GETPEERNAME: - if (PerlSock_getpeername(fd, (struct sockaddr *)SvPVX(sv), &len) < 0) + if (PerlSock_getpeername(fd, (struct sockaddr *)SvPVX_readonly(sv), &len) < 0) goto nuts2; #if defined(VMS_DO_SOCKETS) && defined (DECCRTL_SOCKETS) { static const char nowhere[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; /* If the call succeeded, make sure we don't have a zeroed port/addr */ - if (((struct sockaddr *)SvPVX(sv))->sa_family == AF_INET && - !memcmp((char *)SvPVX(sv) + sizeof(u_short), nowhere, + if (((struct sockaddr *)SvPVX_readonly(sv))->sa_family == AF_INET && + !memcmp((char *)SvPVX_readonly(sv) + sizeof(u_short), nowhere, sizeof(u_short) + sizeof(struct in_addr))) { goto nuts2; } @@ -3466,7 +3466,7 @@ PL_statgv = Nullgv; PL_laststype = OP_STAT; sv_setpv(PL_statname, SvPV(sv, n_a)); - if (!(fp = PerlIO_open(SvPVX(PL_statname), "r"))) { + if (!(fp = PerlIO_open(SvPVX_readonly(PL_statname), "r"))) { if (ckWARN(WARN_NEWLINE) && strchr(SvPV(PL_statname, n_a), '\n')) Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "open"); RETPUSHUNDEF; --- regcomp.c.old 2005-05-02 02:43:17.000000000 -0500 +++ regcomp.c 2005-05-05 00:19:22.577672296 -0500 @@ -2386,7 +2386,7 @@ if (mincount > 1) { SvGROW(last_str, (mincount * l) + 1); repeatcpy(SvPVX(last_str) + l, - SvPVX(last_str), l, mincount - 1); + SvPVX_readonly(last_str), l, mincount - 1); SvCUR_set(last_str, SvCUR(last_str) * mincount); /* Add additional parts. */ SvCUR_set(data->last_found, @@ -3140,7 +3140,7 @@ regprop(sv, (regnode*)data.start_class); PerlIO_printf(Perl_debug_log, "synthetic stclass `%s'.\n", - SvPVX(sv));}); + SvPVX_readonly(sv));}); } /* A temporary algorithm prefers floated substr to fixed one to dig more info. */ @@ -3195,7 +3195,7 @@ regprop(sv, (regnode*)data.start_class); PerlIO_printf(Perl_debug_log, "synthetic stclass `%s'.\n", - SvPVX(sv));}); + SvPVX_readonly(sv));}); } } @@ -5695,7 +5695,7 @@ goto after_print; regprop(sv, node); PerlIO_printf(Perl_debug_log, "%4"IVdf":%*s%s", (IV)(node - start), - (int)(2*l + 1), "", SvPVX(sv)); + (int)(2*l + 1), "", SvPVX_readonly(sv)); if (next == NULL) /* Next ptr. */ PerlIO_printf(Perl_debug_log, "(0)"); else @@ -5803,7 +5803,7 @@ "anchored `%s%.*s%s'%s at %"IVdf" ", PL_colors[0], (int)(SvCUR(r->anchored_substr) - (SvTAIL(r->anchored_substr)!=0)), - SvPVX(r->anchored_substr), + SvPVX_readonly(r->anchored_substr), PL_colors[1], SvTAIL(r->anchored_substr) ? "$" : "", (IV)r->anchored_offset); @@ -5812,7 +5812,7 @@ "anchored utf8 `%s%.*s%s'%s at %"IVdf" ", PL_colors[0], (int)(SvCUR(r->anchored_utf8) - (SvTAIL(r->anchored_utf8)!=0)), - SvPVX(r->anchored_utf8), + SvPVX_readonly(r->anchored_utf8), PL_colors[1], SvTAIL(r->anchored_utf8) ? "$" : "", (IV)r->anchored_offset); @@ -5821,7 +5821,7 @@ "floating `%s%.*s%s'%s at %"IVdf"..%"UVuf" ", PL_colors[0], (int)(SvCUR(r->float_substr) - (SvTAIL(r->float_substr)!=0)), - SvPVX(r->float_substr), + SvPVX_readonly(r->float_substr), PL_colors[1], SvTAIL(r->float_substr) ? "$" : "", (IV)r->float_min_offset, (UV)r->float_max_offset); @@ -5830,7 +5830,7 @@ "floating utf8 `%s%.*s%s'%s at %"IVdf"..%"UVuf" ", PL_colors[0], (int)(SvCUR(r->float_utf8) - (SvTAIL(r->float_utf8)!=0)), - SvPVX(r->float_utf8), + SvPVX_readonly(r->float_utf8), PL_colors[1], SvTAIL(r->float_utf8) ? "$" : "", (IV)r->float_min_offset, (UV)r->float_max_offset); @@ -5848,7 +5848,7 @@ if (r->regstclass) { regprop(sv, r->regstclass); - PerlIO_printf(Perl_debug_log, "stclass `%s' ", SvPVX(sv)); + PerlIO_printf(Perl_debug_log, "stclass `%s' ", SvPVX_readonly(sv)); } if (r->reganch & ROPT_ANCH) { PerlIO_printf(Perl_debug_log, "anchored"); --- scope.c.old 2005-04-19 05:26:03.000000000 -0500 +++ scope.c 2005-05-05 00:19:22.577672296 -0500 @@ -267,7 +267,7 @@ SSPUSHIV((IV)SvLEN(gv)); SvLEN_set(gv, 0); /* forget that anything was allocated here */ SSPUSHIV((IV)SvCUR(gv)); - SSPUSHPTR(SvPVX(gv)); + SSPUSHPTR(SvPVX_readonly(gv)); SvPOK_off(gv); SSPUSHPTR(SvREFCNT_inc(gv)); SSPUSHPTR(GvGP(gv)); @@ -842,8 +842,8 @@ case SAVEt_GP: /* scalar reference */ ptr = SSPOPPTR; gv = (GV*)SSPOPPTR; - if (SvPVX(gv) && SvLEN(gv) > 0) { - Safefree(SvPVX(gv)); + if (SvPVX_readonly(gv) && SvLEN(gv) > 0) { + Safefree(SvPVX_readonly(gv)); } SvPV_set(gv, (char *)SSPOPPTR); SvCUR_set(gv, (STRLEN)SSPOPIV); @@ -1095,7 +1095,7 @@ PL_op_desc[cx->blk_eval.old_op_type]); if (cx->blk_eval.old_namesv) PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n", - SvPVX(cx->blk_eval.old_namesv)); + SvPVX_readonly(cx->blk_eval.old_namesv)); PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n", PTR2UV(cx->blk_eval.old_eval_root)); PerlIO_printf(Perl_debug_log, "BLK_EVAL.RETOP = 0x%"UVxf"\n", --- sv.c.old 2005-05-01 17:42:59.000000000 -0500 +++ sv.c 2005-05-05 00:19:22.578672144 -0500 @@ -754,7 +754,7 @@ *SvPVX(name) = '$'; sv = NEWSV(0,0); Perl_sv_catpvf(aTHX_ name, "{%s}", - pv_display(sv,SvPVX(keyname), SvCUR(keyname), 0, 32)); + pv_display(sv,SvPVX_readonly(keyname), SvCUR(keyname), 0, 32)); SvREFCNT_dec(sv); } else if (subscript_type == FUV_SUBSCRIPT_ARRAY) { @@ -2010,11 +2010,11 @@ { assert(SvOOK(sv)); if (SvIVX(sv)) { - char *s = SvPVX(sv); + const char *s = SvPVX_readonly(sv); SvLEN_set(sv, SvLEN(sv) + SvIVX(sv)); SvPV_set(sv, SvPVX(sv) - SvIVX(sv)); SvIV_set(sv, 0); - Move(s, SvPVX(sv), SvCUR(sv)+1, char); + Move(s, SvPVX_readonly(sv), SvCUR(sv)+1, char); } SvFLAGS(sv) &= ~SVf_OOK; return 0; @@ -2064,7 +2064,7 @@ if (newlen > SvLEN(sv)) { /* need more room? */ if (SvLEN(sv) && s) { #ifdef MYMALLOC - STRLEN l = malloced_size((void*)SvPVX(sv)); + STRLEN l = malloced_size((void*)SvPVX_readonly(sv)); if (newlen <= l) { SvLEN_set(sv, l); return s; @@ -2074,8 +2074,8 @@ } else { New(703, s, newlen, char); - if (SvPVX(sv) && SvCUR(sv)) { - Move(SvPVX(sv), s, (newlen < SvCUR(sv)) ? newlen : SvCUR(sv), char); + if (SvPVX_readonly(sv) && SvCUR(sv)) { + Move(SvPVX_readonly(sv), s, (newlen < SvCUR(sv)) ? newlen : SvCUR(sv), char); } } SvPV_set(sv, s); @@ -2335,11 +2335,11 @@ I32 Perl_looks_like_number(pTHX_ SV *sv) { - register char *sbegin; + register const char *sbegin; STRLEN len; if (SvPOK(sv)) { - sbegin = SvPVX(sv); + sbegin = SvPVX_readonly(sv); len = SvCUR(sv); } else if (SvPOKp(sv)) @@ -2436,7 +2436,7 @@ STATIC int S_sv_2iuv_non_preserve(pTHX_ register SV *sv, I32 numtype) { - DEBUG_c(PerlIO_printf(Perl_debug_log,"sv_2iuv_non '%s', IV=0x%"UVxf" NV=%"NVgf" inttype=%"UVXf"\n", SvPVX(sv), SvIVX(sv), SvNVX(sv), (UV)numtype)); + DEBUG_c(PerlIO_printf(Perl_debug_log,"sv_2iuv_non '%s', IV=0x%"UVxf" NV=%"NVgf" inttype=%"UVXf"\n", SvPVX_readonly(sv), SvIVX(sv), SvNVX(sv), (UV)numtype)); if (SvNVX(sv) < (NV)IV_MIN) { (void)SvIOKp_on(sv); (void)SvNOK_on(sv); @@ -2626,7 +2626,7 @@ } else if (SvPOKp(sv) && SvLEN(sv)) { UV value; - int numtype = grok_number(SvPVX(sv), SvCUR(sv), &value); + int numtype = grok_number(SvPVX_readonly(sv), SvCUR(sv), &value); /* We want to avoid a possible problem when we cache an IV which may be later translated to an NV, and the resulting NV is not the same as the direct translation of the initial string @@ -2693,7 +2693,7 @@ if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) != IS_NUMBER_IN_UV) { /* It wasn't an (integer that doesn't overflow the UV). */ - SvNV_set(sv, Atof(SvPVX(sv))); + SvNV_set(sv, Atof(SvPVX_readonly(sv))); if (! numtype && ckWARN(WARN_NUMERIC)) not_a_number(sv); @@ -2929,7 +2929,7 @@ } else if (SvPOKp(sv) && SvLEN(sv)) { UV value; - int numtype = grok_number(SvPVX(sv), SvCUR(sv), &value); + int numtype = grok_number(SvPVX_readonly(sv), SvCUR(sv), &value); /* We want to avoid a possible problem when we cache a UV which may be later translated to an NV, and the resulting NV is not @@ -2992,7 +2992,7 @@ if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) != IS_NUMBER_IN_UV) { /* It wasn't an integer, or it overflowed the UV. */ - SvNV_set(sv, Atof(SvPVX(sv))); + SvNV_set(sv, Atof(SvPVX_readonly(sv))); if (! numtype && ckWARN(WARN_NUMERIC)) not_a_number(sv); @@ -3101,9 +3101,9 @@ return SvNVX(sv); if (SvPOKp(sv) && SvLEN(sv)) { if (ckWARN(WARN_NUMERIC) && !SvIOKp(sv) && - !grok_number(SvPVX(sv), SvCUR(sv), NULL)) + !grok_number(SvPVX_readonly(sv), SvCUR(sv), NULL)) not_a_number(sv); - return Atof(SvPVX(sv)); + return Atof(SvPVX_readonly(sv)); } if (SvIOKp(sv)) { if (SvIsUV(sv)) @@ -3179,7 +3179,7 @@ } else if (SvPOKp(sv) && SvLEN(sv)) { UV value; - int numtype = grok_number(SvPVX(sv), SvCUR(sv), &value); + int numtype = grok_number(SvPVX_readonly(sv), SvCUR(sv), &value); if (ckWARN(WARN_NUMERIC) && !SvIOKp(sv) && !numtype) not_a_number(sv); #ifdef NV_PRESERVES_UV @@ -3188,10 +3188,10 @@ /* It's definitely an integer */ SvNV_set(sv, (numtype & IS_NUMBER_NEG) ? -(NV)value : (NV)value); } else - SvNV_set(sv, Atof(SvPVX(sv))); + SvNV_set(sv, Atof(SvPVX_readonly(sv))); SvNOK_on(sv); #else - SvNV_set(sv, Atof(SvPVX(sv))); + SvNV_set(sv, Atof(SvPVX_readonly(sv))); /* Only set the public NV OK flag if this NV preserves the value in the PV at least as well as an IV/UV would. Not sure how to do this 100% reliably. */ @@ -3296,7 +3296,7 @@ S_asIV(pTHX_ SV *sv) { UV value; - int numtype = grok_number(SvPVX(sv), SvCUR(sv), &value); + int numtype = grok_number(SvPVX_readonly(sv), SvCUR(sv), &value); if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) == IS_NUMBER_IN_UV) { @@ -3313,7 +3313,7 @@ if (ckWARN(WARN_NUMERIC)) not_a_number(sv); } - return I_V(Atof(SvPVX(sv))); + return I_V(Atof(SvPVX_readonly(sv))); } /* asUV(): extract an unsigned integer from the string value of an SV @@ -3323,7 +3323,7 @@ S_asUV(pTHX_ SV *sv) { UV value; - int numtype = grok_number(SvPVX(sv), SvCUR(sv), &value); + int numtype = grok_number(SvPVX_readonly(sv), SvCUR(sv), &value); if ((numtype & (IS_NUMBER_IN_UV | IS_NUMBER_NOT_INT)) == IS_NUMBER_IN_UV) { @@ -3335,7 +3335,7 @@ if (ckWARN(WARN_NUMERIC)) not_a_number(sv); } - return U_V(Atof(SvPVX(sv))); + return U_V(Atof(SvPVX_readonly(sv))); } /* @@ -3610,7 +3610,7 @@ else ptr = uiv_2buf(buf, SvIVX(sv), 0, 0, &ebuf); SvGROW(sv, (STRLEN)(ebuf - ptr + 1)); /* inlined from sv_setpvn */ - Move(ptr,SvPVX(sv),ebuf - ptr,char); + Move(ptr,SvPVX_readonly(sv),ebuf - ptr,char); SvCUR_set(sv, ebuf - ptr); s = SvEND(sv); *s = '\0'; @@ -3657,11 +3657,11 @@ sv_upgrade(sv, SVt_PV); return (char *)""; } - *lp = s - SvPVX(sv); + *lp = s - SvPVX_readonly(sv); SvCUR_set(sv, *lp); SvPOK_on(sv); DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%"UVxf" 2pv(%s)\n", - PTR2UV(sv),SvPVX(sv))); + PTR2UV(sv),SvPVX_readonly(sv))); return SvPVX(sv); tokensave: @@ -3682,7 +3682,7 @@ if (tsv) { sv_2mortal(tsv); - t = SvPVX(tsv); + t = SvPVX_readonly(tsv); len = SvCUR(tsv); } else { @@ -3918,7 +3918,7 @@ * had a FLAG in SVs to signal if there are any hibit * chars in the PV. Given that there isn't such a flag * make the loop as fast as possible. */ - U8 *s = (U8 *) SvPVX(sv); + U8 *s = (U8 *) SvPVX_readonly(sv); U8 *e = (U8 *) SvEND(sv); U8 *t = s; int hibit = 0; @@ -4038,7 +4038,7 @@ /* it is actually just a matter of turning the utf8 flag on, but * we want to make sure everything inside is valid utf8 first. */ - c = (U8 *) SvPVX(sv); + c = (U8 *) SvPVX_readonly(sv); if (!is_utf8_string(c, SvCUR(sv)+1)) return FALSE; e = (U8 *) SvEND(sv); @@ -4373,7 +4373,7 @@ } if (!intro) cv_ckproto(cv, (GV*)dstr, - SvPOK(sref) ? SvPVX(sref) : Nullch); + SvPOK(sref) ? SvPVX_readonly(sref) : Nullch); } GvCV(dstr) = (CV*)sref; GvCVGEN(dstr) = 0; /* Switch off cacheness. */ @@ -4419,7 +4419,7 @@ SvTAINT(dstr); return; } - if (SvPVX(dstr)) { + if (SvPVX_readonly(dstr)) { SvPV_free(dstr); SvLEN_set(dstr, 0); SvCUR_set(dstr, 0); @@ -4453,8 +4453,8 @@ /* * Check to see if we can just swipe the string. If so, it's a * possible small lose on short strings, but a big win on long ones. - * It might even be a win on short strings if SvPVX(dstr) - * has to be allocated and SvPVX(sstr) has to be freed. + * It might even be a win on short strings if SvPVX_readonly(dstr) + * has to be allocated and SvPVX_readonly(sstr) has to be freed. */ /* Whichever path we take through the next code, we want this true, @@ -4485,7 +4485,7 @@ Have to copy the string. */ STRLEN len = SvCUR(sstr); SvGROW(dstr, len + 1); /* inlined from sv_setpvn */ - Move(SvPVX(sstr),SvPVX(dstr),len,char); + Move(SvPVX_readonly(sstr),SvPVX_readonly(dstr),len,char); SvCUR_set(dstr, len); *SvEND(dstr) = '\0'; } else { @@ -4517,13 +4517,13 @@ } #endif /* Initial code is common. */ - if (SvPVX(dstr)) { /* we know that dtype >= SVt_PV */ + if (SvPVX_readonly(dstr)) { /* we know that dtype >= SVt_PV */ if (SvOOK(dstr)) { SvFLAGS(dstr) &= ~SVf_OOK; - Safefree(SvPVX(dstr) - SvIVX(dstr)); + Safefree(SvPVX_readonly(dstr) - SvIVX(dstr)); } else if (SvLEN(dstr)) - Safefree(SvPVX(dstr)); + Safefree(SvPVX_readonly(dstr)); } #ifdef PERL_COPY_ON_WRITE @@ -4537,14 +4537,14 @@ /* splice us in between source and next-after-source. */ SV_COW_NEXT_SV_SET(dstr, SV_COW_NEXT_SV(sstr)); SV_COW_NEXT_SV_SET(sstr, dstr); - SvPV_set(dstr, SvPVX(sstr)); + SvPV_set(dstr, SvPVX_readonly(sstr)); } else { /* SvIsCOW_shared_hash */ UV hash = SvUVX(sstr); DEBUG_C(PerlIO_printf(Perl_debug_log, "Copy on write: Sharing hash\n")); SvPV_set(dstr, - sharepvn(SvPVX(sstr), + sharepvn(SvPVX_readonly(sstr), (sflags & SVf_UTF8?-cur:cur), hash)); SvUV_set(dstr, hash); } @@ -4667,8 +4667,8 @@ if (dstr) { if (SvTHINKFIRST(dstr)) sv_force_normal_flags(dstr, SV_COW_DROP_PV); - else if (SvPVX(dstr)) - Safefree(SvPVX(dstr)); + else if (SvPVX_readonly(dstr)) + Safefree(SvPVX_readonly(dstr)); } else new_SV(dstr); @@ -4689,7 +4689,7 @@ DEBUG_C(PerlIO_printf(Perl_debug_log, "Fast copy on write: Sharing hash\n")); SvUV_set(dstr, hash); - new_pv = sharepvn(SvPVX(sstr), (SvUTF8(sstr)?-cur:cur), hash); + new_pv = sharepvn(SvPVX_readonly(sstr), (SvUTF8(sstr)?-cur:cur), hash); goto common_exit; } SV_COW_NEXT_SV_SET(dstr, SV_COW_NEXT_SV(sstr)); @@ -4703,7 +4703,7 @@ SV_COW_NEXT_SV_SET(dstr, sstr); } SV_COW_NEXT_SV_SET(sstr, dstr); - new_pv = SvPVX(sstr); + new_pv = SvPVX_readonly(sstr); common_exit: SvPV_set(dstr, new_pv); @@ -4794,7 +4794,7 @@ (void)SvUPGRADE(sv, SVt_PV); SvGROW(sv, len + 1); - Move(ptr,SvPVX(sv),len+1,char); + Move(ptr,SvPVX_readonly(sv),len+1,char); SvCUR_set(sv, len); (void)SvPOK_only_UTF8(sv); /* validate pointer */ SvTAINT(sv); @@ -4838,7 +4838,7 @@ (void)SvOK_off(sv); return; } - if (SvPVX(sv)) + if (SvPVX_readonly(sv)) SvPV_free(sv); Renew(ptr, len+1, char); SvPV_set(sv, ptr); @@ -4893,7 +4893,7 @@ /* don't loop forever if the structure is bust, and we have a pointer into a closed loop. */ assert (current != after); - assert (SvPVX(current) == pvx); + assert (SvPVX_readonly(current) == pvx); } /* Make the SV before us point to the SV after us. */ SV_COW_NEXT_SV_SET(current, after); @@ -4935,7 +4935,7 @@ if (SvREADONLY(sv)) { /* At this point I believe I should acquire a global SV mutex. */ if (SvFAKE(sv)) { - char *pvx = SvPVX(sv); + char *pvx = SvPVX_readonly(sv); STRLEN len = SvLEN(sv); STRLEN cur = SvCUR(sv); U32 hash = SvUVX(sv); @@ -4956,7 +4956,7 @@ SvPOK_off(sv); } else { SvGROW(sv, cur + 1); - Move(pvx,SvPVX(sv),cur,char); + Move(pvx,SvPVX_readonly(sv),cur,char); SvCUR_set(sv, cur); *SvEND(sv) = '\0'; } @@ -4972,7 +4972,7 @@ #else if (SvREADONLY(sv)) { if (SvFAKE(sv)) { - char *pvx = SvPVX(sv); + const char *pvx = SvPVX_readonly(sv); int is_utf8 = SvUTF8(sv); STRLEN len = SvCUR(sv); U32 hash = SvUVX(sv); @@ -4981,7 +4981,7 @@ SvPV_set(sv, (char*)0); SvLEN_set(sv, 0); SvGROW(sv, len + 1); - Move(pvx,SvPVX(sv),len,char); + Move(pvx,SvPVX_readonly(sv),len,char); *SvEND(sv) = '\0'; unsharepvn(pvx, is_utf8 ? -(I32)len : len, hash); } @@ -5018,7 +5018,7 @@ SvPOK(sv) must be true and the C<ptr> must be a pointer to somewhere inside the string buffer. The C<ptr> becomes the first character of the adjusted string. Uses the "OOK hack". -Beware: after this function returns, C<ptr> and SvPVX(sv) may no longer +Beware: after this function returns, C<ptr> and SvPVX_readonly(sv) may no longer refer to the same chunk of data. =cut @@ -5030,17 +5030,17 @@ register STRLEN delta; if (!ptr || !SvPOKp(sv)) return; - delta = ptr - SvPVX(sv); + delta = ptr - SvPVX_readonly(sv); SV_CHECK_THINKFIRST(sv); if (SvTYPE(sv) < SVt_PVIV) sv_upgrade(sv,SVt_PVIV); if (!SvOOK(sv)) { if (!SvLEN(sv)) { /* make copy of shared string */ - char *pvx = SvPVX(sv); + const char *pvx = SvPVX_readonly(sv); STRLEN len = SvCUR(sv); SvGROW(sv, len + 1); - Move(pvx,SvPVX(sv),len,char); + Move(pvx,SvPVX_readonly(sv),len,char); *SvEND(sv) = '\0'; } SvIV_set(sv, 0); @@ -5095,8 +5095,8 @@ dstr = SvPV_force_flags(dsv, dlen, flags); SvGROW(dsv, dlen + slen + 1); if (sstr == dstr) - sstr = SvPVX(dsv); - Move(sstr, SvPVX(dsv) + dlen, slen, char); + sstr = SvPVX_readonly(dsv); + Move(sstr, SvPVX_readonly(dsv) + dlen, slen, char); SvCUR_set(dsv, SvCUR(dsv) + slen); *SvEND(dsv) = '\0'; (void)SvPOK_only_UTF8(dsv); /* validate pointer */ @@ -5218,8 +5218,8 @@ len = strlen(ptr); SvGROW(sv, tlen + len + 1); if (ptr == junk) - ptr = SvPVX(sv); - Move(ptr,SvPVX(sv)+tlen,len+1,char); + ptr = SvPVX_readonly(sv); + Move(ptr,SvPVX_readonly(sv)+tlen,len+1,char); SvCUR_set(sv, SvCUR(sv) + len); (void)SvPOK_only_UTF8(sv); /* validate pointer */ SvTAINT(sv); @@ -5678,7 +5678,7 @@ (void)SvPOK_only_UTF8(bigstr); if (offset + len > curlen) { SvGROW(bigstr, offset+len+1); - Zero(SvPVX(bigstr)+curlen, offset+len-curlen, char); + Zero(SvPVX_readonly(bigstr)+curlen, offset+len-curlen, char); SvCUR_set(bigstr, offset+len); } @@ -5698,7 +5698,7 @@ return; } else if (i == 0) { - Move(little,SvPVX(bigstr)+offset,len,char); + Move(little,SvPVX_readonly(bigstr)+offset,len,char); SvSETMAGIC(bigstr); return; } @@ -5796,7 +5796,7 @@ while ((next = SV_COW_NEXT_SV(current)) != nsv) { assert(next); current = next; - assert(SvPVX(current) == SvPVX(nsv)); + assert(SvPVX_readonly(current) == SvPVX_readonly(nsv)); } /* Make the SV before us point to the SV after us. */ if (DEBUG_C_TEST) { @@ -5961,7 +5961,7 @@ SvREFCNT_dec(SvRV(sv)); } #ifdef PERL_COPY_ON_WRITE - else if (SvPVX(sv)) { + else if (SvPVX_readonly(sv)) { if (SvIsCOW(sv)) { /* I believe I need to grab the global SV mutex here and then recheck the COW status. */ @@ -5969,19 +5969,19 @@ PerlIO_printf(Perl_debug_log, "Copy on write: clear\n"); sv_dump(sv); } - sv_release_COW(sv, SvPVX(sv), SvCUR(sv), SvLEN(sv), + sv_release_COW(sv, SvPVX_readonly(sv), SvCUR(sv), SvLEN(sv), SvUVX(sv), SV_COW_NEXT_SV(sv)); /* And drop it here. */ SvFAKE_off(sv); } else if (SvLEN(sv)) { - Safefree(SvPVX(sv)); + Safefree(SvPVX_readonly(sv)); } } #else - else if (SvPVX(sv) && SvLEN(sv)) - Safefree(SvPVX(sv)); - else if (SvPVX(sv) && SvREADONLY(sv) && SvFAKE(sv)) { - unsharepvn(SvPVX(sv), + else if (SvPVX_readonly(sv) && SvLEN(sv)) + Safefree(SvPVX_readonly(sv)); + else if (SvPVX_readonly(sv) && SvREADONLY(sv) && SvFAKE(sv)) { + unsharepvn(SvPVX_readonly(sv), SvUTF8(sv) ? -(I32)SvCUR(sv) : SvCUR(sv), SvUVX(sv)); SvFAKE_off(sv); @@ -7052,7 +7052,7 @@ } else shortbuffered = 0; - bp = (STDCHAR*)SvPVX(sv) + append; /* move these two too to registers */ + bp = (STDCHAR*)SvPVX_readonly(sv) + append; /* move these two too to registers */ ptr = (STDCHAR*)PerlIO_get_ptr(fp); DEBUG_P(PerlIO_printf(Perl_debug_log, "Screamer: entering, ptr=%"UVuf", cnt=%ld\n",PTR2UV(ptr),(long)cnt)); @@ -7081,10 +7081,10 @@ if (shortbuffered) { /* oh well, must extend */ cnt = shortbuffered; shortbuffered = 0; - bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */ + bpx = bp - (STDCHAR*)SvPVX_readonly(sv); /* box up before relocation */ SvCUR_set(sv, bpx); SvGROW(sv, SvLEN(sv) + append + cnt + 2); - bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */ + bp = (STDCHAR*)SvPVX_readonly(sv) + bpx; /* unbox after relocation */ continue; } @@ -7116,10 +7116,10 @@ if (i == EOF) /* all done for ever? */ goto thats_really_all_folks; - bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */ + bpx = bp - (STDCHAR*)SvPVX_readonly(sv); /* box up before relocation */ SvCUR_set(sv, bpx); SvGROW(sv, bpx + cnt + 2); - bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */ + bp = (STDCHAR*)SvPVX_readonly(sv) + bpx; /* unbox after relocation */ *bp++ = (STDCHAR)i; /* store character from PerlIO_getc */ @@ -7128,7 +7128,7 @@ } thats_all_folks: - if ((rslen > 1 && (STRLEN)(bp - (STDCHAR*)SvPVX(sv)) < rslen) || + if ((rslen > 1 && (STRLEN)(bp - (STDCHAR*)SvPVX_readonly(sv)) < rslen) || memNE((char*)bp - rslen, rsptr, rslen)) goto screamer; /* go back to the fray */ thats_really_all_folks: @@ -7142,10 +7142,10 @@ PTR2UV(PerlIO_get_ptr(fp)), (long)PerlIO_get_cnt(fp), PTR2UV(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0))); *bp = '\0'; - SvCUR_set(sv, bp - (STDCHAR*)SvPVX(sv)); /* set length */ + SvCUR_set(sv, bp - (STDCHAR*)SvPVX_readonly(sv)); /* set length */ DEBUG_P(PerlIO_printf(Perl_debug_log, "Screamer: done, len=%ld, string=|%.*s|\n", - (long)SvCUR(sv),(int)SvCUR(sv),SvPVX(sv))); + (long)SvCUR(sv),(int)SvCUR(sv),SvPVX_readonly(sv))); } else { @@ -7187,7 +7187,7 @@ if (i != EOF && /* joy */ (!rslen || SvCUR(sv) < rslen || - memNE(SvPVX(sv) + SvCUR(sv) - rslen, rsptr, rslen))) + memNE(SvPVX_readonly(sv) + SvCUR(sv) - rslen, rsptr, rslen))) { append = -1; /* @@ -7293,7 +7293,7 @@ return; } - if (!(flags & SVp_POK) || !*SvPVX(sv)) { + if (!(flags & SVp_POK) || !*SvPVX_readonly(sv)) { if ((flags & SVTYPEMASK) < SVt_PVIV) sv_upgrade(sv, SVt_IV); (void)SvIOK_only(sv); @@ -7308,7 +7308,7 @@ /* Got to punt this as an integer if needs be, but we don't issue warnings. Probably ought to make the sv_iv_please() that does the conversion if possible, and silently. */ - int numtype = grok_number(SvPVX(sv), SvCUR(sv), NULL); + int numtype = grok_number(SvPVX_readonly(sv), SvCUR(sv), NULL); if (numtype && !(numtype & IS_NUMBER_INFINITY)) { /* Need to try really hard to see if it's an integer. 9.22337203685478e+18 is an integer. @@ -7332,18 +7332,18 @@ Fall through. */ #if defined(USE_LONG_DOUBLE) DEBUG_c(PerlIO_printf(Perl_debug_log,"sv_inc punt failed to convert '%s' to IOK or NOKp, UV=0x%"UVxf" NV=%"PERL_PRIgldbl"\n", - SvPVX(sv), SvIVX(sv), SvNVX(sv))); + SvPVX_readonly(sv), SvIVX(sv), SvNVX(sv))); #else DEBUG_c(PerlIO_printf(Perl_debug_log,"sv_inc punt failed to convert '%s' to IOK or NOKp, UV=0x%"UVxf" NV=%"NVgf"\n", - SvPVX(sv), SvIVX(sv), SvNVX(sv))); + SvPVX_readonly(sv), SvIVX(sv), SvNVX(sv))); #endif } #endif /* PERL_PRESERVE_IVUV */ - sv_setnv(sv,Atof(SvPVX(sv)) + 1.0); + sv_setnv(sv,Atof(SvPVX_readonly(sv)) + 1.0); return; } d--; - while (d >= SvPVX(sv)) { + while (d >= SvPVX_readonly(sv)) { if (isDIGIT(*d)) { if (++*d <= '9') return; @@ -7373,7 +7373,7 @@ /* oh,oh, the number grew */ SvGROW(sv, SvCUR(sv) + 2); SvCUR_set(sv, SvCUR(sv) + 1); - for (d = SvPVX(sv) + SvCUR(sv); d > SvPVX(sv); d--) + for (d = SvPVX(sv) + SvCUR(sv); d > SvPVX_readonly(sv); d--) *d = d[-1]; if (isDIGIT(d[1])) *d = '1'; @@ -7456,7 +7456,7 @@ } #ifdef PERL_PRESERVE_IVUV { - int numtype = grok_number(SvPVX(sv), SvCUR(sv), NULL); + int numtype = grok_number(SvPVX_readonly(sv), SvCUR(sv), NULL); if (numtype && !(numtype & IS_NUMBER_INFINITY)) { /* Need to try really hard to see if it's an integer. 9.22337203685478e+18 is an integer. @@ -7480,15 +7480,15 @@ Fall through. */ #if defined(USE_LONG_DOUBLE) DEBUG_c(PerlIO_printf(Perl_debug_log,"sv_dec punt failed to convert '%s' to IOK or NOKp, UV=0x%"UVxf" NV=%"PERL_PRIgldbl"\n", - SvPVX(sv), SvIVX(sv), SvNVX(sv))); + SvPVX_readonly(sv), SvIVX(sv), SvNVX(sv))); #else DEBUG_c(PerlIO_printf(Perl_debug_log,"sv_dec punt failed to convert '%s' to IOK or NOKp, UV=0x%"UVxf" NV=%"NVgf"\n", - SvPVX(sv), SvIVX(sv), SvNVX(sv))); + SvPVX_readonly(sv), SvIVX(sv), SvNVX(sv))); #endif } } #endif /* PERL_PRESERVE_IVUV */ - sv_setnv(sv,Atof(SvPVX(sv)) - 1.0); /* punt */ + sv_setnv(sv,Atof(SvPVX_readonly(sv)) - 1.0); /* punt */ } /* @@ -7615,12 +7615,12 @@ /* =for apidoc newSVpvn_share -Creates a new SV with its SvPVX pointing to a shared string in the string +Creates a new SV with its SvPVX_readonly pointing to a shared string in the string table. If the string does not already exist in the table, it is created first. Turns on READONLY and FAKE. The string's hash is stored in the UV slot of the SV; if the C<hash> parameter is non-zero, that value is used; otherwise the hash is computed. The idea here is that as the string table -is used for shared hash keys these strings will have SvPVX == HeKEY and +is used for shared hash keys these strings will have SvPVX_readonly == HeKEY and hash lookup will avoid string compare. =cut @@ -7887,7 +7887,7 @@ SvOK_off(sv); if (SvTYPE(sv) >= SVt_PV) { SvCUR_set(sv, 0); - if (SvPVX(sv) != Nullch) + if (SvPVX_readonly(sv) != Nullch) *SvPVX(sv) = '\0'; SvTAINT(sv); } @@ -8228,14 +8228,14 @@ } else s = sv_2pv_flags(sv, lp, flags); - if (s != SvPVX(sv)) { /* Almost, but not quite, sv_setpvn() */ + if (s != SvPVX_readonly(sv)) { /* Almost, but not quite, sv_setpvn() */ STRLEN len = *lp; if (SvROK(sv)) sv_unref(sv); (void)SvUPGRADE(sv, SVt_PV); /* Never FALSE */ SvGROW(sv, len + 1); - Move(s,SvPVX(sv),len,char); + Move(s,SvPVX_readonly(sv),len,char); SvCUR_set(sv, len); *SvEND(sv) = '\0'; } @@ -8243,7 +8243,7 @@ SvPOK_on(sv); /* validate pointer */ SvTAINT(sv); DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%"UVxf" 2pv(%s)\n", - PTR2UV(sv),SvPVX(sv))); + PTR2UV(sv),SvPVX_readonly(sv))); } } return SvPVX(sv); @@ -9374,7 +9374,7 @@ vecstr = (U8*)SvPVx(vecsv,veclen); vec_utf8 = DO_UTF8(vecsv); /* if this is a version object, we need to return the - * stringified representation (which the SvPVX has + * stringified representation (which the SvPVX_readonly has * already done for us), but not vectorize the args */ if ( *q == 'd' && sv_derived_from(vecsv,"version") ) @@ -10027,7 +10027,7 @@ Copy(eptr, p, elen, char); p += elen; *p = '\0'; - SvCUR_set(sv, p - SvPVX(sv)); + SvCUR_set(sv, p - SvPVX_readonly(sv)); svix = osvix; continue; /* not "break" */ } @@ -10093,7 +10093,7 @@ if (has_utf8) SvUTF8_on(sv); *p = '\0'; - SvCUR_set(sv, p - SvPVX(sv)); + SvCUR_set(sv, p - SvPVX_readonly(sv)); if (vectorize) { esignlen = 0; goto vector; @@ -10607,11 +10607,11 @@ : sv_dup_inc(SvRV(sstr), param)); } - else if (SvPVX(sstr)) { + else if (SvPVX_readonly(sstr)) { /* Has something there */ if (SvLEN(sstr)) { /* Normal PV - clone whole allocated space */ - SvPV_set(dstr, SAVEPVN(SvPVX(sstr), SvLEN(sstr)-1)); + SvPV_set(dstr, SAVEPVN(SvPVX_readonly(sstr), SvLEN(sstr)-1)); if (SvREADONLY(sstr) && SvFAKE(sstr)) { /* Not that normal - actually sstr is copy on write. But we are a true, independant SV, so: */ @@ -10628,12 +10628,12 @@ and they should not have these flags turned off */ - SvPV_set(dstr, sharepvn(SvPVX(sstr), SvCUR(sstr), + SvPV_set(dstr, sharepvn(SvPVX_readonly(sstr), SvCUR(sstr), SvUVX(sstr))); SvUV_set(dstr, SvUVX(sstr)); } else { - SvPV_set(dstr, SAVEPVN(SvPVX(sstr), SvCUR(sstr))); + SvPV_set(dstr, SAVEPVN(SvPVX_readonly(sstr), SvCUR(sstr))); SvFAKE_off(dstr); SvREADONLY_off(dstr); } @@ -10701,9 +10701,9 @@ SvREFCNT(dstr) = 0; /* must be before any other dups! */ #ifdef DEBUGGING - if (SvANY(sstr) && PL_watch_pvx && SvPVX(sstr) == PL_watch_pvx) + if (SvANY(sstr) && PL_watch_pvx && SvPVX_readonly(sstr) == PL_watch_pvx) PerlIO_printf(Perl_debug_log, "watch at %p hit, found string \"%s\"\n", - PL_watch_pvx, SvPVX(sstr)); + PL_watch_pvx, SvPVX_readonly(sstr)); #endif /* don't clone objects whose class has asked us not to */ @@ -11943,7 +11943,7 @@ */ if (SvANY(proto_perl->Ilinestr)) { PL_linestr = sv_dup_inc(proto_perl->Ilinestr, param); - i = proto_perl->Ibufptr - SvPVX(proto_perl->Ilinestr); + i = proto_perl->Ibufptr - SvPVX_readonly(proto_perl->Ilinestr); PL_bufptr = SvPVX(PL_linestr) + (i < 0 ? 0 : i); i = proto_perl->Ioldbufptr - SvPVX(proto_perl->Ilinestr); PL_oldbufptr = SvPVX(PL_linestr) + (i < 0 ? 0 : i); @@ -11975,9 +11975,9 @@ /* XXX See comment on SvANY(proto_perl->Ilinestr) above */ if (SvANY(proto_perl->Ilinestr)) { - i = proto_perl->Ilast_uni - SvPVX(proto_perl->Ilinestr); + i = proto_perl->Ilast_uni - SvPVX_readonly(proto_perl->Ilinestr); PL_last_uni = SvPVX(PL_linestr) + (i < 0 ? 0 : i); - i = proto_perl->Ilast_lop - SvPVX(proto_perl->Ilinestr); + i = proto_perl->Ilast_lop - SvPVX_readonly(proto_perl->Ilinestr); PL_last_lop = SvPVX(PL_linestr) + (i < 0 ? 0 : i); PL_last_lop_op = proto_perl->Ilast_lop_op; } @@ -12354,9 +12354,9 @@ uni = POPs; PUTBACK; s = SvPV(uni, len); - if (s != SvPVX(sv)) { + if (s != SvPVX_readonly(sv)) { SvGROW(sv, len + 1); - Move(s, SvPVX(sv), len, char); + Move(s, SvPVX_readonly(sv), len, char); SvCUR_set(sv, len); SvPVX(sv)[len] = 0; } --- sv.h.old 2005-04-28 06:50:19.000000000 -0500 +++ sv.h 2005-05-04 18:57:01.495963640 -0500 @@ -853,7 +853,7 @@ } \ } \ } STMT_END - +#define SvPVX_readonly(sv) (const char*)SvPVX(sv) #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous --- toke.c.old 2005-04-25 03:14:16.000000000 -0500 +++ toke.c 2005-05-05 00:19:22.578672144 -0500 @@ -487,7 +487,7 @@ static void strip_return(SV *sv) { - register char *s = SvPVX(sv); + register char *s = SvPVX_readonly(sv); register char *e = s + SvCUR(sv); /* outer loop optimized to do nothing if there are no CR-LFs */ while (s < e) { @@ -1060,7 +1060,7 @@ goto finish; d = s; if ( PL_hints & HINT_NEW_STRING ) { - pv = sv_2mortal(newSVpvn(SvPVX(pv), len)); + pv = sv_2mortal(newSVpvn(SvPVX_readonly(pv), len)); if (SvUTF8(sv)) SvUTF8_on(pv); } @@ -1072,7 +1072,7 @@ *d++ = *s++; } *d = '\0'; - SvCUR_set(sv, d - SvPVX(sv)); + SvCUR_set(sv, d - SvPVX_readonly(sv)); finish: if ( PL_hints & HINT_NEW_STRING ) return new_constant(NULL, 0, "q", sv, pv, "q"); @@ -1401,7 +1401,7 @@ continue; } - i = d - SvPVX(sv); /* remember current offset */ + i = d - SvPVX_readonly(sv); /* remember current offset */ SvGROW(sv, SvLEN(sv) + 256); /* never more than 256 chars in a range */ d = SvPVX(sv) + i; /* refresh d after realloc */ d -= 2; /* eat the first char and the - */ @@ -1622,19 +1622,19 @@ */ int hicount = 0; U8 *c; - for (c = (U8 *) SvPVX(sv); c < (U8 *)d; c++) { + for (c = (U8 *) SvPVX_readonly(sv); c < (U8 *)d; c++) { if (!NATIVE_IS_INVARIANT(*c)) { hicount++; } } if (hicount) { - STRLEN offset = d - SvPVX(sv); + STRLEN offset = d - SvPVX_readonly(sv); U8 *src, *dst; d = SvGROW(sv, SvLEN(sv) + hicount + 1) + offset; src = (U8 *)d - 1; dst = src+hicount; d += hicount; - while (src >= (U8 *)SvPVX(sv)) { + while (src >= (U8 *)SvPVX_readonly(sv)) { if (!NATIVE_IS_INVARIANT(*src)) { U8 ch = NATIVE_TO_ASCII(*src); *dst-- = (U8)UTF8_EIGHT_BIT_LO(ch); @@ -1718,7 +1718,7 @@ } #endif if (!has_utf8 && SvUTF8(res)) { - char *ostart = SvPVX(sv); + const char *ostart = SvPVX_readonly(sv); SvCUR_set(sv, d - ostart); SvPOK_on(sv); *d = '\0'; @@ -1729,7 +1729,7 @@ has_utf8 = TRUE; } if (len > (STRLEN)(e - s + 4)) { /* I _guess_ 4 is \N{} --jhi */ - char *odest = SvPVX(sv); + const char *odest = SvPVX_readonly(sv); SvGROW(sv, (SvLEN(sv) + len - (e - s + 4))); d = SvPVX(sv) + (d - odest); @@ -1798,7 +1798,7 @@ s += len; if (need > len) { /* encoded value larger than old, need extra space (NOTE: SvCUR() not set here) */ - STRLEN off = d - SvPVX(sv); + STRLEN off = d - SvPVX_readonly(sv); d = SvGROW(sv, SvLEN(sv) + (need-len)) + off; } d = (char*)uvchr_to_utf8((U8*)d, uv); @@ -1811,7 +1811,7 @@ /* terminate the string and set up the sv */ *d = '\0'; - SvCUR_set(sv, d - SvPVX(sv)); + SvCUR_set(sv, d - SvPVX_readonly(sv)); if (SvCUR(sv) >= SvLEN(sv)) Perl_croak(aTHX_ "panic: constant overflowed allocated space"); @@ -2038,7 +2038,7 @@ if (GvIO(gv)) return 0; if ((cv = GvCVu(gv))) { - char *proto = SvPVX(cv); + const char *proto = SvPVX_readonly(cv); if (proto) { if (*proto == ';') proto++; @@ -4161,7 +4161,7 @@ yylval.opval->op_private = OPpCONST_BARE; /* UTF-8 package name? */ if (UTF && !IN_BYTES && - is_utf8_string((U8*)SvPVX(sv), SvCUR(sv))) + is_utf8_string((U8*)SvPVX_readonly(sv), SvCUR(sv))) SvUTF8_on(sv); /* And if "Foo::", then that's what it certainly is. */ @@ -5595,7 +5595,7 @@ */ I32 -Perl_keyword (pTHX_ char *name, I32 len) +Perl_keyword (pTHX_ const char *name, I32 len) { switch (len) { @@ -8973,7 +8973,7 @@ msg = Perl_newSVpvf(aTHX_ "Constant(%s): %s%s%s", (type ? type: "undef"), why1, why2, why3); msgdone: - yyerror(SvPVX(msg)); + yyerror(SvPVX_readonly(msg)); SvREFCNT_dec(msg); return sv; } @@ -9484,7 +9484,7 @@ } *d = '\0'; PL_bufend = d; - SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); + SvCUR_set(PL_linestr, PL_bufend - SvPVX_readonly(PL_linestr)); s = olds; } #endif @@ -9533,7 +9533,7 @@ sv_setpvn(tmpstr,d+1,s-d); s += len - 1; sv_catpvn(herewas,s,bufend-s); - Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char); + Copy(SvPVX_readonly(herewas),bufptr,SvCUR(herewas) + 1,char); s = olds; goto retval; @@ -9577,7 +9577,7 @@ { PL_bufend[-2] = '\n'; PL_bufend--; - SvCUR_set(PL_linestr, PL_bufend - SvPVX(PL_linestr)); + SvCUR_set(PL_linestr, PL_bufend - SvPVX_readonly(PL_linestr)); } else if (PL_bufend[-1] == '\r') PL_bufend[-1] = '\n'; @@ -9595,7 +9595,7 @@ av_store(CopFILEAV(PL_curcop), (I32)CopLINE(PL_curcop),sv); } if (*s == term && memEQ(s,PL_tokenbuf,len)) { - STRLEN off = PL_bufend - 1 - SvPVX(PL_linestr); + STRLEN off = PL_bufend - 1 - SvPVX_readonly(PL_linestr); *(SvPVX(PL_linestr) + off ) = ' '; sv_catsv(PL_linestr,herewas); PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr); @@ -9614,7 +9614,7 @@ } SvREFCNT_dec(herewas); if (!IN_BYTES) { - if (UTF && is_utf8_string((U8*)SvPVX(tmpstr), SvCUR(tmpstr))) + if (UTF && is_utf8_string((U8*)SvPVX_readonly(tmpstr), SvCUR(tmpstr))) SvUTF8_on(tmpstr); else if (PL_encoding) sv_recode_to_utf8(tmpstr, PL_encoding); @@ -9888,10 +9888,10 @@ bool cont = TRUE; while (cont) { - int offset = s - SvPVX(PL_linestr); + int offset = s - SvPVX_readonly(PL_linestr); bool found = sv_cat_decode(sv, PL_encoding, PL_linestr, &offset, (char*)termstr, termlen); - char *ns = SvPVX(PL_linestr) + offset; + const char *ns = SvPVX_readonly(PL_linestr) + offset; char *svlast = SvEND(sv) - 1; for (; s < ns; s++) { @@ -9904,7 +9904,7 @@ /* handle quoted delimiters */ if (SvCUR(sv) > 1 && *(svlast-1) == '\\') { char *t; - for (t = svlast-2; t >= SvPVX(sv) && *t == '\\';) + for (t = svlast-2; t >= SvPVX_readonly(sv) && *t == '\\';) t--; if ((svlast-1 - t) % 2) { if (!keep_quoted) { @@ -9939,7 +9939,7 @@ if (w < t) { *w++ = term; *w = '\0'; - SvCUR_set(sv, w - SvPVX(sv)); + SvCUR_set(sv, w - SvPVX_readonly(sv)); } last = w; if (--brackets <= 0) @@ -10017,7 +10017,7 @@ } /* terminate the copied string and update the sv's end-of-string */ *to = '\0'; - SvCUR_set(sv, to - SvPVX(sv)); + SvCUR_set(sv, to - SvPVX_readonly(sv)); /* * this next chunk reads more into the buffer if we're not done yet @@ -10027,18 +10027,18 @@ break; /* handle case where we are done yet :-) */ #ifndef PERL_STRICT_CR - if (to - SvPVX(sv) >= 2) { + if (to - SvPVX_readonly(sv) >= 2) { if ((to[-2] == '\r' && to[-1] == '\n') || (to[-2] == '\n' && to[-1] == '\r')) { to[-2] = '\n'; to--; - SvCUR_set(sv, to - SvPVX(sv)); + SvCUR_set(sv, to - SvPVX_readonly(sv)); } else if (to[-1] == '\r') to[-1] = '\n'; } - else if (to - SvPVX(sv) == 1 && to[-1] == '\r') + else if (to - SvPVX_readonly(sv) == 1 && to[-1] == '\r') to[-1] = '\n'; #endif @@ -10579,7 +10579,7 @@ else PL_lex_state = LEX_FORMLINE; if (!IN_BYTES) { - if (UTF && is_utf8_string((U8*)SvPVX(stuff), SvCUR(stuff))) + if (UTF && is_utf8_string((U8*)SvPVX_readonly(stuff), SvCUR(stuff))) SvUTF8_on(stuff); else if (PL_encoding) sv_recode_to_utf8(stuff, PL_encoding); @@ -10705,7 +10705,7 @@ Perl_sv_catpvf(aTHX_ where_sv, "%c", yychar); else Perl_sv_catpvf(aTHX_ where_sv, "\\%03o", yychar & 255); - where = SvPVX(where_sv); + where = SvPVX_readonly(where_sv); } msg = sv_2mortal(newSVpv(s, 0)); Perl_sv_catpvf(aTHX_ msg, " at %s line %"IVdf", ", @@ -10767,7 +10767,7 @@ sv_setpvn(PL_linestr, (const char*)news, newlen); Safefree(news); SvUTF8_on(PL_linestr); - s = (U8*)SvPVX(PL_linestr); + s = (U8*)SvPVX_readonly(PL_linestr); PL_bufend = SvPVX(PL_linestr) + newlen; } #else @@ -10793,7 +10793,7 @@ sv_setpvn(PL_linestr, (const char*)news, newlen); Safefree(news); SvUTF8_on(PL_linestr); - s = (U8*)SvPVX(PL_linestr); + s = (U8*)SvPVX_readonly(PL_linestr); PL_bufend = SvPVX(PL_linestr) + newlen; } #else @@ -10865,8 +10865,8 @@ U8* tmps; I32 newlen; New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); - Copy(SvPVX(sv), tmps, old, char); - utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, + Copy(SvPVX_readonly(sv), tmps, old, char); + utf16_to_utf8((U8*)SvPVX_readonly(sv) + old, tmps + old, SvCUR(sv) - old, &newlen); sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); } @@ -10886,8 +10886,8 @@ U8* tmps; I32 newlen; New(898, tmps, SvCUR(sv) * 3 / 2 + 1, U8); - Copy(SvPVX(sv), tmps, old, char); - utf16_to_utf8((U8*)SvPVX(sv) + old, tmps + old, + Copy(SvPVX_readonly(sv), tmps, old, char); + utf16_to_utf8((U8*)SvPVX_readonly(sv) + old, tmps + old, SvCUR(sv) - old, &newlen); sv_usepvn(sv, (char*)tmps, (STRLEN)newlen + old); } --- universal.c.old 2005-05-03 03:05:56.000000000 -0500 +++ universal.c 2005-05-05 00:19:22.578672144 -0500 @@ -881,9 +881,9 @@ if (details) { XPUSHs(namok ? - newSVpv(SvPVX(*namsvp), 0) : &PL_sv_undef); + newSVpv(SvPVX_readonly(*namsvp), 0) : &PL_sv_undef); XPUSHs(argok ? - newSVpv(SvPVX(*argsvp), 0) : &PL_sv_undef); + newSVpv(SvPVX_readonly(*argsvp), 0) : &PL_sv_undef); if (flgok) XPUSHi(SvIVX(*flgsvp)); else --- utf8.c.old 2005-04-21 11:05:32.000000000 -0500 +++ utf8.c 2005-05-05 00:19:22.578672144 -0500 @@ -521,7 +521,7 @@ } if (warning) { - char *s = SvPVX(sv); + const char *s = SvPVX_readonly(sv); if (PL_op) Perl_warner(aTHX_ packWARN(WARN_UTF8), @@ -1917,7 +1917,7 @@ char * Perl_sv_uni_display(pTHX_ SV *dsv, SV *ssv, STRLEN pvlim, UV flags) { - return Perl_pv_uni_display(aTHX_ dsv, (U8*)SvPVX(ssv), SvCUR(ssv), + return Perl_pv_uni_display(aTHX_ dsv, (U8*)SvPVX_readonly(ssv), SvCUR(ssv), pvlim, flags); } --- util.c.old 2005-05-04 19:46:59.252235416 -0500 +++ util.c 2005-05-05 00:26:51.857371400 -0500 @@ -387,7 +387,7 @@ else mlen = (U8)len; Sv_Grow(sv, len + 256 + FBM_TABLE_OFFSET); - table = (unsigned char*)(SvPVX(sv) + len + FBM_TABLE_OFFSET); + table = (unsigned char*)(SvPVX_readonly(sv) + len + FBM_TABLE_OFFSET); s = table - 1 - FBM_TABLE_OFFSET; /* last char */ memset((void*)table, mlen, 256); table[-1] = (U8)flags; @@ -402,7 +402,7 @@ sv_magic(sv, Nullsv, PERL_MAGIC_bm, Nullch, 0); /* deep magic */ SvVALID_on(sv); - s = (unsigned char*)(SvPVX(sv)); /* deeper magic */ + s = (unsigned char*)(SvPVX_readonly(sv)); /* deeper magic */ for (i = 0; i < len; i++) { if (PL_freq[s[i]] < frequency) { rarest = i; @@ -648,7 +648,7 @@ cant_find: if ( BmRARE(littlestr) == '\n' && BmPREVIOUS(littlestr) == SvCUR(littlestr) - 1) { - little = (unsigned char *)(SvPVX(littlestr)); + little = (unsigned char *)(SvPVX_readonly(littlestr)); littleend = little + SvCUR(littlestr); first = *little++; goto check_tail; @@ -656,12 +656,12 @@ return Nullch; } - little = (unsigned char *)(SvPVX(littlestr)); + little = (unsigned char *)(SvPVX_readonly(littlestr)); littleend = little + SvCUR(littlestr); first = *little++; /* The value of pos we can start at: */ previous = BmPREVIOUS(littlestr); - big = (unsigned char *)(SvPVX(bigstr)); + big = (unsigned char *)(SvPVX_readonly(bigstr)); /* The value of pos we can stop at: */ stop_pos = SvCUR(bigstr) - end_shift - (SvCUR(littlestr) - 1 - previous); if (previous + start_shift > stop_pos) { @@ -702,7 +702,7 @@ if (!SvTAIL(littlestr) || (end_shift > 0)) return Nullch; /* Ignore the trailing "\n". This code is not microoptimized */ - big = (unsigned char *)(SvPVX(bigstr) + SvCUR(bigstr)); + big = (unsigned char *)(SvPVX_readonly(bigstr) + SvCUR(bigstr)); stop_pos = littleend - little; /* Actual littlestr len */ if (stop_pos == 0) return (char*)big; @@ -1008,7 +1008,7 @@ OutCopFILE(cop), (IV)CopLINE(cop)); if (GvIO(PL_last_in_gv) && IoLINES(GvIOp(PL_last_in_gv))) { const bool line_mode = (RsSIMPLE(PL_rs) && - SvCUR(PL_rs) == 1 && *SvPVX(PL_rs) == '\n'); + SvCUR(PL_rs) == 1 && *SvPVX_readonly(PL_rs) == '\n'); Perl_sv_catpvf(aTHX_ sv, ", <%s> %s %"IVdf, PL_last_in_gv == PL_argvgv ? "" : GvNAME(PL_last_in_gv), @@ -2732,13 +2732,13 @@ sv_setpv(tmpsv, "."); else sv_setpvn(tmpsv, a, fa - a); - if (PerlLIO_stat(SvPVX(tmpsv), &tmpstatbuf1) < 0) + if (PerlLIO_stat(SvPVX_readonly(tmpsv), &tmpstatbuf1) < 0) return FALSE; if (fb == b) sv_setpv(tmpsv, "."); else sv_setpvn(tmpsv, b, fb - b); - if (PerlLIO_stat(SvPVX(tmpsv), &tmpstatbuf2) < 0) + if (PerlLIO_stat(SvPVX_readonly(tmpsv), &tmpstatbuf2) < 0) return FALSE; return tmpstatbuf1.st_dev == tmpstatbuf2.st_dev && tmpstatbuf1.st_ino == tmpstatbuf2.st_ino; @@ -3766,12 +3766,12 @@ if (pathlen) { /* shift down */ - Move(SvPVX(sv), SvPVX(sv) + namelen + 1, pathlen, char); + Move(SvPVX_readonly(sv), SvPVX_readonly(sv) + namelen + 1, pathlen, char); } /* prepend current directory to the front */ - *SvPVX(sv) = '/'; - Move(dp->d_name, SvPVX(sv)+1, namelen, char); + *SvPVX_readonly(sv) = '/'; + Move(dp->d_name, SvPVX_readonly(sv)+1, namelen, char); pathlen += (namelen + 1); #ifdef VOID_CLOSEDIR @@ -3788,7 +3788,7 @@ *SvEND(sv) = '\0'; SvPOK_only(sv); - if (PerlDir_chdir(SvPVX(sv)) < 0) { + if (PerlDir_chdir(SvPVX_readonly(sv)) < 0) { SV_CWD_RETURN_UNDEF; } } --tThc/1wpZn/ma/RB--