X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp.c;h=b260ff107c6124a3eee047b2feb889c501574099;hb=170c5524f26ec8d57d5b2a5413842df92809a613;hp=63bc8ed0911eda7129323640ef563c9f3ce2b04e;hpb=b59aed6733cbdee6d898449f638bd7a17e772993;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp.c b/pp.c index 63bc8ed..b260ff1 100644 --- a/pp.c +++ b/pp.c @@ -78,7 +78,7 @@ PP(pp_padav) 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; } } @@ -160,13 +160,13 @@ PP(pp_rv2gv) 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) @@ -238,9 +238,14 @@ PP(pp_rv2sv) 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); @@ -258,8 +263,6 @@ PP(pp_rv2sv) } } 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); } } @@ -364,7 +367,7 @@ PP(pp_prototype) 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. */ @@ -755,7 +758,7 @@ PP(pp_undef) 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; } @@ -1260,7 +1263,7 @@ PP(pp_modulo) 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 */ @@ -1352,7 +1355,7 @@ PP(pp_repeat) else count = uv; } else { - IV iv = SvIV(sv); + const IV iv = SvIV(sv); if (iv < 0) count = 0; else @@ -1370,12 +1373,10 @@ PP(pp_repeat) 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)) @@ -1421,7 +1422,7 @@ PP(pp_repeat) 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[] = @@ -1604,11 +1605,11 @@ PP(pp_right_shift) { 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; @@ -1933,8 +1934,8 @@ PP(pp_ne) 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 @@ -1992,8 +1993,8 @@ PP(pp_ncmp) 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; } @@ -2091,54 +2092,40 @@ PP(pp_ncmp) } } -PP(pp_slt) +PP(pp_sle) { - dSP; tryAMAGICbinSET(slt,0); - { - dPOPTOPssrl; - const int cmp = (IN_LOCALE_RUNTIME - ? sv_cmp_locale(left, right) - : sv_cmp(left, right)); - SETs(boolSV(cmp < 0)); - RETURN; - } -} + dSP; -PP(pp_sgt) -{ - dSP; tryAMAGICbinSET(sgt,0); - { - dPOPTOPssrl; - const int cmp = (IN_LOCALE_RUNTIME - ? sv_cmp_locale(left, right) - : sv_cmp(left, right)); - SETs(boolSV(cmp > 0)); - RETURN; - } -} + int amg_type = sle_amg; + int multiplier = 1; + int rhs = 1; -PP(pp_sle) -{ - dSP; tryAMAGICbinSET(sle,0); - { - dPOPTOPssrl; - const int cmp = (IN_LOCALE_RUNTIME - ? sv_cmp_locale(left, right) - : sv_cmp(left, right)); - SETs(boolSV(cmp <= 0)); - RETURN; + switch (PL_op->op_type) { + case OP_SLT: + amg_type = slt_amg; + /* cmp < 0 */ + rhs = 0; + break; + case OP_SGT: + amg_type = sgt_amg; + /* cmp > 0 */ + multiplier = -1; + rhs = 0; + break; + case OP_SGE: + amg_type = sge_amg; + /* cmp >= 0 */ + multiplier = -1; + break; } -} -PP(pp_sge) -{ - dSP; tryAMAGICbinSET(sge,0); + tryAMAGICbinSET_var(amg_type,0); { dPOPTOPssrl; const int cmp = (IN_LOCALE_RUNTIME ? sv_cmp_locale(left, right) : sv_cmp(left, right)); - SETs(boolSV(cmp >= 0)); + SETs(boolSV(cmp * multiplier < rhs)); RETURN; } } @@ -2694,11 +2681,7 @@ PP(pp_rand) 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); @@ -2897,7 +2880,7 @@ PP(pp_oct) PP(pp_length) { dSP; dTARGET; - SV *sv = TOPs; + SV * const sv = TOPs; if (DO_UTF8(sv)) SETi(sv_len_utf8(sv)); @@ -3242,8 +3225,6 @@ PP(pp_sprintf) dSP; dMARK; dORIGMARK; dTARGET; do_sprintf(TARG, SP-MARK, MARK+1); TAINT_IF(SvTAINTED(TARG)); - if (DO_UTF8(*(MARK+1))) - SvUTF8_on(TARG); SP = ORIGMARK; PUSHTARG; RETURN; @@ -3381,6 +3362,7 @@ PP(pp_ucfirst) SV *sv = TOPs; const U8 *s; STRLEN slen; + const int op_type = PL_op->op_type; SvGETMAGIC(sv); if (DO_UTF8(sv) && @@ -3391,18 +3373,21 @@ PP(pp_ucfirst) STRLEN tculen; utf8_to_uvchr(s, &ulen); - toTITLE_utf8(s, tmpbuf, &tculen); - utf8_to_uvchr(tmpbuf, 0); + if (op_type == OP_UCFIRST) { + toTITLE_utf8(s, tmpbuf, &tculen); + } else { + toLOWER_utf8(s, tmpbuf, &tculen); + } - if (!SvPADTMP(sv) || SvREADONLY(sv)) { + if (!SvPADTMP(sv) || SvREADONLY(sv) || ulen != tculen) { dTARGET; /* slen is the byte length of the whole SV. * ulen is the byte length of the original Unicode character * stored as UTF-8 at s. - * tculen is the byte length of the freshly titlecased - * Unicode character stored as UTF-8 at tmpbuf. - * We first set the result to be the titlecased character, - * and then append the rest of the SV data. */ + * tculen is the byte length of the freshly titlecased (or + * lowercased) Unicode character stored as UTF-8 at tmpbuf. + * We first set the result to be the titlecased (/lowercased) + * character, and then append the rest of the SV data. */ sv_setpvn(TARG, (char*)tmpbuf, tculen); if (slen > ulen) sv_catpvn(TARG, (char*)(s + ulen), slen - ulen); @@ -3428,67 +3413,11 @@ PP(pp_ucfirst) if (IN_LOCALE_RUNTIME) { TAINT; SvTAINTED_on(sv); - *s1 = toUPPER_LC(*s1); - } - else - *s1 = toUPPER(*s1); - } - } - SvSETMAGIC(sv); - RETURN; -} - -PP(pp_lcfirst) -{ - dSP; - SV *sv = TOPs; - const U8 *s; - STRLEN slen; - - SvGETMAGIC(sv); - if (DO_UTF8(sv) && - (s = (const U8*)SvPV_nomg_const(sv, slen)) && slen && - UTF8_IS_START(*s)) { - STRLEN ulen; - U8 tmpbuf[UTF8_MAXBYTES_CASE+1]; - U8 *tend; - UV uv; - - toLOWER_utf8(s, tmpbuf, &ulen); - uv = utf8_to_uvchr(tmpbuf, 0); - tend = uvchr_to_utf8(tmpbuf, uv); - - if (!SvPADTMP(sv) || (STRLEN)(tend - tmpbuf) != ulen || SvREADONLY(sv)) { - dTARGET; - sv_setpvn(TARG, (char*)tmpbuf, tend - tmpbuf); - if (slen > ulen) - sv_catpvn(TARG, (char*)(s + ulen), slen - ulen); - SvUTF8_on(TARG); - SETs(TARG); - } - else { - s = (U8*)SvPV_force_nomg(sv, slen); - Copy(tmpbuf, s, ulen, U8); - } - } - else { - U8 *s1; - if (!SvPADTMP(sv) || SvREADONLY(sv)) { - dTARGET; - SvUTF8_off(TARG); /* decontaminate */ - sv_setsv_nomg(TARG, sv); - sv = TARG; - SETs(sv); - } - s1 = (U8*)SvPV_force_nomg(sv, slen); - if (*s1) { - if (IN_LOCALE_RUNTIME) { - TAINT; - SvTAINTED_on(sv); - *s1 = toLOWER_LC(*s1); + *s1 = (op_type == OP_UCFIRST) + ? toUPPER_LC(*s1) : toLOWER_LC(*s1); } else - *s1 = toLOWER(*s1); + *s1 = (op_type == OP_UCFIRST) ? toUPPER(*s1) : toLOWER(*s1); } } SvSETMAGIC(sv); @@ -3531,7 +3460,7 @@ PP(pp_uc) 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 @@ -3634,7 +3563,7 @@ PP(pp_lc) 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 @@ -3879,7 +3808,7 @@ PP(pp_exists) if (PL_op->op_private & OPpEXISTS_SUB) { GV *gv; - SV *sv = POPs; + SV * const sv = POPs; CV * const cv = sv_2cv(sv, &hv, &gv, FALSE); if (cv) RETPUSHYES; @@ -4475,7 +4404,7 @@ PP(pp_split) 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;