extern Pid_t getpid (void);
#endif
+/*
+ * Some BSDs and Cygwin default to POSIX math instead of IEEE.
+ * This switches them over to IEEE.
+ */
+#if defined(LIBM_LIB_VERSION)
+ _LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
+#endif
+
/* variations on pp_null */
PP(pp_stub)
RETURN;
}
-PP(pp_scalar)
-{
- return NORMAL;
-}
-
/* Pushy stuff. */
PP(pp_padav)
}
gimme = GIMME_V;
if (gimme == G_ARRAY) {
- I32 maxarg = AvFILL((AV*)TARG) + 1;
+ const I32 maxarg = AvFILL((AV*)TARG) + 1;
EXTEND(SP, maxarg);
if (SvMAGICAL(TARG)) {
U32 i;
for (i=0; i < (U32)maxarg; i++) {
- SV **svp = av_fetch((AV*)TARG, i, FALSE);
+ SV ** const svp = av_fetch((AV*)TARG, i, FALSE);
SP[i+1] = (svp) ? *svp : &PL_sv_undef;
}
}
SP += maxarg;
}
else if (gimme == G_SCALAR) {
- SV* sv = sv_newmortal();
- I32 maxarg = AvFILL((AV*)TARG) + 1;
+ SV* const sv = sv_newmortal();
+ const I32 maxarg = AvFILL((AV*)TARG) + 1;
sv_setiv(sv, maxarg);
PUSHs(sv);
}
RETURNOP(do_kv());
}
else if (gimme == G_SCALAR) {
- SV* sv = Perl_hv_scalar(aTHX_ (HV*)TARG);
+ SV* const sv = Perl_hv_scalar(aTHX_ (HV*)TARG);
SETs(sv);
}
RETURN;
}
-PP(pp_padany)
-{
- DIE(aTHX_ "NOT IMPL LINE %d",__LINE__);
-}
-
/* Translations. */
PP(pp_rv2gv)
sv = SvRV(sv);
if (SvTYPE(sv) == SVt_PVIO) {
- GV *gv = (GV*) sv_newmortal();
+ GV * const gv = (GV*) sv_newmortal();
gv_init(gv, 0, "", 0, 0);
GvIOp(gv) = (IO *)sv;
(void)SvREFCNT_inc(sv);
if (SvREADONLY(sv))
Perl_croak(aTHX_ PL_no_modify);
if (PL_op->op_private & OPpDEREF) {
- const char *name;
GV *gv;
if (cUNOP->op_targ) {
STRLEN len;
SV *namesv = PAD_SV(cUNOP->op_targ);
- name = SvPV(namesv, len);
+ const char *name = SvPV(namesv, len);
gv = (GV*)NEWSV(0,0);
gv_init(gv, CopSTASH(PL_curcop), name, len, 0);
}
else {
- name = CopSTASHPV(PL_curcop);
+ const char *name = CopSTASHPV(PL_curcop);
gv = newGVgen(name);
}
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);
if ((PL_op->op_flags & OPf_SPECIAL) &&
!(PL_op->op_flags & OPf_MOD))
{
- SV * temp = (SV*)gv_fetchsv(sv, FALSE, SVt_PVGV);
+ SV * const temp = (SV*)gv_fetchsv(sv, FALSE, SVt_PVGV);
if (!temp
&& (!is_gv_magical_sv(sv,0)
|| !(sv = (SV*)gv_fetchsv(sv, TRUE, SVt_PVGV)))) {
gv = (GV*)gv_fetchsv(sv, TRUE, SVt_PV);
}
}
- sv = GvSV(gv);
+ sv = GvSVn(gv);
}
if (PL_op->op_flags & OPf_MOD) {
if (PL_op->op_private & OPpLVAL_INTRO) {
PP(pp_av2arylen)
{
dSP;
- AV *av = (AV*)TOPs;
- SV *sv = AvARYLEN(av);
- if (!sv) {
- AvARYLEN(av) = sv = NEWSV(0,0);
- sv_upgrade(sv, SVt_IV);
- sv_magic(sv, (SV*)av, PERL_MAGIC_arylen, Nullch, 0);
- }
- SETs(sv);
+ AV * const av = (AV*)TOPs;
+ SV ** const sv = Perl_av_arylen_p(aTHX_ (AV*)av);
+ if (!*sv) {
+ *sv = NEWSV(0,0);
+ sv_upgrade(*sv, SVt_PVMG);
+ sv_magic(*sv, (SV*)av, PERL_MAGIC_arylen, Nullch, 0);
+ }
+ SETs(*sv);
RETURN;
}
RETURN;
}
else {
- MAGIC* mg;
-
if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
- mg = mg_find(sv, PERL_MAGIC_regex_global);
+ const MAGIC * const mg = mg_find(sv, PERL_MAGIC_regex_global);
if (mg && mg->mg_len >= 0) {
I32 i = mg->mg_len;
if (DO_UTF8(sv))
ret = &PL_sv_undef;
if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) {
- char *s = SvPVX(TOPs);
+ const char *s = SvPVX_const(TOPs);
if (strnEQ(s, "CORE::", 6)) {
- int code;
-
- code = keyword(s + 6, SvCUR(TOPs) - 6);
+ const int code = keyword(s + 6, SvCUR(TOPs) - 6);
if (code < 0) { /* Overridable. */
#define MAX_ARGS_OP ((sizeof(I32) - 1) * 2)
int i = 0, n = 0, seen_question = 0;
I32 oa;
char str[ MAX_ARGS_OP * 2 + 2 ]; /* One ';', one '\0' */
- if (code == -KEY_chop || code == -KEY_chomp)
+ if (code == -KEY_chop || code == -KEY_chomp
+ || code == -KEY_exec || code == -KEY_system)
goto set;
while (i < MAXO) { /* The slow way. */
if (strEQ(s + 6, PL_op_name[i])
seen_question = 1;
str[n++] = ';';
}
- else if (n && str[0] == ';' && seen_question)
- goto set; /* XXXX system, exec */
if ((oa & (OA_OPTIONAL - 1)) >= OA_AVREF
&& (oa & (OA_OPTIONAL - 1)) <= OA_SCALARREF
/* But globs are already references (kinda) */
}
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;
PP(pp_ref)
{
dSP; dTARGET;
- SV *sv;
const char *pv;
+ SV * const sv = POPs;
- sv = POPs;
-
- if (sv && SvGMAGICAL(sv))
- mg_get(sv);
+ if (sv)
+ SvGETMAGIC(sv);
if (!sv || !SvROK(sv))
RETPUSHNO;
- sv = SvRV(sv);
- pv = sv_reftype(sv,TRUE);
+ pv = sv_reftype(SvRV(sv),TRUE);
PUSHp(pv, strlen(pv));
RETURN;
}
if (MAXARG == 1)
stash = CopSTASH(PL_curcop);
else {
- SV *ssv = POPs;
+ SV * const ssv = POPs;
STRLEN len;
const char *ptr;
if (ssv && !SvGMAGICAL(ssv) && !SvAMAGIC(ssv) && SvROK(ssv))
Perl_croak(aTHX_ "Attempt to bless into a reference");
- ptr = SvPV(ssv,len);
- if (ckWARN(WARN_MISC) && len == 0)
+ ptr = SvPV_const(ssv,len);
+ if (len == 0 && ckWARN(WARN_MISC))
Perl_warner(aTHX_ packWARN(WARN_MISC),
"Explicit blessing to '' (assuming package main)");
stash = gv_stashpvn(ptr, len, TRUE);
PP(pp_gelem)
{
- GV *gv;
- SV *sv;
- SV *tmpRef;
- const char *elem;
dSP;
- STRLEN n_a;
- sv = POPs;
- elem = SvPV(sv, n_a);
- gv = (GV*)POPs;
- tmpRef = Nullsv;
+ SV *sv = POPs;
+ const char * const elem = SvPV_nolen_const(sv);
+ GV * const gv = (GV*)POPs;
+ SV * tmpRef = Nullsv;
+
sv = Nullsv;
if (elem) {
/* elem will always be NUL terminated. */
- const char *elem2 = elem + 1;
+ const char * const second_letter = elem + 1;
switch (*elem) {
case 'A':
- if (strEQ(elem2, "RRAY"))
+ if (strEQ(second_letter, "RRAY"))
tmpRef = (SV*)GvAV(gv);
break;
case 'C':
- if (strEQ(elem2, "ODE"))
+ if (strEQ(second_letter, "ODE"))
tmpRef = (SV*)GvCVu(gv);
break;
case 'F':
- if (strEQ(elem2, "ILEHANDLE")) {
+ if (strEQ(second_letter, "ILEHANDLE")) {
/* finally deprecated in 5.8.0 */
deprecate("*glob{FILEHANDLE}");
tmpRef = (SV*)GvIOp(gv);
}
else
- if (strEQ(elem2, "ORMAT"))
+ if (strEQ(second_letter, "ORMAT"))
tmpRef = (SV*)GvFORM(gv);
break;
case 'G':
- if (strEQ(elem2, "LOB"))
+ if (strEQ(second_letter, "LOB"))
tmpRef = (SV*)gv;
break;
case 'H':
- if (strEQ(elem2, "ASH"))
+ if (strEQ(second_letter, "ASH"))
tmpRef = (SV*)GvHV(gv);
break;
case 'I':
- if (*elem2 == 'O' && !elem[2])
+ if (*second_letter == 'O' && !elem[2])
tmpRef = (SV*)GvIOp(gv);
break;
case 'N':
- if (strEQ(elem2, "AME"))
+ if (strEQ(second_letter, "AME"))
sv = newSVpvn(GvNAME(gv), GvNAMELEN(gv));
break;
case 'P':
- if (strEQ(elem2, "ACKAGE")) {
- const char *name = HvNAME(GvSTASH(gv));
- sv = newSVpv(name ? name : "__ANON__", 0);
+ if (strEQ(second_letter, "ACKAGE")) {
+ const HEK *hek = HvNAME_HEK(GvSTASH(gv));
+ sv = hek ? newSVhek(hek) : newSVpvn("__ANON__", 8);
}
break;
case 'S':
- if (strEQ(elem2, "CALAR"))
+ if (strEQ(second_letter, "CALAR"))
tmpRef = GvSV(gv);
break;
}
if (pos > PL_maxscream) {
if (PL_maxscream < 0) {
PL_maxscream = pos + 80;
- New(301, PL_screamfirst, 256, I32);
- New(302, PL_screamnext, PL_maxscream, I32);
+ Newx(PL_screamfirst, 256, I32);
+ Newx(PL_screamnext, PL_maxscream, I32);
}
else {
PL_maxscream = pos + pos / 4;
sfirst -= 256;
while (--pos >= 0) {
- ch = s[pos];
+ register const I32 ch = s[pos];
if (sfirst[ch] >= 0)
snext[pos] = sfirst[ch] - pos;
else
PP(pp_defined)
{
dSP;
- register SV* sv;
+ register SV* const sv = POPs;
- sv = POPs;
if (!sv || !SvANY(sv))
RETPUSHNO;
switch (SvTYPE(sv)) {
RETPUSHYES;
break;
default:
- if (SvGMAGICAL(sv))
- mg_get(sv);
+ SvGETMAGIC(sv);
if (SvOK(sv))
RETPUSHYES;
}
hv_undef((HV*)sv);
break;
case SVt_PVCV:
- if (ckWARN(WARN_MISC) && cv_const_sv((CV*)sv))
+ if (cv_const_sv((CV*)sv) && ckWARN(WARN_MISC))
Perl_warner(aTHX_ packWARN(WARN_MISC), "Constant subroutine %s undefined",
CvANON((CV*)sv) ? "(anonymous)" : GvENAME(CvGV((CV*)sv)));
/* FALL THROUGH */
else {
GP *gp;
gp_free((GV*)sv);
- Newz(602, gp, 1, GP);
+ Newxz(gp, 1, GP);
GvGP(sv) = gp_ref(gp);
GvSV(sv) = NEWSV(72,0);
GvLINE(sv) = CopLINE(PL_curcop);
}
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);
we're sure it is safe; otherwise we call pow() and try to convert to
integer afterwards. */
{
- SvIV_please(TOPm1s);
- if (SvIOK(TOPm1s)) {
- bool baseuok = SvUOK(TOPm1s);
- UV baseuv;
+ SvIV_please(TOPs);
+ if (SvIOK(TOPs)) {
+ SvIV_please(TOPm1s);
+ if (SvIOK(TOPm1s)) {
+ UV power;
+ bool baseuok;
+ UV baseuv;
- if (baseuok) {
- baseuv = SvUVX(TOPm1s);
- } else {
- IV iv = SvIVX(TOPm1s);
- if (iv >= 0) {
- baseuv = iv;
- baseuok = TRUE; /* effectively it's a UV now */
- } else {
- baseuv = -iv; /* abs, baseuok == false records sign */
- }
- }
- SvIV_please(TOPs);
- if (SvIOK(TOPs)) {
- UV power;
+ if (SvUOK(TOPs)) {
+ power = SvUVX(TOPs);
+ } else {
+ const IV iv = SvIVX(TOPs);
+ if (iv >= 0) {
+ power = iv;
+ } else {
+ goto float_it; /* Can't do negative powers this way. */
+ }
+ }
- if (SvUOK(TOPs)) {
- power = SvUVX(TOPs);
- } else {
- IV iv = SvIVX(TOPs);
- if (iv >= 0) {
- power = iv;
- } else {
- goto float_it; /* Can't do negative powers this way. */
- }
- }
+ baseuok = SvUOK(TOPm1s);
+ if (baseuok) {
+ baseuv = SvUVX(TOPm1s);
+ } else {
+ const IV iv = SvIVX(TOPm1s);
+ if (iv >= 0) {
+ baseuv = iv;
+ baseuok = TRUE; /* effectively it's a UV now */
+ } else {
+ baseuv = -iv; /* abs, baseuok == false records sign */
+ }
+ }
/* now we have integer ** positive integer. */
is_int = 1;
programmers to notice ** not doing what they mean. */
NV result = 1.0;
NV base = baseuok ? baseuv : -(NV)baseuv;
- int n = 0;
-
- for (; power; base *= base, n++) {
- /* Do I look like I trust gcc with long longs here?
- Do I hell. */
- UV bit = (UV)1 << (UV)n;
- if (power & bit) {
- result *= base;
- /* Only bother to clear the bit if it is set. */
- power -= bit;
- /* Avoid squaring base again if we're done. */
- if (power == 0) break;
- }
- }
+
+ if (power & 1) {
+ result *= base;
+ }
+ while (power >>= 1) {
+ base *= base;
+ if (power & 1) {
+ result *= base;
+ }
+ }
SP--;
SETn( result );
SvIV_please(TOPs);
RETURN;
} else {
register unsigned int highbit = 8 * sizeof(UV);
- register unsigned int lowbit = 0;
- register unsigned int diff;
- bool odd_power = (bool)(power & 1);
- while ((diff = (highbit - lowbit) >> 1)) {
- if (baseuv & ~((1 << (lowbit + diff)) - 1))
- lowbit += diff;
- else
- highbit -= diff;
+ register unsigned int diff = 8 * sizeof(UV);
+ while (diff >>= 1) {
+ highbit -= diff;
+ if (baseuv >> highbit) {
+ highbit += diff;
+ }
}
/* we now have baseuv < 2 ** highbit */
if (power * highbit <= 8 * sizeof(UV)) {
on same algorithm as above */
register UV result = 1;
register UV base = baseuv;
- register int n = 0;
- for (; power; base *= base, n++) {
- register UV bit = (UV)1 << (UV)n;
- if (power & bit) {
+ const bool odd_power = (bool)(power & 1);
+ if (odd_power) {
+ result *= base;
+ }
+ while (power >>= 1) {
+ base *= base;
+ if (power & 1) {
result *= base;
- power -= bit;
- if (power == 0) break;
}
}
SP--;
if (auvok) {
alow = SvUVX(TOPm1s);
} else {
- IV aiv = SvIVX(TOPm1s);
+ const IV aiv = SvIVX(TOPm1s);
if (aiv >= 0) {
alow = aiv;
auvok = TRUE; /* effectively it's a UV now */
if (buvok) {
blow = SvUVX(TOPs);
} else {
- IV biv = SvIVX(TOPs);
+ const IV biv = SvIVX(TOPs);
if (biv >= 0) {
blow = biv;
buvok = TRUE; /* effectively it's a UV now */
right = SvUVX(TOPs);
}
else {
- IV biv = SvIVX(TOPs);
+ const IV biv = SvIVX(TOPs);
if (biv >= 0) {
right = biv;
right_non_neg = TRUE; /* effectively it's a UV now */
left = SvUVX(TOPm1s);
}
else {
- IV aiv = SvIVX(TOPm1s);
+ const IV aiv = SvIVX(TOPm1s);
if (aiv >= 0) {
left = aiv;
left_non_neg = TRUE; /* effectively it's a UV now */
#endif
) {
/* Integer division can't overflow, but it can be imprecise. */
- UV result = left / right;
+ const UV result = left / right;
if (result * right == left) {
SP--; /* result is valid */
if (left_non_neg == right_non_neg) {
if (!right_neg) {
right = SvUVX(POPs);
} else {
- IV biv = SvIVX(POPs);
+ const IV biv = SvIVX(POPs);
if (biv >= 0) {
right = biv;
right_neg = FALSE; /* effectively it's a UV now */
{
register IV count;
dPOPss;
- if (SvGMAGICAL(sv))
- mg_get(sv);
+ SvGETMAGIC(sv);
if (SvIOKp(sv)) {
if (SvUOK(sv)) {
- UV uv = SvUV(sv);
+ const UV uv = SvUV(sv);
if (uv > IV_MAX)
count = IV_MAX; /* The best we can do? */
else
}
}
else if (SvNOKp(sv)) {
- NV nv = SvNV(sv);
+ const NV nv = SvNV(sv);
if (nv < 0.0)
count = 0;
else
if (count < 1)
SvCUR_set(TARG, 0);
else {
- IV max = count * len;
+ 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);
if ((auvok = SvUOK(TOPm1s)))
auv = SvUVX(TOPm1s);
else {
- register IV aiv = SvIVX(TOPm1s);
+ register const IV aiv = SvIVX(TOPm1s);
if (aiv >= 0) {
auv = aiv;
auvok = 1; /* Now acting as a sign flag. */
if (buvok)
buv = SvUVX(TOPs);
else {
- register IV biv = SvIVX(TOPs);
+ register const IV biv = SvIVX(TOPs);
if (biv >= 0) {
buv = biv;
buvok = 1;
{
dSP; dATARGET; tryAMAGICbin(lshift,opASSIGN);
{
- IV shift = POPi;
+ const IV shift = POPi;
if (PL_op->op_private & HINT_INTEGER) {
IV i = TOPi;
SETi(i << shift);
{
dSP; dATARGET; tryAMAGICbin(rshift,opASSIGN);
{
- IV shift = POPi;
+ const IV shift = POPi;
if (PL_op->op_private & HINT_INTEGER) {
IV i = TOPi;
SETi(i >> shift);
bool buvok = SvUOK(TOPs);
if (!auvok && !buvok) { /* ## IV < IV ## */
- IV aiv = SvIVX(TOPm1s);
- IV biv = SvIVX(TOPs);
+ const IV aiv = SvIVX(TOPm1s);
+ const IV biv = SvIVX(TOPs);
SP--;
SETs(boolSV(aiv < biv));
RETURN;
}
if (auvok && buvok) { /* ## UV < UV ## */
- UV auv = SvUVX(TOPm1s);
- UV buv = SvUVX(TOPs);
+ const UV auv = SvUVX(TOPm1s);
+ const UV buv = SvUVX(TOPs);
SP--;
SETs(boolSV(auv < buv));
}
if (auvok) { /* ## UV < IV ## */
UV auv;
- IV biv;
-
- biv = SvIVX(TOPs);
+ const IV biv = SvIVX(TOPs);
SP--;
if (biv < 0) {
/* As (a) is a UV, it's >=0, so it cannot be < */
RETURN;
}
{ /* ## IV < UV ## */
- IV aiv;
+ const IV aiv = SvIVX(TOPm1s);
UV buv;
- aiv = SvIVX(TOPm1s);
if (aiv < 0) {
/* As (b) is a UV, it's >=0, so it must be < */
SP--;
bool buvok = SvUOK(TOPs);
if (!auvok && !buvok) { /* ## IV > IV ## */
- IV aiv = SvIVX(TOPm1s);
- IV biv = SvIVX(TOPs);
-
+ const IV aiv = SvIVX(TOPm1s);
+ const IV biv = SvIVX(TOPs);
+
SP--;
SETs(boolSV(aiv > biv));
RETURN;
}
if (auvok && buvok) { /* ## UV > UV ## */
- UV auv = SvUVX(TOPm1s);
- UV buv = SvUVX(TOPs);
+ const UV auv = SvUVX(TOPm1s);
+ const UV buv = SvUVX(TOPs);
SP--;
SETs(boolSV(auv > buv));
}
if (auvok) { /* ## UV > IV ## */
UV auv;
- IV biv;
-
- biv = SvIVX(TOPs);
+ const IV biv = SvIVX(TOPs);
+
SP--;
if (biv < 0) {
/* As (a) is a UV, it's >=0, so it must be > */
RETURN;
}
{ /* ## IV > UV ## */
- IV aiv;
+ const IV aiv = SvIVX(TOPm1s);
UV buv;
- aiv = SvIVX(TOPm1s);
if (aiv < 0) {
/* As (b) is a UV, it's >=0, so it cannot be > */
SP--;
bool buvok = SvUOK(TOPs);
if (!auvok && !buvok) { /* ## IV <= IV ## */
- IV aiv = SvIVX(TOPm1s);
- IV biv = SvIVX(TOPs);
+ const IV aiv = SvIVX(TOPm1s);
+ const IV biv = SvIVX(TOPs);
SP--;
SETs(boolSV(aiv <= biv));
}
if (auvok) { /* ## UV <= IV ## */
UV auv;
- IV biv;
-
- biv = SvIVX(TOPs);
+ const IV biv = SvIVX(TOPs);
+
SP--;
if (biv < 0) {
/* As (a) is a UV, it's >=0, so a cannot be <= */
RETURN;
}
{ /* ## IV <= UV ## */
- IV aiv;
+ const IV aiv = SvIVX(TOPm1s);
UV buv;
-
- aiv = SvIVX(TOPm1s);
+
if (aiv < 0) {
/* As (b) is a UV, it's >=0, so a must be <= */
SP--;
bool buvok = SvUOK(TOPs);
if (!auvok && !buvok) { /* ## IV >= IV ## */
- IV aiv = SvIVX(TOPm1s);
- IV biv = SvIVX(TOPs);
-
+ const IV aiv = SvIVX(TOPm1s);
+ const IV biv = SvIVX(TOPs);
+
SP--;
SETs(boolSV(aiv >= biv));
RETURN;
}
if (auvok && buvok) { /* ## UV >= UV ## */
- UV auv = SvUVX(TOPm1s);
- UV buv = SvUVX(TOPs);
-
+ const UV auv = SvUVX(TOPm1s);
+ const UV buv = SvUVX(TOPs);
+
SP--;
SETs(boolSV(auv >= buv));
RETURN;
}
if (auvok) { /* ## UV >= IV ## */
UV auv;
- IV biv;
-
- biv = SvIVX(TOPs);
+ const IV biv = SvIVX(TOPs);
+
SP--;
if (biv < 0) {
/* As (a) is a UV, it's >=0, so it must be >= */
RETURN;
}
{ /* ## IV >= UV ## */
- IV aiv;
+ const IV aiv = SvIVX(TOPm1s);
UV buv;
-
- aiv = SvIVX(TOPm1s);
+
if (aiv < 0) {
/* As (b) is a UV, it's >=0, so a cannot be >= */
SP--;
differ from normal zero. As I understand it. (Need to
check - is negative zero implementation defined behaviour
anyway?). NWC */
- UV buv = SvUVX(POPs);
- UV auv = SvUVX(TOPs);
-
+ const UV buv = SvUVX(POPs);
+ const UV auv = SvUVX(TOPs);
+
SETs(boolSV(auv != buv));
RETURN;
}
if (SvIOK(TOPs)) {
SvIV_please(TOPm1s);
if (SvIOK(TOPm1s)) {
- bool leftuvok = SvUOK(TOPm1s);
- bool rightuvok = SvUOK(TOPs);
+ const bool leftuvok = SvUOK(TOPm1s);
+ const bool rightuvok = SvUOK(TOPs);
I32 value;
if (!leftuvok && !rightuvok) { /* ## IV <=> IV ## */
- IV leftiv = SvIVX(TOPm1s);
- IV rightiv = SvIVX(TOPs);
+ const IV leftiv = SvIVX(TOPm1s);
+ const IV rightiv = SvIVX(TOPs);
if (leftiv > rightiv)
value = 1;
else
value = 0;
} else if (leftuvok && rightuvok) { /* ## UV <=> UV ## */
- UV leftuv = SvUVX(TOPm1s);
- UV rightuv = SvUVX(TOPs);
+ const UV leftuv = SvUVX(TOPm1s);
+ const UV rightuv = SvUVX(TOPs);
if (leftuv > rightuv)
value = 1;
else
value = 0;
} else if (leftuvok) { /* ## UV <=> IV ## */
- UV leftuv;
- IV rightiv;
-
- rightiv = SvIVX(TOPs);
+ const IV rightiv = SvIVX(TOPs);
if (rightiv < 0) {
/* As (a) is a UV, it's >=0, so it cannot be < */
value = 1;
} else {
- leftuv = SvUVX(TOPm1s);
+ const UV leftuv = SvUVX(TOPm1s);
if (leftuv > (UV)rightiv) {
value = 1;
} else if (leftuv < (UV)rightiv) {
}
}
} else { /* ## IV <=> UV ## */
- IV leftiv;
- UV rightuv;
-
- leftiv = SvIVX(TOPm1s);
+ const IV leftiv = SvIVX(TOPm1s);
if (leftiv < 0) {
/* As (b) is a UV, it's >=0, so it must be < */
value = -1;
} else {
- rightuv = SvUVX(TOPs);
+ const UV rightuv = SvUVX(TOPs);
if ((UV)leftiv > rightuv) {
value = 1;
} else if ((UV)leftiv < rightuv) {
dSP; tryAMAGICbinSET(slt,0);
{
dPOPTOPssrl;
- int cmp = (IN_LOCALE_RUNTIME
+ const int cmp = (IN_LOCALE_RUNTIME
? sv_cmp_locale(left, right)
: sv_cmp(left, right));
SETs(boolSV(cmp < 0));
dSP; tryAMAGICbinSET(sgt,0);
{
dPOPTOPssrl;
- int cmp = (IN_LOCALE_RUNTIME
+ const int cmp = (IN_LOCALE_RUNTIME
? sv_cmp_locale(left, right)
: sv_cmp(left, right));
SETs(boolSV(cmp > 0));
dSP; tryAMAGICbinSET(sle,0);
{
dPOPTOPssrl;
- int cmp = (IN_LOCALE_RUNTIME
+ const int cmp = (IN_LOCALE_RUNTIME
? sv_cmp_locale(left, right)
: sv_cmp(left, right));
SETs(boolSV(cmp <= 0));
dSP; tryAMAGICbinSET(sge,0);
{
dPOPTOPssrl;
- int cmp = (IN_LOCALE_RUNTIME
+ const int cmp = (IN_LOCALE_RUNTIME
? sv_cmp_locale(left, right)
: sv_cmp(left, right));
SETs(boolSV(cmp >= 0));
dSP; dTARGET; tryAMAGICbin(scmp,0);
{
dPOPTOPssrl;
- int cmp = (IN_LOCALE_RUNTIME
+ const int cmp = (IN_LOCALE_RUNTIME
? sv_cmp_locale(left, right)
: sv_cmp(left, right));
SETi( cmp );
dSP; dATARGET; tryAMAGICbin(band,opASSIGN);
{
dPOPTOPssrl;
- if (SvGMAGICAL(left)) mg_get(left);
- if (SvGMAGICAL(right)) mg_get(right);
+ SvGETMAGIC(left);
+ SvGETMAGIC(right);
if (SvNIOKp(left) || SvNIOKp(right)) {
if (PL_op->op_private & HINT_INTEGER) {
- IV i = SvIV_nomg(left) & SvIV_nomg(right);
+ const IV i = SvIV_nomg(left) & SvIV_nomg(right);
SETi(i);
}
else {
- UV u = SvUV_nomg(left) & SvUV_nomg(right);
+ const UV u = SvUV_nomg(left) & SvUV_nomg(right);
SETu(u);
}
}
dSP; dATARGET; tryAMAGICbin(bxor,opASSIGN);
{
dPOPTOPssrl;
- if (SvGMAGICAL(left)) mg_get(left);
- if (SvGMAGICAL(right)) mg_get(right);
+ SvGETMAGIC(left);
+ SvGETMAGIC(right);
if (SvNIOKp(left) || SvNIOKp(right)) {
if (PL_op->op_private & HINT_INTEGER) {
- IV i = (USE_LEFT(left) ? SvIV_nomg(left) : 0) ^ SvIV_nomg(right);
+ const IV i = (USE_LEFT(left) ? SvIV_nomg(left) : 0) ^ SvIV_nomg(right);
SETi(i);
}
else {
- UV u = (USE_LEFT(left) ? SvUV_nomg(left) : 0) ^ SvUV_nomg(right);
+ const UV u = (USE_LEFT(left) ? SvUV_nomg(left) : 0) ^ SvUV_nomg(right);
SETu(u);
}
}
dSP; dATARGET; tryAMAGICbin(bor,opASSIGN);
{
dPOPTOPssrl;
- if (SvGMAGICAL(left)) mg_get(left);
- if (SvGMAGICAL(right)) mg_get(right);
+ SvGETMAGIC(left);
+ SvGETMAGIC(right);
if (SvNIOKp(left) || SvNIOKp(right)) {
if (PL_op->op_private & HINT_INTEGER) {
- IV i = (USE_LEFT(left) ? SvIV_nomg(left) : 0) | SvIV_nomg(right);
+ const IV i = (USE_LEFT(left) ? SvIV_nomg(left) : 0) | SvIV_nomg(right);
SETi(i);
}
else {
- UV u = (USE_LEFT(left) ? SvUV_nomg(left) : 0) | SvUV_nomg(right);
+ const UV u = (USE_LEFT(left) ? SvUV_nomg(left) : 0) | SvUV_nomg(right);
SETu(u);
}
}
dSP; dTARGET; tryAMAGICun(neg);
{
dTOPss;
- int flags = SvFLAGS(sv);
- if (SvGMAGICAL(sv))
- mg_get(sv);
+ const int flags = SvFLAGS(sv);
+ SvGETMAGIC(sv);
if ((flags & SVf_IOK) || ((flags & (SVp_IOK | SVp_NOK)) == SVp_IOK)) {
/* It's publicly an integer, or privately an integer-not-float */
oops_its_an_int:
SETn(-SvNV(sv));
else if (SvPOKp(sv)) {
STRLEN len;
- char *s = SvPV(sv, len);
+ const char *s = SvPV_const(sv, len);
if (isIDFIRST(*s)) {
sv_setpvn(TARG, "-", 1);
sv_catsv(TARG, sv);
dSP; dTARGET; tryAMAGICun(compl);
{
dTOPss;
- if (SvGMAGICAL(sv))
- mg_get(sv);
+ SvGETMAGIC(sv);
if (SvNIOKp(sv)) {
if (PL_op->op_private & HINT_INTEGER) {
- IV i = ~SvIV_nomg(sv);
+ const IV i = ~SvIV_nomg(sv);
SETi(i);
}
else {
- UV u = ~SvUV_nomg(sv);
+ const UV u = ~SvUV_nomg(sv);
SETu(u);
}
}
register I32 anum;
STRLEN len;
- (void)SvPV_nomg(sv,len); /* force check for uninit var */
+ (void)SvPV_nomg_const(sv,len); /* force check for uninit var */
sv_setsv_nomg(TARG, sv);
tmps = (U8*)SvPV_force(TARG, len);
anum = len;
send = tmps + len;
while (tmps < send) {
- UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV);
+ const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV);
tmps += UTF8SKIP(tmps);
targlen += UNISKIP(~c);
nchar++;
tmps -= len;
if (nwide) {
- Newz(0, result, targlen + 1, U8);
+ Newxz(result, targlen + 1, U8);
while (tmps < send) {
- UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV);
+ const UV c = utf8n_to_uvchr(tmps, send-tmps, &l, UTF8_ALLOW_ANYUV);
tmps += UTF8SKIP(tmps);
result = uvchr_to_utf8_flags(result, ~c, UNICODE_ALLOW_ANY);
}
SvUTF8_on(TARG);
}
else {
- Newz(0, result, nchar + 1, U8);
+ Newxz(result, nchar + 1, U8);
while (tmps < send) {
- U8 c = (U8)utf8n_to_uvchr(tmps, 0, &l, UTF8_ALLOW_ANY);
+ const U8 c = (U8)utf8n_to_uvchr(tmps, 0, &l, UTF8_ALLOW_ANY);
tmps += UTF8SKIP(tmps);
*result++ = ~c;
}
/* The assumption is to use hereafter the old vanilla version... */
PL_op->op_ppaddr =
PL_ppaddr[OP_I_MODULO] =
- &Perl_pp_i_modulo_0;
+ Perl_pp_i_modulo_0;
/* .. but if we have glibc, we might have a buggy _moddi3
* (at least glicb 2.2.5 is known to have this bug), in other
* words our integer modulus with negative quad as the second
{
dSP; dTARGET; tryAMAGICun(sin);
{
- NV value;
- value = POPn;
- value = Perl_sin(value);
- XPUSHn(value);
+ const NV value = POPn;
+ XPUSHn(Perl_sin(value));
RETURN;
}
}
{
dSP; dTARGET; tryAMAGICun(cos);
{
- NV value;
- value = POPn;
- value = Perl_cos(value);
- XPUSHn(value);
+ const NV value = POPn;
+ XPUSHn(Perl_cos(value));
RETURN;
}
}
{
dSP; dTARGET; tryAMAGICun(log);
{
- NV value;
- value = POPn;
+ const NV value = POPn;
if (value <= 0.0) {
SET_NUMERIC_STANDARD();
DIE(aTHX_ "Can't take log of %"NVgf, value);
}
- value = Perl_log(value);
- XPUSHn(value);
+ XPUSHn(Perl_log(value));
RETURN;
}
}
{
dSP; dTARGET; tryAMAGICun(sqrt);
{
- NV value;
- value = POPn;
+ const NV value = POPn;
if (value < 0.0) {
SET_NUMERIC_STANDARD();
DIE(aTHX_ "Can't take sqrt of %"NVgf, value);
}
- value = Perl_sqrt(value);
- XPUSHn(value);
+ XPUSHn(Perl_sqrt(value));
RETURN;
}
}
{
dSP; dTARGET; tryAMAGICun(int);
{
- NV value;
- IV iv = TOPi; /* attempt to convert to IV if possible. */
+ const IV iv = TOPi; /* attempt to convert to IV if possible. */
/* XXX it's arguable that compiler casting to IV might be subtly
different from modf (for numbers inside (IV_MIN,UV_MAX)) in which
else preferring IV has introduced a subtle behaviour change bug. OTOH
SETu(0);
else if (SvIOK(TOPs)) {
if (SvIsUV(TOPs)) {
- UV uv = TOPu;
+ const UV uv = TOPu;
SETu(uv);
} else
SETi(iv);
} else {
- value = TOPn;
+ const NV value = TOPn;
if (value >= 0.0) {
if (value < (NV)UV_MAX + 0.5) {
SETu(U_V(value));
dSP; dTARGET; tryAMAGICun(abs);
{
/* This will cache the NV value if string isn't actually integer */
- IV iv = TOPi;
+ const IV iv = TOPi;
if (!SvOK(TOPs))
SETu(0);
}
}
} else{
- NV value = TOPn;
+ const NV value = TOPn;
if (value < 0.0)
- value = -value;
- SETn(value);
+ SETn(-value);
+ else
+ SETn(value);
}
}
RETURN;
PP(pp_hex)
{
dSP; dTARGET;
- char *tmps;
+ const char *tmps;
I32 flags = PERL_SCAN_ALLOW_UNDERSCORES;
STRLEN len;
NV result_nv;
UV result_uv;
- SV* sv = POPs;
+ SV* const sv = POPs;
- tmps = (SvPVx(sv, len));
+ tmps = (SvPV_const(sv, len));
if (DO_UTF8(sv)) {
/* If Unicode, try to downgrade
* If not possible, croak. */
- SV* tsv = sv_2mortal(newSVsv(sv));
+ SV* const tsv = sv_2mortal(newSVsv(sv));
SvUTF8_on(tsv);
sv_utf8_downgrade(tsv, FALSE);
- tmps = SvPVX(tsv);
+ tmps = SvPV_const(tsv, len);
}
result_uv = grok_hex (tmps, &len, &flags, &result_nv);
if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) {
PP(pp_oct)
{
dSP; dTARGET;
- char *tmps;
+ const char *tmps;
I32 flags = PERL_SCAN_ALLOW_UNDERSCORES;
STRLEN len;
NV result_nv;
UV result_uv;
- SV* sv = POPs;
+ SV* const sv = POPs;
- tmps = (SvPVx(sv, len));
+ tmps = (SvPV_const(sv, len));
if (DO_UTF8(sv)) {
/* If Unicode, try to downgrade
* If not possible, croak. */
- SV* tsv = sv_2mortal(newSVsv(sv));
+ SV* const tsv = sv_2mortal(newSVsv(sv));
SvUTF8_on(tsv);
sv_utf8_downgrade(tsv, FALSE);
- tmps = SvPVX(tsv);
+ tmps = SvPV_const(tsv, len);
}
while (*tmps && len && isSPACE(*tmps))
tmps++, len--;
SV *repl_sv = NULL;
const char *repl = 0;
STRLEN repl_len;
- int num_args = PL_op->op_private & 7;
+ const int num_args = PL_op->op_private & 7;
bool repl_need_utf8_upgrade = FALSE;
bool repl_is_utf8 = FALSE;
if (num_args > 2) {
if (num_args > 3) {
repl_sv = POPs;
- repl = SvPV(repl_sv, repl_len);
+ repl = SvPV_const(repl_sv, repl_len);
repl_is_utf8 = DO_UTF8(repl_sv) && SvCUR(repl_sv);
}
len = POPi;
else if (DO_UTF8(sv))
repl_need_utf8_upgrade = TRUE;
}
- tmps = SvPV(sv, curlen);
+ tmps = SvPV_const(sv, curlen);
if (DO_UTF8(sv)) {
utf8_curlen = sv_len_utf8(sv);
if (utf8_curlen == curlen)
RETPUSHUNDEF;
}
else {
- I32 upos = pos;
- I32 urem = rem;
+ const I32 upos = pos;
+ const I32 urem = rem;
if (utf8_curlen)
sv_pos_u2b(sv, &pos, &rem);
tmps += pos;
if (repl_need_utf8_upgrade) {
repl_sv_copy = newSVsv(repl_sv);
sv_utf8_upgrade(repl_sv_copy);
- repl = SvPV(repl_sv_copy, repl_len);
+ repl = SvPV_const(repl_sv_copy, repl_len);
repl_is_utf8 = DO_UTF8(repl_sv_copy) && SvCUR(sv);
}
sv_insert(sv, pos, rem, repl, repl_len);
else if (lvalue) { /* it's an lvalue! */
if (!SvGMAGICAL(sv)) {
if (SvROK(sv)) {
- STRLEN n_a;
- SvPV_force(sv,n_a);
+ SvPV_force_nolen(sv);
if (ckWARN(WARN_SUBSTR))
Perl_warner(aTHX_ packWARN(WARN_SUBSTR),
"Attempt to use reference as lvalue in substr");
PP(pp_vec)
{
dSP; dTARGET;
- register IV size = POPi;
- register IV offset = POPi;
- register SV *src = POPs;
- I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET;
+ register const IV size = POPi;
+ register const IV offset = POPi;
+ register SV * const src = POPs;
+ const I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET;
SvTAINTED_off(TARG); /* decontaminate */
if (lvalue) { /* it's an lvalue! */
SV *temp = Nullsv;
I32 offset;
I32 retval;
- char *tmps;
- char *tmps2;
+ const char *tmps;
+ const char *tmps2;
STRLEN biglen;
- I32 arybase = PL_curcop->cop_arybase;
+ const I32 arybase = PL_curcop->cop_arybase;
int big_utf8;
int little_utf8;
little_utf8 = DO_UTF8(little);
if (big_utf8 ^ little_utf8) {
/* One needs to be upgraded. */
- SV *bytes = little_utf8 ? big : little;
+ SV * const bytes = little_utf8 ? big : little;
STRLEN len;
- char *p = SvPV(bytes, len);
+ const char * const p = SvPV_const(bytes, len);
temp = newSVpvn(p, len);
}
if (big_utf8 && offset > 0)
sv_pos_u2b(big, &offset, 0);
- tmps = SvPV(big, biglen);
+ tmps = SvPV_const(big, biglen);
if (offset < 0)
offset = 0;
else if (offset > (I32)biglen)
STRLEN llen;
I32 offset;
I32 retval;
- char *tmps;
- char *tmps2;
- I32 arybase = PL_curcop->cop_arybase;
+ const char *tmps;
+ const char *tmps2;
+ const I32 arybase = PL_curcop->cop_arybase;
int big_utf8;
int little_utf8;
little_utf8 = DO_UTF8(little);
if (big_utf8 ^ little_utf8) {
/* One needs to be upgraded. */
- SV *bytes = little_utf8 ? big : little;
+ SV * const bytes = little_utf8 ? big : little;
STRLEN len;
- char *p = SvPV(bytes, len);
+ const char *p = SvPV_const(bytes, len);
temp = newSVpvn(p, len);
little = temp;
}
}
- tmps2 = SvPV(little, llen);
- tmps = SvPV(big, blen);
+ tmps2 = SvPV_const(little, llen);
+ tmps = SvPV_const(big, blen);
if (MAXARG < 3)
offset = blen;
dSP; dTARGET;
SV *argsv = POPs;
STRLEN len;
- U8 *s = (U8*)SvPVx(argsv, len);
+ const U8 *s = (U8*)SvPV_const(argsv, len);
SV *tmpsv;
if (PL_encoding && SvPOK(argsv) && !DO_UTF8(argsv)) {
{
dSP; dTARGET;
char *tmps;
- UV value = POPu;
+ UV value;
+
+ if (((SvIOK_notUV(TOPs) && SvIV(TOPs) < 0)
+ ||
+ (SvNOK(TOPs) && SvNV(TOPs) < 0.0))) {
+ if (IN_BYTES) {
+ value = POPu; /* chr(-1) eq chr(0xff), etc. */
+ } else {
+ (void) POPs; /* Ignore the argument value. */
+ value = UNICODE_REPLACEMENT;
+ }
+ } else {
+ value = POPu;
+ }
- (void)SvUPGRADE(TARG,SVt_PV);
+ SvUPGRADE(TARG,SVt_PV);
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));
+ SvCUR_set(TARG, tmps - SvPVX_const(TARG));
*tmps = '\0';
(void)SvPOK_only(TARG);
SvUTF8_on(TARG);
#ifdef HAS_CRYPT
dSP; dTARGET;
dPOPTOPssrl;
- STRLEN n_a;
STRLEN len;
- char *tmps = SvPV(left, len);
+ const char *tmps = SvPV_const(left, len);
if (DO_UTF8(left)) {
/* If Unicode, try to downgrade.
* If not possible, croak.
* Yes, we made this up. */
- SV* tsv = sv_2mortal(newSVsv(left));
+ SV* const tsv = sv_2mortal(newSVsv(left));
SvUTF8_on(tsv);
sv_utf8_downgrade(tsv, FALSE);
- tmps = SvPVX(tsv);
+ tmps = SvPV_const(tsv, len);
}
# ifdef USE_ITHREADS
# ifdef HAS_CRYPT_R
# endif /* HAS_CRYPT_R */
# endif /* USE_ITHREADS */
# ifdef FCRYPT
- sv_setpv(TARG, fcrypt(tmps, SvPV(right, n_a)));
+ sv_setpv(TARG, fcrypt(tmps, SvPV_nolen_const(right)));
# else
- sv_setpv(TARG, PerlProc_crypt(tmps, SvPV(right, n_a)));
+ sv_setpv(TARG, PerlProc_crypt(tmps, SvPV_nolen_const(right)));
# endif
SETs(TARG);
RETURN;
{
dSP;
SV *sv = TOPs;
- register U8 *s;
+ const U8 *s;
STRLEN slen;
SvGETMAGIC(sv);
if (DO_UTF8(sv) &&
- (s = (U8*)SvPV_nomg(sv, slen)) && slen &&
+ (s = (const U8*)SvPV_nomg_const(sv, slen)) && slen &&
UTF8_IS_START(*s)) {
U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
STRLEN ulen;
}
}
else {
+ U8 *s1;
if (!SvPADTMP(sv) || SvREADONLY(sv)) {
dTARGET;
SvUTF8_off(TARG); /* decontaminate */
sv = TARG;
SETs(sv);
}
- s = (U8*)SvPV_force_nomg(sv, slen);
- if (*s) {
+ s1 = (U8*)SvPV_force_nomg(sv, slen);
+ if (*s1) {
if (IN_LOCALE_RUNTIME) {
TAINT;
SvTAINTED_on(sv);
- *s = toUPPER_LC(*s);
+ *s1 = toUPPER_LC(*s1);
}
else
- *s = toUPPER(*s);
+ *s1 = toUPPER(*s1);
}
}
SvSETMAGIC(sv);
{
dSP;
SV *sv = TOPs;
- register U8 *s;
+ const U8 *s;
STRLEN slen;
SvGETMAGIC(sv);
if (DO_UTF8(sv) &&
- (s = (U8*)SvPV_nomg(sv, slen)) && slen &&
+ (s = (const U8*)SvPV_nomg_const(sv, slen)) && slen &&
UTF8_IS_START(*s)) {
STRLEN ulen;
U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
}
}
else {
+ U8 *s1;
if (!SvPADTMP(sv) || SvREADONLY(sv)) {
dTARGET;
SvUTF8_off(TARG); /* decontaminate */
sv = TARG;
SETs(sv);
}
- s = (U8*)SvPV_force_nomg(sv, slen);
- if (*s) {
+ s1 = (U8*)SvPV_force_nomg(sv, slen);
+ if (*s1) {
if (IN_LOCALE_RUNTIME) {
TAINT;
SvTAINTED_on(sv);
- *s = toLOWER_LC(*s);
+ *s1 = toLOWER_LC(*s1);
}
else
- *s = toLOWER(*s);
+ *s1 = toLOWER(*s1);
}
}
SvSETMAGIC(sv);
{
dSP;
SV *sv = TOPs;
- register U8 *s;
STRLEN len;
SvGETMAGIC(sv);
dTARGET;
STRLEN ulen;
register U8 *d;
- U8 *send;
+ const U8 *s;
+ const U8 *send;
U8 tmpbuf[UTF8_MAXBYTES+1];
- s = (U8*)SvPV_nomg(sv,len);
+ s = (const U8*)SvPV_nomg_const(sv,len);
if (!len) {
SvUTF8_off(TARG); /* decontaminate */
sv_setpvn(TARG, "", 0);
else {
STRLEN min = len + 1;
- (void)SvUPGRADE(TARG, SVt_PV);
+ SvUPGRADE(TARG, SVt_PV);
SvGROW(TARG, min);
(void)SvPOK_only(TARG);
d = (U8*)SvPVX(TARG);
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_const(TARG);
/* If someone uppercases one million U+03B0s we
* SvGROW() one million times. Or we could try
}
*d = '\0';
SvUTF8_on(TARG);
- SvCUR_set(TARG, d - (U8*)SvPVX(TARG));
+ SvCUR_set(TARG, d - (U8*)SvPVX_const(TARG));
SETs(TARG);
}
}
else {
+ U8 *s;
if (!SvPADTMP(sv) || SvREADONLY(sv)) {
dTARGET;
SvUTF8_off(TARG); /* decontaminate */
}
s = (U8*)SvPV_force_nomg(sv, len);
if (len) {
- register U8 *send = s + len;
+ register const U8 *send = s + len;
if (IN_LOCALE_RUNTIME) {
TAINT;
{
dSP;
SV *sv = TOPs;
- register U8 *s;
STRLEN len;
SvGETMAGIC(sv);
if (DO_UTF8(sv)) {
dTARGET;
+ const U8 *s;
STRLEN ulen;
register U8 *d;
- U8 *send;
+ const U8 *send;
U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
- s = (U8*)SvPV_nomg(sv,len);
+ s = (const U8*)SvPV_nomg_const(sv,len);
if (!len) {
SvUTF8_off(TARG); /* decontaminate */
sv_setpvn(TARG, "", 0);
else {
STRLEN min = len + 1;
- (void)SvUPGRADE(TARG, SVt_PV);
+ SvUPGRADE(TARG, SVt_PV);
SvGROW(TARG, min);
(void)SvPOK_only(TARG);
d = (U8*)SvPVX(TARG);
send = s + len;
while (s < send) {
- STRLEN u = UTF8SKIP(s);
- UV uv = toLOWER_utf8(s, tmpbuf, &ulen);
+ const STRLEN u = UTF8SKIP(s);
+ const UV uv = toLOWER_utf8(s, tmpbuf, &ulen);
#define GREEK_CAPITAL_LETTER_SIGMA 0x03A3 /* Unicode U+03A3 */
if (uv == GREEK_CAPITAL_LETTER_SIGMA) {
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_const(TARG);
/* If someone lowercases one million U+0130s we
* SvGROW() one million times. Or we could try
}
*d = '\0';
SvUTF8_on(TARG);
- SvCUR_set(TARG, d - (U8*)SvPVX(TARG));
+ SvCUR_set(TARG, d - (U8*)SvPVX_const(TARG));
SETs(TARG);
}
}
else {
+ U8 *s;
if (!SvPADTMP(sv) || SvREADONLY(sv)) {
dTARGET;
SvUTF8_off(TARG); /* decontaminate */
s = (U8*)SvPV_force_nomg(sv, len);
if (len) {
- register U8 *send = s + len;
+ register const U8 * const send = s + len;
if (IN_LOCALE_RUNTIME) {
TAINT;
PP(pp_quotemeta)
{
dSP; dTARGET;
- SV *sv = TOPs;
+ SV * const sv = TOPs;
STRLEN len;
- register char *s = SvPV(sv,len);
- register char *d;
+ register const char *s = SvPV_const(sv,len);
SvUTF8_off(TARG); /* decontaminate */
if (len) {
- (void)SvUPGRADE(TARG, SVt_PV);
+ register char *d;
+ SvUPGRADE(TARG, SVt_PV);
SvGROW(TARG, (len * 2) + 1);
d = SvPVX(TARG);
if (DO_UTF8(sv)) {
}
}
*d = '\0';
- SvCUR_set(TARG, d - SvPVX(TARG));
+ SvCUR_set(TARG, d - SvPVX_const(TARG));
(void)SvPOK_only_UTF8(TARG);
}
else
PP(pp_aslice)
{
dSP; dMARK; dORIGMARK;
- register SV** svp;
- register AV* av = (AV*)POPs;
- register I32 lval = (PL_op->op_flags & OPf_MOD || LVRET);
- I32 arybase = PL_curcop->cop_arybase;
- I32 elem;
+ register AV* const av = (AV*)POPs;
+ register const I32 lval = (PL_op->op_flags & OPf_MOD || LVRET);
if (SvTYPE(av) == SVt_PVAV) {
+ const I32 arybase = PL_curcop->cop_arybase;
if (lval && PL_op->op_private & OPpLVAL_INTRO) {
+ register SV **svp;
I32 max = -1;
for (svp = MARK + 1; svp <= SP; svp++) {
- elem = SvIVx(*svp);
+ const I32 elem = SvIVx(*svp);
if (elem > max)
max = elem;
}
av_extend(av, max);
}
while (++MARK <= SP) {
- elem = SvIVx(*MARK);
+ register SV **svp;
+ I32 elem = SvIVx(*MARK);
if (elem > 0)
elem -= arybase;
PP(pp_each)
{
dSP;
- HV *hash = (HV*)POPs;
+ HV * const hash = (HV*)POPs;
HE *entry;
- I32 gimme = GIMME_V;
+ const I32 gimme = GIMME_V;
PUTBACK;
/* might clobber stack_sp */
EXTEND(SP, 2);
if (entry) {
- SV* sv = hv_iterkeysv(entry);
+ SV* const sv = hv_iterkeysv(entry);
PUSHs(sv); /* won't clobber stack_sp */
if (gimme == G_ARRAY) {
SV *val;
RETURN;
}
-PP(pp_values)
-{
- return do_kv();
-}
-
-PP(pp_keys)
-{
- return do_kv();
-}
-
PP(pp_delete)
{
dSP;
- I32 gimme = GIMME_V;
- I32 discard = (gimme == G_VOID) ? G_DISCARD : 0;
- SV *sv;
- HV *hv;
+ const I32 gimme = GIMME_V;
+ const I32 discard = (gimme == G_VOID) ? G_DISCARD : 0;
if (PL_op->op_private & OPpSLICE) {
dMARK; dORIGMARK;
- U32 hvtype;
- hv = (HV*)POPs;
- hvtype = SvTYPE(hv);
+ HV * const hv = (HV*)POPs;
+ const U32 hvtype = SvTYPE(hv);
if (hvtype == SVt_PVHV) { /* hash element */
while (++MARK <= SP) {
- sv = hv_delete_ent(hv, *MARK, discard, 0);
+ SV * const sv = hv_delete_ent(hv, *MARK, discard, 0);
*MARK = sv ? sv : &PL_sv_undef;
}
}
else if (hvtype == SVt_PVAV) { /* array element */
if (PL_op->op_flags & OPf_SPECIAL) {
while (++MARK <= SP) {
- sv = av_delete((AV*)hv, SvIV(*MARK), discard);
+ SV * const sv = av_delete((AV*)hv, SvIV(*MARK), discard);
*MARK = sv ? sv : &PL_sv_undef;
}
}
}
else {
SV *keysv = POPs;
- hv = (HV*)POPs;
+ HV * const hv = (HV*)POPs;
+ SV *sv;
if (SvTYPE(hv) == SVt_PVHV)
sv = hv_delete_ent(hv, keysv, discard, 0);
else if (SvTYPE(hv) == SVt_PVAV) {
if (PL_op->op_private & OPpEXISTS_SUB) {
GV *gv;
- CV *cv;
SV *sv = POPs;
- cv = sv_2cv(sv, &hv, &gv, FALSE);
+ CV * const cv = sv_2cv(sv, &hv, &gv, FALSE);
if (cv)
RETPUSHYES;
if (gv && isGV(gv) && GvCV(gv) && !GvCVGEN(gv))
PP(pp_hslice)
{
dSP; dMARK; dORIGMARK;
- register HV *hv = (HV*)POPs;
- register I32 lval = (PL_op->op_flags & OPf_MOD || LVRET);
- bool localizing = PL_op->op_private & OPpLVAL_INTRO ? TRUE : FALSE;
+ register HV * const hv = (HV*)POPs;
+ register const I32 lval = (PL_op->op_flags & OPf_MOD || LVRET);
+ const bool localizing = PL_op->op_private & OPpLVAL_INTRO;
bool other_magic = FALSE;
if (localizing) {
}
while (++MARK <= SP) {
- SV *keysv = *MARK;
+ SV * const keysv = *MARK;
SV **svp;
HE *he;
bool preeminent = FALSE;
if (lval) {
if (!svp || *svp == &PL_sv_undef) {
- STRLEN n_a;
- DIE(aTHX_ PL_no_helem, SvPV(keysv, n_a));
+ DIE(aTHX_ PL_no_helem_sv, keysv);
}
if (localizing) {
if (preeminent)
save_helem(hv, keysv, svp);
else {
STRLEN keylen;
- char *key = SvPV(keysv, keylen);
+ const char *key = SvPV_const(keysv, keylen);
SAVEDELETE(hv, savepvn(key,keylen), keylen);
}
}
PP(pp_lslice)
{
dSP;
- SV **lastrelem = PL_stack_sp;
- SV **lastlelem = PL_stack_base + POPMARK;
- SV **firstlelem = PL_stack_base + POPMARK + 1;
- register SV **firstrelem = lastlelem + 1;
- I32 arybase = PL_curcop->cop_arybase;
- I32 lval = PL_op->op_flags & OPf_MOD;
- I32 is_something_there = lval;
-
- register I32 max = lastrelem - lastlelem;
+ SV ** const lastrelem = PL_stack_sp;
+ SV ** const lastlelem = PL_stack_base + POPMARK;
+ SV ** const firstlelem = PL_stack_base + POPMARK + 1;
+ register SV ** const firstrelem = lastlelem + 1;
+ const I32 arybase = PL_curcop->cop_arybase;
+ I32 is_something_there = PL_op->op_flags & OPf_MOD;
+
+ register const I32 max = lastrelem - lastlelem;
register SV **lelem;
- register I32 ix;
if (GIMME != G_ARRAY) {
- ix = SvIVx(*lastlelem);
+ I32 ix = SvIVx(*lastlelem);
if (ix < 0)
ix += max;
else
}
for (lelem = firstlelem; lelem <= lastlelem; lelem++) {
- ix = SvIVx(*lelem);
+ I32 ix = SvIVx(*lelem);
if (ix < 0)
ix += max;
else
PP(pp_anonlist)
{
dSP; dMARK; dORIGMARK;
- I32 items = SP - MARK;
- SV *av = sv_2mortal((SV*)av_make(items, MARK+1));
+ const I32 items = SP - MARK;
+ SV * const av = sv_2mortal((SV*)av_make(items, MARK+1));
SP = ORIGMARK; /* av_make() might realloc stack_sp */
XPUSHs(av);
RETURN;
PP(pp_anonhash)
{
dSP; dMARK; dORIGMARK;
- HV* hv = (HV*)sv_2mortal((SV*)newHV());
+ HV* const hv = (HV*)sv_2mortal((SV*)newHV());
while (MARK < SP) {
- SV* key = *++MARK;
- SV *val = NEWSV(46, 0);
+ SV * const key = *++MARK;
+ SV * const val = NEWSV(46, 0);
if (MARK < SP)
sv_setsv(val, *++MARK);
else if (ckWARN(WARN_MISC))
I32 after;
I32 diff;
SV **tmparyval = 0;
- MAGIC *mg;
+ const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
- if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) {
+ if (mg) {
*MARK-- = SvTIED_obj((SV*)ary, mg);
PUSHMARK(MARK);
PUTBACK;
/* make new elements SVs now: avoid problems if they're from the array */
for (dst = MARK, i = newlen; i; i--) {
- SV *h = *dst;
+ SV * const h = *dst;
*dst++ = newSVsv(h);
}
if (diff < 0) { /* shrinking the area */
if (newlen) {
- New(451, tmparyval, newlen, SV*); /* so remember insertion */
+ Newx(tmparyval, newlen, SV*); /* so remember insertion */
Copy(MARK, tmparyval, newlen, SV*);
}
}
else { /* no, expanding (or same) */
if (length) {
- New(452, tmparyval, length, SV*); /* so remember deletion */
+ Newx(tmparyval, length, SV*); /* so remember deletion */
Copy(AvARRAY(ary)+offset, tmparyval, length, SV*);
}
{
dVAR; dSP; dMARK; dORIGMARK; dTARGET;
register AV *ary = (AV*)*++MARK;
- register SV *sv = &PL_sv_undef;
- MAGIC *mg;
+ const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
- if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) {
+ if (mg) {
*MARK-- = SvTIED_obj((SV*)ary, mg);
PUSHMARK(MARK);
PUTBACK;
call_method("PUSH",G_SCALAR|G_DISCARD);
LEAVE;
SPAGAIN;
+ SP = ORIGMARK;
+ PUSHi( AvFILL(ary) + 1 );
}
else {
- /* Why no pre-extend of ary here ? */
for (++MARK; MARK <= SP; MARK++) {
- sv = NEWSV(51, 0);
+ SV * const sv = NEWSV(51, 0);
if (*MARK)
sv_setsv(sv, *MARK);
- av_push(ary, sv);
+ av_store(ary, AvFILLp(ary)+1, sv);
}
+ SP = ORIGMARK;
+ PUSHi( AvFILLp(ary) + 1 );
}
- SP = ORIGMARK;
- PUSHi( AvFILL(ary) + 1 );
RETURN;
}
PP(pp_pop)
{
dSP;
- AV *av = (AV*)POPs;
- SV *sv = av_pop(av);
+ AV * const av = (AV*)POPs;
+ SV * const sv = av_pop(av);
if (AvREAL(av))
(void)sv_2mortal(sv);
PUSHs(sv);
PP(pp_shift)
{
dSP;
- AV *av = (AV*)POPs;
- SV *sv = av_shift(av);
+ AV * const av = (AV*)POPs;
+ SV * const sv = av_shift(av);
EXTEND(SP, 1);
if (!sv)
RETPUSHUNDEF;
{
dVAR; dSP; dMARK; dORIGMARK; dTARGET;
register AV *ary = (AV*)*++MARK;
- register SV *sv;
- register I32 i = 0;
- MAGIC *mg;
+ const MAGIC * const mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied);
- if ((mg = SvTIED_mg((SV*)ary, PERL_MAGIC_tied))) {
+ if (mg) {
*MARK-- = SvTIED_obj((SV*)ary, mg);
PUSHMARK(MARK);
PUTBACK;
SPAGAIN;
}
else {
+ register I32 i = 0;
av_unshift(ary, SP - MARK);
while (MARK < SP) {
- sv = newSVsv(*++MARK);
+ SV * const sv = newSVsv(*++MARK);
(void)av_store(ary, i++, sv);
}
}
PP(pp_reverse)
{
dSP; dMARK;
- register SV *tmp;
- SV **oldsp = SP;
+ SV ** const oldsp = SP;
if (GIMME == G_ARRAY) {
MARK++;
while (MARK < SP) {
- tmp = *MARK;
+ register SV * const tmp = *MARK;
*MARK++ = *SP;
*SP-- = tmp;
}
if (len > 1) {
if (DO_UTF8(TARG)) { /* first reverse each character */
U8* s = (U8*)SvPVX(TARG);
- U8* send = (U8*)(s + len);
+ const U8* send = (U8*)(s + len);
while (s < send) {
if (UTF8_IS_INVARIANT(*s)) {
s++;
dVAR; dSP; dTARG;
AV *ary;
register IV limit = POPi; /* note, negative is forever */
- SV *sv = POPs;
+ SV * const sv = POPs;
STRLEN len;
- register char *s = SvPV(sv, len);
- bool do_utf8 = DO_UTF8(sv);
- char *strend = s + len;
+ register const char *s = SvPV_const(sv, len);
+ const bool do_utf8 = DO_UTF8(sv);
+ const char *strend = s + len;
register PMOP *pm;
register REGEXP *rx;
register SV *dstr;
- register char *m;
+ register const char *m;
I32 iters = 0;
- STRLEN slen = do_utf8 ? utf8_length((U8*)s, (U8*)strend) : (strend - s);
+ const STRLEN slen = do_utf8 ? utf8_length((U8*)s, (U8*)strend) : (strend - s);
I32 maxiters = slen + 10;
- I32 i;
- char *orig;
- I32 origlimit = limit;
+ const char *orig;
+ const I32 origlimit = limit;
I32 realarray = 0;
I32 base;
- I32 gimme = GIMME_V;
- I32 oldsave = PL_savestack_ix;
+ const I32 gimme = GIMME_V;
+ const I32 oldsave = PL_savestack_ix;
I32 make_mortal = 1;
bool multiline = 0;
MAGIC *mg = (MAGIC *) NULL;
}
else {
if (!AvREAL(ary)) {
+ I32 i;
AvREAL_on(ary);
AvREIFY_off(ary);
for (i = AvFILLp(ary); i >= 0; i--)
}
else if (rx->precomp[0] == '^' && rx->precomp[1] == '\0') {
while (--limit) {
- /*SUPPRESS 530*/
- for (m = s; m < strend && *m != '\n'; m++) ;
+ for (m = s; m < strend && *m != '\n'; m++)
+ ;
m++;
if (m >= strend)
break;
(rx->reganch & RE_USE_INTUIT) && !rx->nparens
&& (rx->reganch & ROPT_CHECK_ALL)
&& !(rx->reganch & ROPT_ANCH)) {
- int tail = (rx->reganch & RE_INTUIT_TAIL);
- SV *csv = CALLREG_INTUIT_STRING(aTHX_ rx);
+ const int tail = (rx->reganch & RE_INTUIT_TAIL);
+ SV * const csv = CALLREG_INTUIT_STRING(aTHX_ rx);
len = rx->minlen;
if (len == 1 && !(rx->reganch & ROPT_UTF8) && !tail) {
- STRLEN n_a;
- char c = *SvPV(csv, n_a);
+ const char c = *SvPV_nolen_const(csv);
while (--limit) {
- /*SUPPRESS 530*/
- for (m = s; m < strend && *m != c; m++) ;
+ for (m = s; m < strend && *m != c; m++)
+ ;
if (m >= strend)
break;
dstr = newSVpvn(s, m-s);
}
}
else {
-#ifndef lint
while (s < strend && --limit &&
(m = fbm_instr((unsigned char*)s, (unsigned char*)strend,
csv, multiline ? FBMrf_MULTILINE : 0)) )
-#endif
{
dstr = newSVpvn(s, m-s);
if (make_mortal)
maxiters += slen * rx->nparens;
while (s < strend && --limit)
{
+ I32 rex_return;
PUTBACK;
- i = CALLREGEXEC(aTHX_ rx, s, strend, orig, 1 , sv, NULL, 0);
+ rex_return = CALLREGEXEC(aTHX_ rx, (char*)s, (char*)strend, (char*)orig, 1 ,
+ sv, NULL, 0);
SPAGAIN;
- if (i == 0)
+ if (rex_return == 0)
break;
TAINT_IF(RX_MATCH_TAINTED(rx));
if (RX_MATCH_COPIED(rx) && rx->subbeg != orig) {
(void)SvUTF8_on(dstr);
XPUSHs(dstr);
if (rx->nparens) {
+ I32 i;
for (i = 1; i <= (I32)rx->nparens; i++) {
s = rx->startp[i] + orig;
m = rx->endp[i] + orig;
/* keep field after final delim? */
if (s < strend || (iters && origlimit)) {
- STRLEN l = strend - s;
+ const STRLEN l = strend - s;
dstr = newSVpvn(s, l);
if (make_mortal)
sv_2mortal(dstr);
LEAVE;
SPAGAIN;
if (gimme == G_ARRAY) {
+ I32 i;
/* EXTEND should not be needed - we just popped them */
EXTEND(SP, iters);
for (i=0; i < iters; i++) {
RETURN;
}
-PP(pp_threadsv)
+
+PP(unimplemented_op)
{
- DIE(aTHX_ "tried to access per-thread data in non-threaded perl");
+ DIE(aTHX_ "panic: unimplemented op %s (#%d) called", OP_NAME(PL_op),
+ PL_op->op_type);
}
/*
* indent-tabs-mode: t
* End:
*
- * vim: shiftwidth=4:
-*/
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */