summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2008-10-29 21:57:34 +0000
committerNicholas Clark <nick@ccl4.org>2008-10-29 21:57:34 +0000
commitea726b52599b52cf534201a46ec3455418c9eb8e (patch)
tree4206fe1b3aea75154b82cac19301cc56345b63a4
parent126f53f392147cb95f8643714b33fe373747680a (diff)
downloadperl-ea726b52599b52cf534201a46ec3455418c9eb8e.tar.gz
Add MUTABLE_CV(), and eliminate (CV *) casts in *.c.
p4raw-id: //depot/perl@34647
-rw-r--r--gv.c4
-rw-r--r--handy.h1
-rw-r--r--mg.c2
-rw-r--r--op.c4
-rw-r--r--pad.c16
-rw-r--r--perl.c6
-rw-r--r--pp.c19
-rw-r--r--pp_ctl.c6
-rw-r--r--pp_hot.c4
-rw-r--r--pp_sort.c2
-rw-r--r--pp_sys.c4
-rw-r--r--sv.c18
-rw-r--r--toke.c6
-rw-r--r--xsutils.c16
14 files changed, 55 insertions, 53 deletions
diff --git a/gv.c b/gv.c
index 9d3730851b..7d737de22c 100644
--- a/gv.c
+++ b/gv.c
@@ -1764,10 +1764,10 @@ Perl_Gv_AMupdate(pTHX_ HV *stash)
if (i < DESTROY_amg)
have_ovl = 1;
} else if (gv) { /* Autoloaded... */
- cv = (CV*)gv;
+ cv = MUTABLE_CV(gv);
filled = 1;
}
- amt.table[i]=(CV*)SvREFCNT_inc_simple(cv);
+ amt.table[i]=MUTABLE_CV(SvREFCNT_inc_simple(cv));
}
if (filled) {
AMT_AMAGIC_on(&amt);
diff --git a/handy.h b/handy.h
index 446df5b2c9..32239b9ee3 100644
--- a/handy.h
+++ b/handy.h
@@ -55,6 +55,7 @@ Null SV pointer. (No longer available when C<PERL_CORE> is defined.)
#endif
#define MUTABLE_AV(p) ((AV *)MUTABLE_PTR(p))
+#define MUTABLE_CV(p) ((CV *)MUTABLE_PTR(p))
#define MUTABLE_HV(p) ((HV *)MUTABLE_PTR(p))
#define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p))
diff --git a/mg.c b/mg.c
index e302e0f430..18f9083885 100644
--- a/mg.c
+++ b/mg.c
@@ -2916,7 +2916,7 @@ Perl_sighandler(int sig)
if (flags & 16)
PL_scopestack_ix += 1;
/* sv_2cv is too complicated, try a simpler variant first: */
- if (!SvROK(PL_psig_ptr[sig]) || !(cv = (CV*)SvRV(PL_psig_ptr[sig]))
+ if (!SvROK(PL_psig_ptr[sig]) || !(cv = MUTABLE_CV(SvRV(PL_psig_ptr[sig])))
|| SvTYPE(cv) != SVt_PVCV) {
HV *st;
cv = sv_2cv(PL_psig_ptr[sig], &st, &gv, GV_ADD);
diff --git a/op.c b/op.c
index cc027bf6b9..90a0c52976 100644
--- a/op.c
+++ b/op.c
@@ -5569,7 +5569,7 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
{
Perl_warner(aTHX_ packWARN(WARN_PROTOTYPE), "Runaway prototype");
}
- cv_ckproto_len((CV*)gv, NULL, ps, ps_len);
+ cv_ckproto_len((const CV *)gv, NULL, ps, ps_len);
}
if (ps)
sv_setpvn((SV*)gv, ps, ps_len);
@@ -6103,7 +6103,7 @@ Perl_newXS(pTHX_ const char *name, XSUBADDR_t subaddr, const char *filename)
if (cv) /* must reuse cv if autoloaded */
cv_undef(cv);
else {
- cv = (CV*)newSV_type(SVt_PVCV);
+ cv = MUTABLE_CV(newSV_type(SVt_PVCV));
if (name) {
GvCV(gv) = cv;
GvCVGEN(gv) = 0;
diff --git a/pad.c b/pad.c
index 16a539b1d0..caf3df584c 100644
--- a/pad.c
+++ b/pad.c
@@ -285,7 +285,7 @@ Perl_pad_undef(pTHX_ CV* cv)
if (namesv && namesv != &PL_sv_undef
&& *SvPVX_const(namesv) == '&')
{
- CV * const innercv = (CV*)curpad[ix];
+ CV * const innercv = MUTABLE_CV(curpad[ix]);
U32 inner_rc = SvREFCNT(innercv);
assert(inner_rc);
namepad[ix] = NULL;
@@ -511,10 +511,10 @@ Perl_pad_add_anon(pTHX_ SV* sv, OPCODE op_type)
/* to avoid ref loops, we never have parent + child referencing each
* other simultaneously */
- if (CvOUTSIDE((CV*)sv)) {
- assert(!CvWEAKOUTSIDE((CV*)sv));
- CvWEAKOUTSIDE_on((CV*)sv);
- SvREFCNT_dec(CvOUTSIDE((CV*)sv));
+ if (CvOUTSIDE((const CV *)sv)) {
+ assert(!CvWEAKOUTSIDE((const CV *)sv));
+ CvWEAKOUTSIDE_on(MUTABLE_CV(sv));
+ SvREFCNT_dec(CvOUTSIDE(MUTABLE_CV(sv)));
}
return ix;
}
@@ -1486,7 +1486,7 @@ Perl_cv_clone(pTHX_ CV *proto)
ENTER;
SAVESPTR(PL_compcv);
- cv = PL_compcv = (CV*)newSV_type(SvTYPE(proto));
+ cv = PL_compcv = MUTABLE_CV(newSV_type(SvTYPE(proto)));
CvFLAGS(cv) = CvFLAGS(proto) & ~(CVf_CLONE|CVf_WEAKOUTSIDE);
CvCLONED_on(cv);
@@ -1502,7 +1502,7 @@ Perl_cv_clone(pTHX_ CV *proto)
CvROOT(cv) = OpREFCNT_inc(CvROOT(proto));
OP_REFCNT_UNLOCK;
CvSTART(cv) = CvSTART(proto);
- CvOUTSIDE(cv) = (CV*)SvREFCNT_inc_simple(outside);
+ CvOUTSIDE(cv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(proto);
if (SvPOK(proto))
@@ -1620,7 +1620,7 @@ Perl_pad_fixup_inner_anons(pTHX_ PADLIST *padlist, CV *old_cv, CV *new_cv)
if (namesv && namesv != &PL_sv_undef
&& *SvPVX_const(namesv) == '&')
{
- CV * const innercv = (CV*)curpad[ix];
+ CV * const innercv = MUTABLE_CV(curpad[ix]);
assert(CvWEAKOUTSIDE(innercv));
assert(CvOUTSIDE(innercv) == old_cv);
CvOUTSIDE(innercv) = new_cv;
diff --git a/perl.c b/perl.c
index 11f21be370..24904f59cd 100644
--- a/perl.c
+++ b/perl.c
@@ -2100,7 +2100,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
}
}
- PL_main_cv = PL_compcv = (CV*)newSV_type(SVt_PVCV);
+ PL_main_cv = PL_compcv = MUTABLE_CV(newSV_type(SVt_PVCV));
CvUNIQUE_on(PL_compcv);
CvPADLIST(PL_compcv) = pad_new(0);
@@ -2649,7 +2649,7 @@ Perl_call_sv(pTHX_ SV *sv, VOL I32 flags)
&& (PL_DBcv || (PL_DBcv = GvCV(PL_DBsub)))
/* Try harder, since this may have been a sighandler, thus
* curstash may be meaningless. */
- && (SvTYPE(sv) != SVt_PVCV || CvSTASH((CV*)sv) != PL_debstash)
+ && (SvTYPE(sv) != SVt_PVCV || CvSTASH((const CV *)sv) != PL_debstash)
&& !(flags & G_NODEBUG))
PL_op->op_private |= OPpENTERSUB_DB;
@@ -5114,7 +5114,7 @@ Perl_call_list(pTHX_ I32 oldscope, AV *paramList)
PERL_ARGS_ASSERT_CALL_LIST;
while (av_len(paramList) >= 0) {
- cv = (CV*)av_shift(paramList);
+ cv = MUTABLE_CV(av_shift(paramList));
if (PL_savebegin) {
if (paramList == PL_beginav) {
/* save PL_beginav for compiler */
diff --git a/pp.c b/pp.c
index af00a2a68a..38ba12e0de 100644
--- a/pp.c
+++ b/pp.c
@@ -376,7 +376,7 @@ PP(pp_rv2cv)
CV *cv = sv_2cv(TOPs, &stash_unused, &gv, flags);
if (cv) {
if (CvCLONE(cv))
- cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
+ cv = MUTABLE_CV(sv_2mortal((SV*)cv_clone(cv)));
if ((PL_op->op_private & OPpLVAL_INTRO)) {
if (gv && GvCV(gv) == cv && (gv = gv_autoload4(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), FALSE)))
cv = GvCV(gv);
@@ -385,10 +385,10 @@ PP(pp_rv2cv)
}
}
else if ((flags == (GV_ADD|GV_NOEXPAND)) && gv && SvROK(gv)) {
- cv = (CV*)gv;
+ cv = MUTABLE_CV(gv);
}
else
- cv = (CV*)&PL_sv_undef;
+ cv = MUTABLE_CV(&PL_sv_undef);
SETs((SV*)cv);
RETURN;
}
@@ -472,9 +472,9 @@ PP(pp_prototype)
PP(pp_anoncode)
{
dVAR; dSP;
- CV* cv = (CV*)PAD_SV(PL_op->op_targ);
+ CV *cv = MUTABLE_CV(PAD_SV(PL_op->op_targ));
if (CvCLONE(cv))
- cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
+ cv = MUTABLE_CV(sv_2mortal((SV*)cv_clone(cv)));
EXTEND(SP,1);
PUSHs((SV*)cv);
RETURN;
@@ -811,14 +811,15 @@ PP(pp_undef)
case SVt_PVCV:
if (cv_const_sv((const CV *)sv) && ckWARN(WARN_MISC))
Perl_warner(aTHX_ packWARN(WARN_MISC), "Constant subroutine %s undefined",
- CvANON((CV*)sv) ? "(anonymous)" : GvENAME(CvGV((CV*)sv)));
+ CvANON((const CV *)sv) ? "(anonymous)"
+ : GvENAME(CvGV((const CV *)sv)));
/* FALLTHROUGH */
case SVt_PVFM:
{
/* let user-undef'd sub keep its identity */
- GV* const gv = CvGV((CV*)sv);
- cv_undef((CV*)sv);
- CvGV((CV*)sv) = gv;
+ GV* const gv = CvGV((const CV *)sv);
+ cv_undef(MUTABLE_CV(sv));
+ CvGV((const CV *)sv) = gv;
}
break;
case SVt_PVGV:
diff --git a/pp_ctl.c b/pp_ctl.c
index c30d485696..71a35d3bc9 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2412,7 +2412,7 @@ PP(pp_goto)
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) {
I32 cxix;
register PERL_CONTEXT *cx;
- CV* cv = (CV*)SvRV(sv);
+ CV *cv = MUTABLE_CV(SvRV(sv));
SV** mark;
I32 items = 0;
I32 oldsave;
@@ -2983,13 +2983,13 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
PUSHMARK(SP);
SAVESPTR(PL_compcv);
- PL_compcv = (CV*)newSV_type(SVt_PVCV);
+ PL_compcv = MUTABLE_CV(newSV_type(SVt_PVCV));
CvEVAL_on(PL_compcv);
assert(CxTYPE(&cxstack[cxstack_ix]) == CXt_EVAL);
cxstack[cxstack_ix].blk_eval.cv = PL_compcv;
CvOUTSIDE_SEQ(PL_compcv) = seq;
- CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outside);
+ CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outside));
/* set up a scratch pad */
diff --git a/pp_hot.c b/pp_hot.c
index 44ded8a62f..d812e95644 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2714,7 +2714,7 @@ PP(pp_entersub)
SV * const * sp = &sv; /* Used in tryAMAGICunDEREF macro. */
tryAMAGICunDEREF(to_cv);
}
- cv = (CV*)SvRV(sv);
+ cv = MUTABLE_CV(SvRV(sv));
if (SvTYPE(cv) == SVt_PVCV)
break;
/* FALL THROUGH */
@@ -2723,7 +2723,7 @@ PP(pp_entersub)
DIE(aTHX_ "Not a CODE reference");
/* This is the second most common case: */
case SVt_PVCV:
- cv = (CV*)sv;
+ cv = MUTABLE_CV(sv);
break;
}
diff --git a/pp_sort.c b/pp_sort.c
index 777bd7a9be..d06a953d2a 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1813,7 +1813,7 @@ S_sortcv_xsub(pTHX_ SV *const a, SV *const b)
dVAR; dSP;
const I32 oldsaveix = PL_savestack_ix;
const I32 oldscopeix = PL_scopestack_ix;
- CV * const cv=(CV*)PL_sortcop;
+ CV * const cv=MUTABLE_CV(PL_sortcop);
I32 result;
PERL_ARGS_ASSERT_SORTCV_XSUB;
diff --git a/pp_sys.c b/pp_sys.c
index 7122499b5d..1a75bbbffc 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1306,7 +1306,7 @@ PP(pp_enterwrite)
DIE(aTHX_ "Not a format reference");
}
if (CvCLONE(cv))
- cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
+ cv = MUTABLE_CV(sv_2mortal((SV*)cv_clone(cv)));
IoFLAGS(io) &= ~IOf_DIDTOP;
return doform(cv,gv,PL_op->op_next);
@@ -1397,7 +1397,7 @@ PP(pp_leavewrite)
DIE(aTHX_ "Undefined top format called");
}
if (cv && CvCLONE(cv))
- cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
+ cv = MUTABLE_CV(sv_2mortal((SV*)cv_clone(cv)));
return doform(cv, gv, PL_op);
}
diff --git a/sv.c b/sv.c
index 6acddc1597..575d663302 100644
--- a/sv.c
+++ b/sv.c
@@ -3502,7 +3502,7 @@ S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr)
common:
if (intro) {
if (stype == SVt_PVCV) {
- /*if (GvCVGEN(dstr) && (GvCV(dstr) != (CV*)sref || GvCVGEN(dstr))) {*/
+ /*if (GvCVGEN(dstr) && (GvCV(dstr) != (const CV *)sref || GvCVGEN(dstr))) {*/
if (GvCVGEN(dstr)) {
SvREFCNT_dec(GvCV(dstr));
GvCV(dstr) = NULL;
@@ -3514,14 +3514,14 @@ S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr)
else
dref = *location;
if (stype == SVt_PVCV && (*location != sref || GvCVGEN(dstr))) {
- CV* const cv = (CV*)*location;
+ CV* const cv = MUTABLE_CV(*location);
if (cv) {
if (!GvCVGEN((GV*)dstr) &&
(CvROOT(cv) || CvXSUB(cv)))
{
/* Redefining a sub - warning is mandatory if
it was a const and its value changed. */
- if (CvCONST(cv) && CvCONST((CV*)sref)
+ if (CvCONST(cv) && CvCONST((const CV *)sref)
&& cv_const_sv(cv)
== cv_const_sv((const CV *)sref)) {
NOOP;
@@ -3534,7 +3534,7 @@ S_glob_assign_ref(pTHX_ SV *const dstr, SV *const sstr)
}
else if (ckWARN(WARN_REDEFINE)
|| (CvCONST(cv)
- && (!CvCONST((CV*)sref)
+ && (!CvCONST((const CV *)sref)
|| sv_cmp(cv_const_sv(cv),
cv_const_sv((const CV *)
sref))))) {
@@ -5509,7 +5509,7 @@ Perl_sv_clear(pTHX_ register SV *const sv)
goto freescalar;
case SVt_PVCV:
case SVt_PVFM:
- cv_undef((CV*)sv);
+ cv_undef(MUTABLE_CV(sv));
goto freescalar;
case SVt_PVHV:
if (PL_last_swash_hv == (const HV *)sv) {
@@ -7945,7 +7945,7 @@ Perl_sv_2cv(pTHX_ SV *sv, HV **const st, GV **const gvp, const I32 lref)
case SVt_PVCV:
*st = CvSTASH(sv);
*gvp = NULL;
- return (CV*)sv;
+ return MUTABLE_CV(sv);
case SVt_PVHV:
case SVt_PVAV:
*st = NULL;
@@ -7968,7 +7968,7 @@ Perl_sv_2cv(pTHX_ SV *sv, HV **const st, GV **const gvp, const I32 lref)
sv = SvRV(sv);
if (SvTYPE(sv) == SVt_PVCV) {
- cv = (CV*)sv;
+ cv = MUTABLE_CV(sv);
*gvp = NULL;
*st = CvSTASH(cv);
return cv;
@@ -10088,8 +10088,8 @@ ptr_table_* functions.
#define av_dup_inc(s,t) (AV*)SvREFCNT_inc(sv_dup((const SV *)s,t))
#define hv_dup(s,t) MUTABLE_HV(sv_dup((const SV *)s,t))
#define hv_dup_inc(s,t) MUTABLE_HV(SvREFCNT_inc(sv_dup((const SV *)s,t)))
-#define cv_dup(s,t) (CV*)sv_dup((SV*)s,t)
-#define cv_dup_inc(s,t) (CV*)SvREFCNT_inc(sv_dup((const SV *)s,t))
+#define cv_dup(s,t) MUTABLE_CV(sv_dup((SV*)s,t))
+#define cv_dup_inc(s,t) MUTABLE_CV(SvREFCNT_inc(sv_dup((const SV *)s,t)))
#define io_dup(s,t) (IO*)sv_dup((SV*)s,t)
#define io_dup_inc(s,t) (IO*)SvREFCNT_inc(sv_dup((const SV *)s,t))
#define gv_dup(s,t) (GV*)sv_dup((SV*)s,t)
diff --git a/toke.c b/toke.c
index 7b11deff67..9f1c886fc1 100644
--- a/toke.c
+++ b/toke.c
@@ -5442,7 +5442,7 @@ Perl_yylex(pTHX)
/* Real typeglob, so get the real subroutine: */
? GvCVu(gv)
/* A proxy for a subroutine in this package? */
- : SvOK(gv) ? (CV *) gv : NULL)
+ : SvOK(gv) ? MUTABLE_CV(gv) : NULL)
: NULL;
/* See if it's the indirect object for a list operator. */
@@ -12565,12 +12565,12 @@ Perl_start_subparse(pTHX_ I32 is_format, U32 flags)
save_item(PL_subname);
SAVESPTR(PL_compcv);
- PL_compcv = (CV*)newSV_type(is_format ? SVt_PVFM : SVt_PVCV);
+ PL_compcv = MUTABLE_CV(newSV_type(is_format ? SVt_PVFM : SVt_PVCV));
CvFLAGS(PL_compcv) |= flags;
PL_subline = CopLINE(PL_curcop);
CvPADLIST(PL_compcv) = pad_new(padnew_SAVE|padnew_SAVESUB);
- CvOUTSIDE(PL_compcv) = (CV*)SvREFCNT_inc_simple(outsidecv);
+ CvOUTSIDE(PL_compcv) = MUTABLE_CV(SvREFCNT_inc_simple(outsidecv));
CvOUTSIDE_SEQ(PL_compcv) = PL_cop_seqmax;
return oldsavestack_ix;
diff --git a/xsutils.c b/xsutils.c
index 67bf6ca73f..e5c3dd8dbf 100644
--- a/xsutils.c
+++ b/xsutils.c
@@ -77,9 +77,9 @@ modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
case 'l':
if (memEQ(name, "lvalue", 6)) {
if (negated)
- CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
+ CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
else
- CvFLAGS((CV*)sv) |= CVf_LVALUE;
+ CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
continue;
}
break;
@@ -87,18 +87,18 @@ modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
case 'k':
if (memEQ(name, "locked", 6)) {
if (negated)
- CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
+ CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LOCKED;
else
- CvFLAGS((CV*)sv) |= CVf_LOCKED;
+ CvFLAGS(MUTABLE_CV(sv)) |= CVf_LOCKED;
continue;
}
break;
case 'h':
if (memEQ(name, "method", 6)) {
if (negated)
- CvFLAGS((CV*)sv) &= ~CVf_METHOD;
+ CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
else
- CvFLAGS((CV*)sv) |= CVf_METHOD;
+ CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
continue;
}
break;
@@ -203,7 +203,7 @@ usage:
switch (SvTYPE(sv)) {
case SVt_PVCV:
- cvflags = CvFLAGS((CV*)sv);
+ cvflags = CvFLAGS((const CV *)sv);
if (cvflags & CVf_LOCKED)
XPUSHs(newSVpvs_flags("locked", SVs_TEMP));
#ifdef CVf_LVALUE
@@ -212,7 +212,7 @@ usage:
#endif
if (cvflags & CVf_METHOD)
XPUSHs(newSVpvs_flags("method", SVs_TEMP));
- if (GvUNIQUE(CvGV((CV*)sv)))
+ if (GvUNIQUE(CvGV((const CV *)sv)))
XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
break;
case SVt_PVGV: