[PATCH] SvPVX_const - patch #2

--OXfL5xGRrasGEqWY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Attached is the second in a series of patches to convert read-only 
usage of SvPVX() to using SvPVX_const() instead.  This patch includes
changes to:

dump.c
gv.c
op.c
pad.c
perlio.c
perly.c
pp.c
pp_ctl.c

The next patch should take care of the remaining core C code.  sv.c is 
easily the most affected by these changes, and will be in the next patch.
The core-only modules will be modified in the following patch.

Steve Peters
steve@fisharerojo.org

--OXfL5xGRrasGEqWY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="svpvx_const2.patch"

--- dump.c.old	Mon May 16 12:23:31 2005
+++ dump.c	Wed May 18 16:55:43 2005
@@ -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_const(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_const(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_const(sv) && *SvPVX_const(sv) == '1' &&
 		SvNVX(sv) == 1.0)
 		goto finish;
 	}
@@ -297,14 +297,14 @@
     }
 
     if (SvPOKp(sv)) {
-	if (!SvPVX(sv))
+	if (!SvPVX_const(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_const(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
+	    Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX_const(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_const(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_const(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_const(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_const(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_const(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_const(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_const(sv)) {
+	    Perl_dump_indent(aTHX_ level, file,"  PV = 0x%"UVxf" ", PTR2UV(SvPVX_const(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_const(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
+	    PerlIO_printf(file, "%s", pv_display(d, SvPVX_const(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_const(d) + 1 : "");
 	if (nest < maxnest && av_len((AV*)sv) >= 0) {
 	    int count;
 	    for (count = 0; count <=  av_len((AV*)sv) && count < maxnest; count++) {
--- gv.c.old	Wed May 11 03:24:13 2005
+++ gv.c	Wed May 18 17:04:31 2005
@@ -111,7 +111,7 @@
     dVAR;
     register GP *gp;
     const bool doproto = SvTYPE(gv) > SVt_NULL;
-    const char * const proto = (doproto && SvPOK(gv)) ? SvPVX(gv) : NULL;
+    const char * const proto = (doproto && SvPOK(gv)) ? SvPVX_const(gv) : NULL;
 
     sv_upgrade((SV*)gv, SVt_PVGV);
     if (SvLEN(gv)) {
@@ -120,7 +120,7 @@
 	    SvLEN_set(gv, 0);
 	    SvPOK_off(gv);
 	} else
-	    Safefree(SvPVX(gv));
+	    Safefree(SvPVX_const(gv));
     }
     Newz(602, gp, 1, GP);
     GvGP(gv) = gp_ref(gp);
@@ -433,7 +433,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_const(tmpstr), SvCUR(tmpstr), TRUE);
 	    DEBUG_o( Perl_deb(aTHX_ "Treating %s as %s::%s\n",
 			 origname, HvNAME(stash), name) );
 	}
@@ -1411,12 +1411,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_const(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_const(gvsv) : "???";
 		    Perl_croak(aTHX_ "%s method `%.256s' overloading `%s' "\
 				"in package `%.256s'",
 			       (GvCVGEN(gv) ? "Stub found while resolving"
@@ -1703,7 +1703,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_const(msg)) );
 	} else {
 	  Perl_croak(aTHX_ "%"SVf, msg);
 	}
--- op.c.old	Tue May 17 10:44:22 2005
+++ op.c	Wed May 18 17:27:54 2005
@@ -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_const(sv), "di", 2) ||
+			strnEQ(SvPVX_const(sv), "ds", 2) ||
+			strnEQ(SvPVX_const(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_const(meth), SvCUR(meth));
 	SvUV_set(meth, hash);
     }
     imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL|OPf_WANT_VOID,
@@ -3038,7 +3038,7 @@
 	    (void)SvIOK_on(meth);
 	    {
 		U32 hash;
-		PERL_HASH(hash, SvPVX(meth), SvCUR(meth));
+		PERL_HASH(hash, SvPVX_const(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_const(meth), SvCUR(meth));
 	    SvUV_set(meth, hash);
 	}
 	imop = convert(OP_ENTERSUB, OPf_STACKED|OPf_SPECIAL,
@@ -4082,7 +4082,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_const(cv)))) && ckWARN_d(WARN_PROTOTYPE)) {
 	SV* msg = sv_newmortal();
 	SV* name = Nullsv;
 
@@ -4251,7 +4251,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_const(sv);
     }
     else
 	aname = Nullch;
@@ -4501,9 +4501,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_const(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_const(tmpstr), SvCUR(tmpstr))
 		&& (pcv = GvCV(db_postponed)))
 	    {
 		dSP;
@@ -5837,10 +5837,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_const(sv), ':') || strchr(SvPVX_const(sv), '\''))) {
 	    OP *cmop;
 	    if (!SvREADONLY(sv) || !SvFAKE(sv)) {
-		sv = newSVpvn_share(SvPVX(sv), SvCUR(sv), 0);
+		sv = newSVpvn_share(SvPVX_const(sv), SvCUR(sv), 0);
 	    }
 	    else {
 		kSVOP->op_sv = Nullsv;
@@ -5892,7 +5892,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) &&
@@ -5900,7 +5900,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_const(((SVOP*)oa)->op_sv)) &&
 	     mode[0] == '>' && mode[1] == '&' &&	/* A dup open. */
 	     (last == oa->op_sibling))			/* The bareword. */
 	      last->op_private &= ~OPpCONST_STRICT;
@@ -6675,7 +6675,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_const(GvCV(gv))) {
 		    /* XXX could check prototype here instead of just carping */
 		    SV *sv = sv_newmortal();
 		    gv_efullname3(sv, gv, Nullch);
--- pad.c.old	Wed May 11 03:24:13 2005
+++ pad.c	Wed May 18 17:32:16 2005
@@ -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_const(namesv) == '&')
 	    {
 		CV * const innercv = (CV*)curpad[ix];
 		U32 inner_rc = SvREFCNT(innercv);
@@ -517,7 +517,7 @@
 	    && (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
 	    && (!is_our
 		|| ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash))
-	    && strEQ(name, SvPVX(sv)))
+	    && strEQ(name, SvPVX_const(sv)))
 	{
 	    Perl_warner(aTHX_ packWARN(WARN_MISC),
 		"\"%s\" variable %s masks earlier declaration in same %s",
@@ -536,7 +536,7 @@
 		&& !SvFAKE(sv)
 		&& (SvIVX(sv) == PAD_MAX || SvIVX(sv) == 0)
 		&& ((SvFLAGS(sv) & SVpad_OUR) && GvSTASH(sv) == ourstash)
-		&& strEQ(name, SvPVX(sv)))
+		&& strEQ(name, SvPVX_const(sv)))
 	    {
 		Perl_warner(aTHX_ packWARN(WARN_MISC),
 		    "\"our\" variable %s redeclared", name);
@@ -586,7 +586,7 @@
 	if (namesv && namesv != &PL_sv_undef
 	    && !SvFAKE(namesv)
 	    && (SvFLAGS(namesv) & SVpad_OUR)
-	    && strEQ(SvPVX(namesv), name)
+	    && strEQ(SvPVX_const(namesv), name)
 	    && U_32(SvNVX(namesv)) == PAD_MAX /* min */
 	)
 	    return offset;
@@ -669,7 +669,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_const(namesv), name))
 	    {
 		if (SvFAKE(namesv))
 		    fake_offset = offset; /* in case we don't find a real one */
@@ -816,7 +816,7 @@
 	PL_curpad = AvARRAY(PL_comppad);
 
 	new_offset = pad_add_name(
-	    SvPVX(*out_name_sv),
+	    SvPVX_const(*out_name_sv),
 	    (SvFLAGS(*out_name_sv) & SVpad_TYPED)
 		    ? SvSTASH(*out_name_sv) : Nullhv,
 	    (SvFLAGS(*out_name_sv) & SVpad_OUR)
@@ -966,7 +966,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_const(sv),
 		(long)U_32(SvNVX(sv)), (long)SvIVX(sv))
 	    );
 	}
@@ -1015,7 +1015,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_const(sv),
 		(long)U_32(SvNVX(sv)), (long)SvIVX(sv))
 	    );
 	}
@@ -1168,7 +1168,7 @@
 	     */
 	    if (!((namesv = namep[ix]) != Nullsv &&
 		  namesv != &PL_sv_undef &&
-		   *SvPVX(namesv) == '&'))
+		   *SvPVX_const(namesv) == '&'))
 	    {
 		SvREFCNT_dec(PL_curpad[ix]);
 		PL_curpad[ix] = Nullsv;
@@ -1289,7 +1289,7 @@
 		    (int) ix,
 		    PTR2UV(ppad[ix]),
 		    (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0),
-		    SvPVX(namesv),
+		    SvPVX_const(namesv),
 		    (unsigned long)SvIVX(namesv),
 		    (unsigned long)SvNVX(namesv)
 
@@ -1302,7 +1302,7 @@
 		    (unsigned long) (ppad[ix] ? SvREFCNT(ppad[ix]) : 0),
 		    (long)U_32(SvNVX(namesv)),
 		    (long)SvIVX(namesv),
-		    SvPVX(namesv)
+		    SvPVX_const(namesv)
 		);
 	}
 	else if (full) {
@@ -1425,7 +1425,7 @@
     CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(proto);
 
     if (SvPOK(proto))
-	sv_setpvn((SV*)cv, SvPVX(proto), SvCUR(proto));
+	sv_setpvn((SV*)cv, SvPVX_const(proto), SvCUR(proto));
 
     CvPADLIST(cv) = pad_new(padnew_CLONE|padnew_SAVE);
 
@@ -1448,7 +1448,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_const(namesv));
 		    sv = Nullsv;
 		}
 		else {
@@ -1457,7 +1457,7 @@
 		}
 	    }
 	    if (!sv) {
-                const char sigil = SvPVX(namesv)[0];
+                const char sigil = SvPVX_const(namesv)[0];
                 if (sigil == '&')
 		    sv = SvREFCNT_inc(ppad[ix]);
                 else if (sigil == '@')
@@ -1529,7 +1529,7 @@
     for (ix = AvFILLp(comppad_name); ix > 0; ix--) {
         const SV *namesv = namepad[ix];
 	if (namesv && namesv != &PL_sv_undef
-	    && *SvPVX(namesv) == '&')
+	    && *SvPVX_const(namesv) == '&')
 	{
 	    CV *innercv = (CV*)curpad[ix];
 	    assert(CvWEAKOUTSIDE(innercv));
@@ -1567,7 +1567,7 @@
 
 	for ( ;ix > 0; ix--) {
 	    if (names_fill >= ix && names[ix] != &PL_sv_undef) {
-		const char sigil = SvPVX(names[ix])[0];
+		const char sigil = SvPVX_const(names[ix])[0];
 		if ((SvFLAGS(names[ix]) & SVf_FAKE) || sigil == '&') {
 		    /* outer lexical or anon code */
 		    av_store(newpad, ix, SvREFCNT_inc(oldpad[ix]));
--- perlio.c.old	Wed May 11 03:24:14 2005
+++ perlio.c	Wed May 18 17:34:48 2005
@@ -4892,7 +4892,7 @@
 	  f = PerlIO_fdopen(fd, "w+");
 	  if (f)
 	       PerlIOBase(f)->flags |= PERLIO_F_TEMP;
-	  PerlLIO_unlink(SvPVX(sv));
+	  PerlLIO_unlink(SvPVX_const(sv));
 	  SvREFCNT_dec(sv);
      }
 #    else	/* !HAS_MKSTEMP, fallback to stdio tmpfile(). */
--- perly.c.old	Wed May 11 03:24:14 2005
+++ perly.c	Wed May 18 17:37:16 2005
@@ -322,7 +322,7 @@
 #ifdef DEBUGGING
     yyns_sv = NEWSV(73, YYINITDEPTH * sizeof(char *));
     SAVEFREESV(yyns_sv);
-    yyns = (const char **) SvPVX(yyns_sv);
+    yyns = SvPVX_const(yyns_sv);
     yynsp = yyns;
 #endif
 
@@ -366,7 +366,7 @@
 	 yyvs = (YYSTYPE *) SvPVX(yyvs_sv);
 #ifdef DEBUGGING
 	 SvGROW(yyns_sv, yystacksize * sizeof(char *));
-	 yyns = (const char **) SvPVX(yyns_sv);
+	 yyns = SvPVX_const(yyns_sv);
 	 if (! yyns)
 	       goto yyoverflowlab;
 	 yynsp = yyns + yysize - 1;
--- pp.c.old	Wed May 11 03:24:14 2005
+++ pp.c	Wed May 18 17:40:34 2005
@@ -181,7 +181,7 @@
 		    }
 		    if (SvTYPE(sv) < SVt_RV)
 			sv_upgrade(sv, SVt_RV);
-		    if (SvPVX(sv)) {
+		    if (SvPVX_const(sv)) {
 			SvPV_free(sv);
 			SvLEN_set(sv, 0);
                         SvCUR_set(sv, 0);
@@ -376,7 +376,7 @@
 
     ret = &PL_sv_undef;
     if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) {
-	const char *s = SvPVX(TOPs);
+	const char *s = SvPVX_const(TOPs);
 	if (strnEQ(s, "CORE::", 6)) {
 	    const int code = keyword(s + 6, SvCUR(TOPs) - 6);
 	    if (code < 0) {	/* Overridable. */
@@ -427,7 +427,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_const(cv), SvCUR(cv)));
   set:
     SETs(ret);
     RETURN;
@@ -826,7 +826,7 @@
 	}
 	break;
     default:
-	if (SvTYPE(sv) >= SVt_PV && SvPVX(sv) && SvLEN(sv)) {
+	if (SvTYPE(sv) >= SVt_PV && SvPVX_const(sv) && SvLEN(sv)) {
 	    SvPV_free(sv);
 	    SvPV_set(sv, Nullch);
 	    SvLEN_set(sv, 0);
--- pp_ctl.c.old	Mon May 16 12:23:32 2005
+++ pp_ctl.c	Wed May 18 17:53:07 2005
@@ -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_const(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_const(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_const(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_const(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_const(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_const(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_const(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_const(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_const(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_const(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_const(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_const(nsv), SvCUR(nsv),
                                &PL_sv_undef, 0);
 		DIE(aTHX_ "%sCompilation failed in require",
 		    *msg ? msg : "Unknown error\n");
@@ -1971,7 +1971,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_const(nsv), SvCUR(nsv), G_DISCARD);
 	    DIE(aTHX_ "%"SVf" did not return a true value", nsv);
 	}
 	break;
@@ -2658,8 +2658,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_const(sv);
+    register const char *send = SvPVX_const(sv) + SvCUR(sv);
     register I32 line = 1;
 
     while (s && s < send) {
@@ -2942,7 +2942,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_const(nsv), SvCUR(nsv),
                           &PL_sv_undef, 0);
 	    DIE(aTHX_ "%sCompilation failed in require",
 		*msg ? msg : "Unknown error\n");
@@ -3298,9 +3298,9 @@
 		AV *ar = GvAVn(PL_incgv);
 		I32 i;
 		sv_catpvn(msg, " in @INC", 8);
-		if (instr(SvPVX(msg), ".h "))
+		if (instr(SvPVX_const(msg), ".h "))
 		    sv_catpv(msg, " (change .h to .ph maybe?)");
-		if (instr(SvPVX(msg), ".ph "))
+		if (instr(SvPVX_const(msg), ".ph "))
 		    sv_catpv(msg, " (did you run h2ph?)");
 		sv_catpv(msg, " (@INC contains:");
 		for (i = 0; i <= AvFILL(ar); i++) {
@@ -3526,7 +3526,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_const(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 */
     }

--OXfL5xGRrasGEqWY--
0
steve
5/21/2005 2:42:10 AM
perl.perl5.porters 48287 articles. 1 followers. Follow

1 Replies
440 Views

Similar Articles

[PageSpeed] 9

At 2005-05-20 21:42:10 -0500, steve@fisharerojo.org wrote:
>
> Attached is the second in a series of patches to convert read-only
> usage of SvPVX() to using SvPVX_const() instead.

Thanks, applied. (#24523)

-- ams
0
ams
5/21/2005 3:25:06 AM
Reply: