/* pp.c
*
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- * 2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
+ * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
if (SvMAGICAL(TARG)) {
U32 i;
for (i=0; i < (U32)maxarg; i++) {
- SV ** const svp = av_fetch((AV*)TARG, i, FALSE);
+ SV * const * const svp = av_fetch((AV*)TARG, i, FALSE);
SP[i+1] = (svp) ? *svp : &PL_sv_undef;
}
}
GV *gv;
if (cUNOP->op_targ) {
STRLEN len;
- SV *namesv = PAD_SV(cUNOP->op_targ);
- const char *name = SvPV(namesv, len);
+ SV * const namesv = PAD_SV(cUNOP->op_targ);
+ const char * const name = SvPV(namesv, len);
gv = (GV*)NEWSV(0,0);
gv_init(gv, CopSTASH(PL_curcop), name, len, 0);
}
else {
- const char *name = CopSTASHPV(PL_curcop);
+ const char * const name = CopSTASHPV(PL_curcop);
gv = newGVgen(name);
}
if (SvTYPE(sv) < SVt_RV)
if ((PL_op->op_flags & OPf_SPECIAL) &&
!(PL_op->op_flags & OPf_MOD))
{
- SV * const temp = (SV*)gv_fetchsv(sv, FALSE, SVt_PVGV);
+ SV * const temp = (SV*)gv_fetchsv(sv, 0, SVt_PVGV);
if (!temp
&& (!is_gv_magical_sv(sv,0)
- || !(sv = (SV*)gv_fetchsv(sv, TRUE, SVt_PVGV)))) {
+ || !(sv = (SV*)gv_fetchsv(sv, GV_ADD, SVt_PVGV)))) {
RETSETUNDEF;
}
sv = temp;
else {
if (PL_op->op_private & HINT_STRICT_REFS)
DIE(aTHX_ PL_no_symref_sv, sv, "a symbol");
- sv = (SV*)gv_fetchsv(sv, TRUE, SVt_PVGV);
+ if ((PL_op->op_private & (OPpLVAL_INTRO|OPpDONT_INIT_GV))
+ == OPpDONT_INIT_GV) {
+ /* We are the target of a coderef assignment. Return
+ the scalar unchanged, and let pp_sasssign deal with
+ things. */
+ RETURN;
+ }
+ sv = (SV*)gv_fetchsv(sv, GV_ADD, SVt_PVGV);
}
}
}
PP(pp_rv2sv)
{
- GV *gv = Nullgv;
+ GV *gv = NULL;
dSP; dTOPss;
if (SvROK(sv)) {
if (SvROK(sv))
goto wasref;
}
+ if (PL_op->op_private & HINT_STRICT_REFS) {
+ if (SvOK(sv))
+ DIE(aTHX_ PL_no_symref_sv, sv, "a SCALAR");
+ else
+ DIE(aTHX_ PL_no_usym, "a SCALAR");
+ }
if (!SvOK(sv)) {
- if (PL_op->op_flags & OPf_REF ||
- PL_op->op_private & HINT_STRICT_REFS)
+ if (PL_op->op_flags & OPf_REF)
DIE(aTHX_ PL_no_usym, "a SCALAR");
if (ckWARN(WARN_UNINITIALIZED))
report_uninit(sv);
if ((PL_op->op_flags & OPf_SPECIAL) &&
!(PL_op->op_flags & OPf_MOD))
{
- gv = (GV*)gv_fetchsv(sv, FALSE, SVt_PV);
+ gv = (GV*)gv_fetchsv(sv, 0, SVt_PV);
if (!gv
&& (!is_gv_magical_sv(sv, 0)
- || !(gv = (GV*)gv_fetchsv(sv, TRUE, SVt_PV))))
+ || !(gv = (GV*)gv_fetchsv(sv, GV_ADD, SVt_PV))))
{
RETSETUNDEF;
}
}
else {
- if (PL_op->op_private & HINT_STRICT_REFS)
- DIE(aTHX_ PL_no_symref_sv, sv, "a SCALAR");
- gv = (GV*)gv_fetchsv(sv, TRUE, SVt_PV);
+ gv = (GV*)gv_fetchsv(sv, GV_ADD, SVt_PV);
}
}
sv = GvSVn(gv);
if (!*sv) {
*sv = NEWSV(0,0);
sv_upgrade(*sv, SVt_PVMG);
- sv_magic(*sv, (SV*)av, PERL_MAGIC_arylen, Nullch, 0);
+ sv_magic(*sv, (SV*)av, PERL_MAGIC_arylen, NULL, 0);
}
SETs(*sv);
RETURN;
if (PL_op->op_flags & OPf_MOD || LVRET) {
if (SvTYPE(TARG) < SVt_PVLV) {
sv_upgrade(TARG, SVt_PVLV);
- sv_magic(TARG, Nullsv, PERL_MAGIC_pos, Nullch, 0);
+ sv_magic(TARG, NULL, PERL_MAGIC_pos, NULL, 0);
}
LvTYPE(TARG) = '.';
dSP;
GV *gv;
HV *stash;
-
+ const I32 flags = (PL_op->op_flags & OPf_SPECIAL)
+ ? 0
+ : ((PL_op->op_private & (OPpLVAL_INTRO|OPpMAY_RETURN_CONSTANT)) == OPpMAY_RETURN_CONSTANT)
+ ? GV_ADD|GV_NOEXPAND
+ : GV_ADD;
/* We usually try to add a non-existent subroutine in case of AUTOLOAD. */
/* (But not in defined().) */
- CV *cv = sv_2cv(TOPs, &stash, &gv, !(PL_op->op_flags & OPf_SPECIAL));
+
+ CV *cv = sv_2cv(TOPs, &stash, &gv, flags);
if (cv) {
if (CvCLONE(cv))
cv = (CV*)sv_2mortal((SV*)cv_clone(cv));
DIE(aTHX_ "Can't modify non-lvalue subroutine call");
}
}
+ else if ((flags == (GV_ADD|GV_NOEXPAND)) && gv && SvROK(gv)) {
+ cv = (CV*)gv;
+ }
else
cv = (CV*)&PL_sv_undef;
SETs((SV*)cv);
CV *cv;
HV *stash;
GV *gv;
- SV *ret;
+ SV *ret = &PL_sv_undef;
- ret = &PL_sv_undef;
if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) {
- const char *s = SvPVX_const(TOPs);
+ const char * const s = SvPVX_const(TOPs);
if (strnEQ(s, "CORE::", 6)) {
const int code = keyword(s + 6, SvCUR(TOPs) - 6);
if (code < 0) { /* Overridable. */
}
}
}
- cv = sv_2cv(TOPs, &stash, &gv, FALSE);
+ cv = sv_2cv(TOPs, &stash, &gv, 0);
if (cv && SvPOK(cv))
ret = sv_2mortal(newSVpvn(SvPVX_const(cv), SvCUR(cv)));
set:
SV *sv = POPs;
const char * const elem = SvPV_nolen_const(sv);
GV * const gv = (GV*)POPs;
- SV * tmpRef = Nullsv;
+ SV * tmpRef = NULL;
- sv = Nullsv;
+ sv = NULL;
if (elem) {
/* elem will always be NUL terminated. */
const char * const second_letter = elem + 1;
break;
case 'P':
if (strEQ(second_letter, "ACKAGE")) {
- const HEK *hek = HvNAME_HEK(GvSTASH(gv));
- sv = hek ? newSVhek(hek) : newSVpvn("__ANON__", 8);
+ const HV * const stash = GvSTASH(gv);
+ const HEK * const hek = stash ? HvNAME_HEK(stash) : NULL;
+ sv = hek ? newSVhek(hek) : newSVpvs("__ANON__");
}
break;
case 'S':
SvSCREAM_on(sv);
/* piggyback on m//g magic */
- sv_magic(sv, Nullsv, PERL_MAGIC_regex_global, Nullch, 0);
+ sv_magic(sv, NULL, PERL_MAGIC_regex_global, NULL, 0);
RETPUSHYES;
}
case SVt_PVFM:
{
/* let user-undef'd sub keep its identity */
- GV* gv = CvGV((CV*)sv);
+ GV* const gv = CvGV((CV*)sv);
cv_undef((CV*)sv);
CvGV((CV*)sv) = gv;
}
default:
if (SvTYPE(sv) >= SVt_PV && SvPVX_const(sv) && SvLEN(sv)) {
SvPV_free(sv);
- SvPV_set(sv, Nullch);
+ SvPV_set(sv, NULL);
SvLEN_set(sv, 0);
}
SvOK_off(sv);
} else if (!ahigh && !bhigh) {
/* eg 32 bit is at most 0xFFFF * 0xFFFF == 0xFFFE0001
so the unsigned multiply cannot overflow. */
- UV product = alow * blow;
+ const UV product = alow * blow;
if (auvok == buvok) {
/* -ve * -ve or +ve * +ve gives a +ve result. */
SP--;
if (!left_neg) {
left = SvUVX(POPs);
} else {
- IV aiv = SvIVX(POPs);
+ const IV aiv = SvIVX(POPs);
if (aiv >= 0) {
left = aiv;
left_neg = FALSE; /* effectively it's a UV now */
else
count = uv;
} else {
- IV iv = SvIV(sv);
+ const IV iv = SvIV(sv);
if (iv < 0)
count = 0;
else
count = SvIVx(sv);
if (GIMME == G_ARRAY && PL_op->op_private & OPpREPEAT_DOLIST) {
dMARK;
- I32 items = SP - MARK;
- I32 max;
- static const char oom_list_extend[] =
- "Out of memory during list extend";
+ static const char oom_list_extend[] = "Out of memory during list extend";
+ const I32 items = SP - MARK;
+ const I32 max = items * count;
- max = items * count;
MEM_WRAP_CHECK_1(max, SV*, oom_list_extend);
/* Did the max computation overflow? */
if (items > 0 && max > 0 && (max < items || max < count))
SP -= items;
}
else { /* Note: mark already snarfed by pp_list */
- SV *tmpstr = POPs;
+ SV * const tmpstr = POPs;
STRLEN len;
bool isutf;
static const char oom_string_extend[] =
if (count < 1)
SvCUR_set(TARG, 0);
else {
- STRLEN max = (UV)count * len;
+ const STRLEN max = (UV)count * len;
if (len > ((MEM_SIZE)~0)/count)
Perl_croak(aTHX_ oom_string_extend);
MEM_WRAP_CHECK_1(max, char, oom_string_extend);
{
const IV shift = POPi;
if (PL_op->op_private & HINT_INTEGER) {
- IV i = TOPi;
+ const IV i = TOPi;
SETi(i << shift);
}
else {
- UV u = TOPu;
+ const UV u = TOPu;
SETu(u << shift);
}
RETURN;
{
const IV shift = POPi;
if (PL_op->op_private & HINT_INTEGER) {
- IV i = TOPi;
+ const IV i = TOPi;
SETi(i >> shift);
}
else {
- UV u = TOPu;
+ const UV u = TOPu;
SETu(u >> shift);
}
RETURN;
if (SvIOK(TOPs)) {
SvIV_please(TOPm1s);
if (SvIOK(TOPm1s)) {
- bool auvok = SvUOK(TOPm1s);
- bool buvok = SvUOK(TOPs);
+ const bool auvok = SvUOK(TOPm1s);
+ const bool buvok = SvUOK(TOPs);
if (auvok == buvok) { /* ## IV == IV or UV == UV ## */
/* Casting IV to UV before comparison isn't going to matter
dSP; dTARGET; tryAMAGICbin(ncmp,0);
#ifndef NV_PRESERVES_UV
if (SvROK(TOPs) && !SvAMAGIC(TOPs) && SvROK(TOPm1s) && !SvAMAGIC(TOPm1s)) {
- UV right = PTR2UV(SvRV(POPs));
- UV left = PTR2UV(SvRV(TOPs));
+ const UV right = PTR2UV(SvRV(POPs));
+ const UV left = PTR2UV(SvRV(TOPs));
SETi((left > right) - (left < right));
RETURN;
}
SETn(-SvNV(sv));
else if (SvPOKp(sv)) {
STRLEN len;
- const char *s = SvPV_const(sv, len);
+ const char * const s = SvPV_const(sv, len);
if (isIDFIRST(*s)) {
sv_setpvn(TARG, "-", 1);
sv_catsv(TARG, sv);
PP(pp_srand)
{
dSP;
- UV anum;
- if (MAXARG < 1)
- anum = seed();
- else
- anum = POPu;
+ const UV anum = (MAXARG < 1) ? seed() : POPu;
(void)seedDrand01((Rand_seed_t)anum);
PL_srand_called = TRUE;
EXTEND(SP, 1);
PP(pp_length)
{
dSP; dTARGET;
- SV *sv = TOPs;
+ SV * const sv = TOPs;
if (DO_UTF8(sv))
SETi(sv_len_utf8(sv));
const char *tmps;
const I32 arybase = PL_curcop->cop_arybase;
SV *repl_sv = NULL;
- const char *repl = 0;
+ const char *repl = NULL;
STRLEN repl_len;
const int num_args = PL_op->op_private & 7;
bool repl_need_utf8_upgrade = FALSE;
if (SvTYPE(TARG) < SVt_PVLV) {
sv_upgrade(TARG, SVt_PVLV);
- sv_magic(TARG, Nullsv, PERL_MAGIC_substr, Nullch, 0);
+ sv_magic(TARG, NULL, PERL_MAGIC_substr, NULL, 0);
}
else
SvOK_off(TARG);
TARG = sv_newmortal();
if (SvTYPE(TARG) < SVt_PVLV) {
sv_upgrade(TARG, SVt_PVLV);
- sv_magic(TARG, Nullsv, PERL_MAGIC_vec, Nullch, 0);
+ sv_magic(TARG, NULL, PERL_MAGIC_vec, NULL, 0);
}
LvTYPE(TARG) = 'v';
if (LvTARG(TARG) != src) {
dSP; dTARGET;
SV *big;
SV *little;
- SV *temp = Nullsv;
+ SV *temp = NULL;
I32 offset;
I32 retval;
const char *tmps;
dSP; dTARGET;
SV *big;
SV *little;
- SV *temp = Nullsv;
+ SV *temp = NULL;
STRLEN blen;
STRLEN llen;
I32 offset;
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_const(TARG);
+ const UV o = d - (U8*)SvPVX_const(TARG);
/* If someone uppercases one million U+03B0s we
* SvGROW() one million times. Or we could try
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_const(TARG);
+ const UV o = d - (U8*)SvPVX_const(TARG);
/* If someone lowercases one million U+0130s we
* SvGROW() one million times. Or we could try
if (PL_op->op_private & OPpEXISTS_SUB) {
GV *gv;
- SV *sv = POPs;
- CV * const cv = sv_2cv(sv, &hv, &gv, FALSE);
+ SV * const sv = POPs;
+ CV * const cv = sv_2cv(sv, &hv, &gv, 0);
if (cv)
RETPUSHYES;
if (gv && isGV(gv) && GvCV(gv) && !GvCVGEN(gv))
I32 newlen;
I32 after;
I32 diff;
- SV **tmparyval = 0;
+ SV **tmparyval = NULL;
const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
if (mg) {
else if (gimme != G_ARRAY)
ary = GvAVn(PL_defgv);
else
- ary = Nullav;
+ ary = NULL;
if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {
realarray = 1;
PUTBACK;