X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/f54cb97a39f1a5849851e77a33524dfca2644cf5..a19d7498e238ac7c03cb96036dee4a734a2a0356:/doop.c diff --git a/doop.c b/doop.c index 39e5d36..9e55103 100644 --- a/doop.c +++ b/doop.c @@ -60,7 +60,7 @@ S_do_trans_simple(pTHX_ SV *sv) /* Allow for expansion: $_="a".chr(400); tr/a/\xFE/, FE needs encoding */ if (grows) - New(0, d, len*2+1, U8); + Newx(d, len*2+1, U8); else d = s; dstart = d; @@ -97,8 +97,8 @@ S_do_trans_simple(pTHX_ SV *sv) STATIC I32 S_do_trans_count(pTHX_ SV *sv) { - U8 *s; - U8 *send; + const U8 *s; + const U8 *send; I32 matches = 0; STRLEN len; const I32 complement = PL_op->op_private & OPpTRANS_COMPLEMENT; @@ -107,7 +107,7 @@ S_do_trans_count(pTHX_ SV *sv) if (!tbl) Perl_croak(aTHX_ "panic: do_trans_count line %d",__LINE__); - s = (U8*)SvPV(sv, len); + s = (const U8*)SvPV_const(sv, len); send = s + len; if (!SvUTF8(sv)) @@ -190,7 +190,7 @@ S_do_trans_complex(pTHX_ SV *sv) } else { /* isutf8 */ if (grows) - New(0, d, len*2+1, U8); + Newx(d, len*2+1, U8); else d = s; dstart = d; @@ -306,8 +306,8 @@ S_do_trans_simple_utf8(pTHX_ SV *sv) const I32 grows = PL_op->op_private & OPpTRANS_GROWS; STRLEN len; - SV* rv = (SV*)cSVOP->op_sv; - HV* hv = (HV*)SvRV(rv); + SV* const rv = (SV*)cSVOP->op_sv; + HV* const hv = (HV*)SvRV(rv); SV** svp = hv_fetch(hv, "NONE", 4, FALSE); const UV none = svp ? SvUV(*svp) : 0x7fffffff; const UV extra = none + 1; @@ -337,7 +337,7 @@ S_do_trans_simple_utf8(pTHX_ SV *sv) if (grows) { /* d needs to be bigger than s, in case e.g. upgrading is required */ - New(0, d, len * 3 + UTF8_MAXBYTES, U8); + Newx(d, len * 3 + UTF8_MAXBYTES, U8); dend = d + len * 3; dstart = d; } @@ -395,19 +395,19 @@ S_do_trans_simple_utf8(pTHX_ SV *sv) STATIC I32 S_do_trans_count_utf8(pTHX_ SV *sv) { - U8 *s; - U8 *start = 0, *send; + const U8 *s; + const U8 *start = 0, *send; I32 matches = 0; STRLEN len; - SV* rv = (SV*)cSVOP->op_sv; - HV* hv = (HV*)SvRV(rv); - SV** svp = hv_fetch(hv, "NONE", 4, FALSE); + SV* const rv = (SV*)cSVOP->op_sv; + HV* const hv = (HV*)SvRV(rv); + SV** const svp = hv_fetch(hv, "NONE", 4, FALSE); const UV none = svp ? SvUV(*svp) : 0x7fffffff; const UV extra = none + 1; U8 hibit = 0; - s = (U8*)SvPV(sv, len); + s = (const U8*)SvPV_const(sv, len); if (!SvUTF8(sv)) { const U8 *t = s; const U8 *e = s + len; @@ -442,8 +442,8 @@ S_do_trans_complex_utf8(pTHX_ SV *sv) const I32 squash = PL_op->op_private & OPpTRANS_SQUASH; const I32 del = PL_op->op_private & OPpTRANS_DELETE; const I32 grows = PL_op->op_private & OPpTRANS_GROWS; - SV* rv = (SV*)cSVOP->op_sv; - HV* hv = (HV*)SvRV(rv); + SV * const rv = (SV*)cSVOP->op_sv; + HV * const hv = (HV*)SvRV(rv); SV** svp = hv_fetch(hv, "NONE", 4, FALSE); const UV none = svp ? SvUV(*svp) : 0x7fffffff; const UV extra = none + 1; @@ -456,7 +456,8 @@ S_do_trans_complex_utf8(pTHX_ SV *sv) U8 *s = (U8*)SvPV(sv, len); const I32 isutf8 = SvUTF8(sv); if (!isutf8) { - const U8 *t = s, *e = s + len; + const U8 *t = s; + const U8 * const e = s + len; while (t < e) { const U8 ch = *t++; if ((hibit = !NATIVE_IS_INVARIANT(ch))) @@ -476,7 +477,7 @@ S_do_trans_complex_utf8(pTHX_ SV *sv) if (grows) { /* d needs to be bigger than s, in case e.g. upgrading is required */ - New(0, d, len * 3 + UTF8_MAXBYTES, U8); + Newx(d, len * 3 + UTF8_MAXBYTES, U8); dend = d + len * 3; dstart = d; } @@ -605,7 +606,7 @@ Perl_do_trans(pTHX_ SV *sv) if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) Perl_croak(aTHX_ PL_no_modify); } - (void)SvPV(sv, len); + (void)SvPV_const(sv, len); if (!len) return 0; if (!(PL_op->op_private & OPpTRANS_IDENTICAL)) { @@ -643,22 +644,22 @@ Perl_do_trans(pTHX_ SV *sv) void Perl_do_join(pTHX_ register SV *sv, SV *del, register SV **mark, register SV **sp) { - SV **oldmark = mark; + SV ** const oldmark = mark; register I32 items = sp - mark; register STRLEN len; STRLEN delimlen; - (void) SvPV(del, delimlen); /* stringify and get the delimlen */ + (void) SvPV_const(del, delimlen); /* stringify and get the delimlen */ /* SvCUR assumes it's SvPOK() and woe betide you if it's not. */ mark++; len = (items > 0 ? (delimlen * (items - 1) ) : 0); - (void)SvUPGRADE(sv, SVt_PV); + SvUPGRADE(sv, SVt_PV); if (SvLEN(sv) < len + items) { /* current length is way too short */ while (items-- > 0) { if (*mark && !SvGAMAGIC(*mark) && SvOK(*mark)) { STRLEN tmplen; - SvPV(*mark, tmplen); + SvPV_const(*mark, tmplen); len += tmplen; } mark++; @@ -700,7 +701,7 @@ void Perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg) { STRLEN patlen; - const char *pat = SvPV(*sarg, patlen); + const char * const pat = SvPV_const(*sarg, patlen); bool do_taint = FALSE; SvUTF8_off(sv); @@ -717,7 +718,7 @@ UV Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size) { STRLEN srclen, len; - unsigned char *s = (unsigned char *) SvPV(sv, srclen); + const unsigned char *s = (const unsigned char *) SvPV_const(sv, srclen); UV retnum = 0; if (offset < 0) @@ -954,7 +955,6 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv) HV* hv = (HV*)sv; HE* entry; (void)hv_iterinit(hv); - /*SUPPRESS 560*/ while ((entry = hv_iternext(hv))) do_chop(astr,hv_iterval(hv,entry)); return; @@ -977,7 +977,7 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv) s = send - 1; while (s > start && UTF8_IS_CONTINUATION(*s)) s--; - if (utf8_to_uvchr((U8*)s, 0)) { + if (is_utf8_string((U8*)s, send - s)) { sv_setpvn(astr, s, send - s); *s = '\0'; SvCUR_set(sv, s - start); @@ -1006,7 +1006,6 @@ Perl_do_chomp(pTHX_ register SV *sv) { register I32 count; STRLEN len; - STRLEN n_a; char *s; char *temp_buffer = NULL; SV* svrecode = Nullsv; @@ -1018,7 +1017,7 @@ Perl_do_chomp(pTHX_ register SV *sv) count = 0; if (SvTYPE(sv) == SVt_PVAV) { register I32 i; - AV* av = (AV*)sv; + AV* const av = (AV*)sv; const I32 max = AvFILL(av); for (i = 0; i <= max; i++) { @@ -1029,10 +1028,9 @@ Perl_do_chomp(pTHX_ register SV *sv) return count; } else if (SvTYPE(sv) == SVt_PVHV) { - HV* hv = (HV*)sv; + HV* const hv = (HV*)sv; HE* entry; (void)hv_iterinit(hv); - /*SUPPRESS 560*/ while ((entry = hv_iternext(hv))) count += do_chomp(hv_iterval(hv,entry)); return count; @@ -1072,7 +1070,7 @@ Perl_do_chomp(pTHX_ register SV *sv) } else { STRLEN rslen, rs_charlen; - char *rsptr = SvPV(PL_rs, rslen); + const char *rsptr = SvPV_const(PL_rs, rslen); rs_charlen = SvUTF8(PL_rs) ? sv_len_utf8(PL_rs) @@ -1099,7 +1097,7 @@ Perl_do_chomp(pTHX_ register SV *sv) * Do not recode PL_rs as a side-effect. */ svrecode = newSVpvn(rsptr, rslen); sv_recode_to_utf8(svrecode, PL_encoding); - rsptr = SvPV(svrecode, rslen); + rsptr = SvPV_const(svrecode, rslen); rs_charlen = sv_len_utf8(svrecode); } else { @@ -1123,7 +1121,7 @@ Perl_do_chomp(pTHX_ register SV *sv) count += rs_charlen; } } - s = SvPV_force(sv, n_a); + s = SvPV_force_nolen(sv); SvCUR_set(sv, len); *SvEND(sv) = '\0'; SvNIOK_off(sv); @@ -1149,12 +1147,12 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right) register char *dc; STRLEN leftlen; STRLEN rightlen; - register char *lc; - register char *rc; + register const char *lc; + register const char *rc; register I32 len; I32 lensave; - char *lsave; - char *rsave; + const char *lsave; + const char *rsave; const bool left_utf = DO_UTF8(left); const bool right_utf = DO_UTF8(right); I32 needlen = 0; @@ -1166,17 +1164,16 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right) if (sv != left || (optype != OP_BIT_AND && !SvOK(sv) && !SvGMAGICAL(sv))) sv_setpvn(sv, "", 0); /* avoid undef warning on |= and ^= */ - lsave = lc = SvPV_nomg(left, leftlen); - rsave = rc = SvPV_nomg(right, rightlen); + lsave = lc = SvPV_nomg_const(left, leftlen); + rsave = rc = SvPV_nomg_const(right, rightlen); len = leftlen < rightlen ? leftlen : rightlen; lensave = len; if ((left_utf || right_utf) && (sv == left || sv == right)) { needlen = optype == OP_BIT_AND ? len : leftlen + rightlen; - Newz(801, dc, needlen + 1, char); + Newxz(dc, needlen + 1, char); } else if (SvOK(sv) || SvTYPE(sv) > SVt_PVMG) { - STRLEN n_a; - dc = SvPV_force_nomg(sv, n_a); + dc = SvPV_force_nomg_nolen(sv); if (SvCUR(sv) < (STRLEN)len) { dc = SvGROW(sv, (STRLEN)(len + 1)); (void)memzero(dc + SvCUR(sv), len - SvCUR(sv) + 1); @@ -1187,7 +1184,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right) else { needlen = ((optype == OP_BIT_AND) ? len : (leftlen > rightlen ? leftlen : rightlen)); - Newz(801, dc, needlen + 1, char); + Newxz(dc, needlen + 1, char); (void)sv_usepvn(sv, dc, needlen); dc = SvPVX(sv); /* sv_usepvn() calls Renew() */ } @@ -1380,7 +1377,6 @@ Perl_do_kv(pTHX) i = HvKEYS(keys); else { i = 0; - /*SUPPRESS 560*/ while (hv_iternext(keys)) i++; } PUSHi( i ); @@ -1393,7 +1389,7 @@ Perl_do_kv(pTHX) while ((entry = hv_iternext(keys))) { SPAGAIN; if (dokeys) { - SV* sv = hv_iterkeysv(entry); + SV* const sv = hv_iterkeysv(entry); XPUSHs(sv); /* won't clobber stack_sp */ } if (dovalues) { @@ -1402,7 +1398,7 @@ Perl_do_kv(pTHX) tmpstr = hv_iterval(hv,entry); DEBUG_H(Perl_sv_setpvf(aTHX_ tmpstr, "%lu%%%d=%lu", (unsigned long)HeHASH(entry), - HvMAX(keys)+1, + (int)HvMAX(keys)+1, (unsigned long)(HeHASH(entry) & HvMAX(keys)))); SPAGAIN; XPUSHs(tmpstr); @@ -1419,5 +1415,5 @@ Perl_do_kv(pTHX) * indent-tabs-mode: t * End: * - * vim: shiftwidth=4: -*/ + * ex: set ts=8 sts=4 sw=4 noet: + */