From: Andy Lester Date: Sun, 30 Oct 2005 23:44:13 +0000 (-0600) Subject: Etta James presents: More consting X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c4420975666e665b3282e2edeea3304e6626be36;p=p5sagit%2Fp5-mst-13.2.git Etta James presents: More consting Message-ID: <20051031054413.GA10767@petdance.com> p4raw-id: //depot/perl@25915 --- diff --git a/cop.h b/cop.h index f1a51fd..6672a53 100644 --- a/cop.h +++ b/cop.h @@ -679,7 +679,7 @@ typedef struct stackinfo PERL_SI; #define POPSTACK \ STMT_START { \ dSP; \ - PERL_SI *prev = PL_curstackinfo->si_prev; \ + PERL_SI * const prev = PL_curstackinfo->si_prev; \ if (!prev) { \ PerlIO_printf(Perl_error_log, "panic: POPSTACK\n"); \ my_exit(1); \ diff --git a/doop.c b/doop.c index 9e55103..ec8fab2 100644 --- a/doop.c +++ b/doop.c @@ -36,7 +36,7 @@ S_do_trans_simple(pTHX_ SV *sv) const I32 grows = PL_op->op_private & OPpTRANS_GROWS; STRLEN len; - const short *tbl = (short*)cPVOP->op_pv; + const short * const tbl = (short*)cPVOP->op_pv; if (!tbl) Perl_croak(aTHX_ "panic: do_trans_simple line %d",__LINE__); @@ -49,10 +49,9 @@ S_do_trans_simple(pTHX_ SV *sv) const I32 ch = tbl[*s]; if (ch >= 0) { matches++; - *s++ = (U8)ch; + *s = (U8)ch; } - else - s++; + s++; } SvSETMAGIC(sv); return matches; @@ -308,7 +307,7 @@ S_do_trans_simple_utf8(pTHX_ SV *sv) SV* const rv = (SV*)cSVOP->op_sv; HV* const hv = (HV*)SvRV(rv); - SV** svp = hv_fetch(hv, "NONE", 4, FALSE); + SV* const * svp = hv_fetch(hv, "NONE", 4, FALSE); const UV none = svp ? SvUV(*svp) : 0x7fffffff; const UV extra = none + 1; UV final = 0; @@ -319,7 +318,8 @@ S_do_trans_simple_utf8(pTHX_ SV *sv) s = (U8*)SvPV(sv, len); 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))) @@ -402,7 +402,7 @@ S_do_trans_count_utf8(pTHX_ SV *sv) SV* const rv = (SV*)cSVOP->op_sv; HV* const hv = (HV*)SvRV(rv); - SV** const svp = hv_fetch(hv, "NONE", 4, FALSE); + SV* const * const svp = hv_fetch(hv, "NONE", 4, FALSE); const UV none = svp ? SvUV(*svp) : 0x7fffffff; const UV extra = none + 1; U8 hibit = 0; @@ -410,7 +410,7 @@ S_do_trans_count_utf8(pTHX_ SV *sv) s = (const U8*)SvPV_const(sv, len); if (!SvUTF8(sv)) { const U8 *t = s; - const U8 *e = s + len; + const U8 * const e = s + len; while (t < e) { const U8 ch = *t++; if ((hibit = !NATIVE_IS_INVARIANT(ch))) @@ -422,8 +422,8 @@ S_do_trans_count_utf8(pTHX_ SV *sv) send = s + len; while (s < send) { - UV uv; - if ((uv = swash_fetch(rv, s, TRUE)) < none || uv == extra) + const UV uv = swash_fetch(rv, s, TRUE); + if (uv < none || uv == extra) matches++; s += UTF8SKIP(s); } @@ -444,7 +444,7 @@ S_do_trans_complex_utf8(pTHX_ SV *sv) const I32 grows = PL_op->op_private & OPpTRANS_GROWS; SV * const rv = (SV*)cSVOP->op_sv; HV * const hv = (HV*)SvRV(rv); - SV** svp = hv_fetch(hv, "NONE", 4, FALSE); + SV * const *svp = hv_fetch(hv, "NONE", 4, FALSE); const UV none = svp ? SvUV(*svp) : 0x7fffffff; const UV extra = none + 1; UV final = 0; @@ -855,7 +855,6 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size) void Perl_do_vecset(pTHX_ SV *sv) { - SV *targ = LvTARG(sv); register I32 offset; register I32 size; register unsigned char *s; @@ -863,6 +862,7 @@ Perl_do_vecset(pTHX_ SV *sv) I32 mask; STRLEN targlen; STRLEN len; + SV * const targ = LvTARG(sv); if (!targ) return; @@ -941,7 +941,7 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv) 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++) { @@ -952,7 +952,7 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv) return; } else if (SvTYPE(sv) == SVt_PVHV) { - HV* hv = (HV*)sv; + HV* const hv = (HV*)sv; HE* entry; (void)hv_iterinit(hv); while ((entry = hv_iternext(hv))) @@ -972,7 +972,7 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv) s = SvPV_force(sv, len); if (DO_UTF8(sv)) { if (s && len) { - char *send = s + len; + char * const send = s + len; char *start = s; s = send - 1; while (s > start && UTF8_IS_CONTINUATION(*s)) @@ -1192,7 +1192,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right) (void)SvPOK_only(sv); if (left_utf || right_utf) { UV duc, luc, ruc; - char *dcsave = dc; + char * const dcsave = dc; STRLEN lulen = leftlen; STRLEN rulen = rightlen; STRLEN ulen; @@ -1330,7 +1330,7 @@ OP * Perl_do_kv(pTHX) { dSP; - HV *hv = (HV*)POPs; + HV * const hv = (HV*)POPs; HV *keys; register HE *entry; const I32 gimme = GIMME_V; diff --git a/hv.c b/hv.c index 838dbbc..a780b19 100644 --- a/hv.c +++ b/hv.c @@ -1942,7 +1942,7 @@ Perl_hv_iternext_flags(pTHX_ HV *hv, I32 flags) oldentry = entry = iter->xhv_eiter; /* HvEITER(hv) */ if ((mg = SvTIED_mg((SV*)hv, PERL_MAGIC_tied))) { - SV *key = sv_newmortal(); + SV * const key = sv_newmortal(); if (entry) { sv_setsv(key, HeSVKEY_force(entry)); SvREFCNT_dec(HeSVKEY(entry)); /* get rid of previous key */ @@ -2092,7 +2092,7 @@ Perl_hv_iterval(pTHX_ HV *hv, register HE *entry) { if (SvRMAGICAL(hv)) { if (mg_find((SV*)hv, PERL_MAGIC_tied)) { - SV* sv = sv_newmortal(); + SV* const sv = sv_newmortal(); if (HeKLEN(entry) == HEf_SVKEY) mg_copy((SV*)hv, sv, (char*)HeKEY_sv(entry), HEf_SVKEY); else diff --git a/numeric.c b/numeric.c index 77e10e3..a745a70 100644 --- a/numeric.c +++ b/numeric.c @@ -500,7 +500,7 @@ Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send) #ifdef USE_LOCALE_NUMERIC if (PL_numeric_radix_sv && IN_LOCALE) { STRLEN len; - const char* radix = SvPV(PL_numeric_radix_sv, len); + const char * const radix = SvPV(PL_numeric_radix_sv, len); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; @@ -543,7 +543,7 @@ int Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep) { const char *s = pv; - const char *send = pv + len; + const char * const send = pv + len; const UV max_div_10 = UV_MAX / 10; const char max_mod_10 = UV_MAX % 10; int numtype = 0; @@ -765,7 +765,7 @@ S_mulexp10(NV value, I32 exponent) #if ((defined(VMS) && !defined(__IEEE_FP)) || defined(_UNICOS)) && defined(NV_MAX_10_EXP) STMT_START { - NV exp_v = log10(value); + const NV exp_v = log10(value); if (exponent >= NV_MAX_10_EXP || exponent + exp_v >= NV_MAX_10_EXP) return NV_MAX; if (exponent < 0) { diff --git a/op.c b/op.c index 58c3153..d1f73ea 100644 --- a/op.c +++ b/op.c @@ -4507,8 +4507,8 @@ Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) const char *tname = (name ? name : aname); if (PERLDB_SUBLINE && PL_curstash != PL_debstash) { - SV *sv = NEWSV(0,0); - SV *tmpstr = sv_newmortal(); + SV * const sv = NEWSV(0,0); + SV * const tmpstr = sv_newmortal(); GV *db_postponed = gv_fetchpv("DB::postponed", GV_ADDMULTI, SVt_PVHV); HV *hv; diff --git a/perl.c b/perl.c index ec8fd4e..e367695 100644 --- a/perl.c +++ b/perl.c @@ -810,10 +810,10 @@ perl_destruct(pTHXx) */ { I32 i = AvFILLp(PL_regex_padav) + 1; - SV **ary = AvARRAY(PL_regex_padav); + SV * const * const ary = AvARRAY(PL_regex_padav); while (i) { - SV *resv = ary[--i]; + SV * const resv = ary[--i]; if (SvFLAGS(resv) & SVf_BREAK) { /* this is PL_reg_curpm, already freed @@ -1089,7 +1089,7 @@ perl_destruct(pTHXx) */ I32 riter = 0; const I32 max = HvMAX(PL_strtab); - HE ** const array = HvARRAY(PL_strtab); + HE * const * const array = HvARRAY(PL_strtab); HE *hent = array[0]; for (;;) { @@ -1826,7 +1826,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) */ const char *space; - char *pv = SvPV_nolen(opts_prog); + char * const pv = SvPV_nolen(opts_prog); const char c = pv[opts+76]; pv[opts+76] = '\0'; space = strrchr(pv+opts+26, ' '); @@ -2337,7 +2337,7 @@ set and the variable does not exist then NULL is returned. AV* Perl_get_av(pTHX_ const char *name, I32 create) { - GV* gv = gv_fetchpv(name, create, SVt_PVAV); + GV* const gv = gv_fetchpv(name, create, SVt_PVAV); if (create) return GvAVn(gv); if (gv) @@ -2384,7 +2384,7 @@ subroutine does not exist then NULL is returned. CV* Perl_get_cv(pTHX_ const char *name, I32 create) { - GV* gv = gv_fetchpv(name, create, SVt_PVCV); + GV* const gv = gv_fetchpv(name, create, SVt_PVCV); /* XXX unsafe for threads if eval_owner isn't held */ /* XXX this is probably not what they think they're getting. * It has the same effect as "sub name;", i.e. just a forward @@ -2486,7 +2486,7 @@ Perl_call_sv(pTHX_ SV *sv, I32 flags) I32 oldscope; bool oldcatch = CATCH_GET; int ret; - OP* oldop = PL_op; + OP* const oldop = PL_op; dJMPENV; if (flags & G_DISCARD) { @@ -2653,7 +2653,7 @@ Perl_eval_sv(pTHX_ SV *sv, I32 flags) volatile I32 oldmark = SP - PL_stack_base; volatile I32 retval = 0; int ret; - OP* oldop = PL_op; + OP* const oldop = PL_op; dJMPENV; if (flags & G_DISCARD) { @@ -2786,9 +2786,9 @@ Perl_require_pv(pTHX_ const char *pv) void Perl_magicname(pTHX_ const char *sym, const char *name, I32 namlen) { - register GV *gv; + register GV * const gv = gv_fetchpv(sym,TRUE, SVt_PV); - if ((gv = gv_fetchpv(sym,TRUE, SVt_PV))) + if (gv) sv_magic(GvSV(gv), (SV*)gv, PERL_MAGIC_sv, name, namlen); } @@ -2880,7 +2880,7 @@ Perl_get_debug_opts(pTHX_ const char **s, bool givehelp) static const char debopts[] = "psltocPmfrxu HXDSTRJvCAq"; for (; isALNUM(**s); (*s)++) { - const char *d = strchr(debopts,**s); + const char * const d = strchr(debopts,**s); if (d) i |= 1 << (d - debopts); else if (ckWARN_d(WARN_DEBUGGING)) @@ -2989,8 +2989,7 @@ Perl_moreswitches(pTHX_ char *s) in the fashion that -MSome::Mod does. */ if (*s == ':' || *s == '=') { const char *start; - SV *sv; - sv = newSVpv("use Devel::", 0); + SV * const sv = newSVpv("use Devel::", 0); start = ++s; /* We now allow -d:Module=Foo,Bar */ while(isALNUM(*s) || *s==':') ++s; @@ -3540,9 +3539,9 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, SV *sv) } #else /* IAMSUID */ else if (PL_preprocess) { - const char *cpp_cfg = CPPSTDIN; - SV *cpp = newSVpvn("",0); - SV *cmd = NEWSV(0,0); + const char * const cpp_cfg = CPPSTDIN; + SV * const cpp = newSVpvn("",0); + SV * const cmd = NEWSV(0,0); if (cpp_cfg[0] == 0) /* PERL_MICRO? */ Perl_croak(aTHX_ "Can't run with cpp -P with CPPSTDIN undefined"); @@ -4337,7 +4336,7 @@ S_forbid_setid(pTHX_ const char *s) void Perl_init_debugger(pTHX) { - HV *ostash = PL_curstash; + HV * const ostash = PL_curstash; PL_curstash = PL_debstash; PL_dbargs = GvAV(gv_AVadd((gv_fetchpv("DB::args", GV_ADDMULTI, SVt_PVAV)))); @@ -4908,8 +4907,8 @@ S_incpush(pTHX_ const char *dir, bool addsubdirs, bool addoldvers, bool usesep, if (addsubdirs || addoldvers) { #ifdef PERL_INC_VERSION_LIST /* Configure terminates PERL_INC_VERSION_LIST with a NULL */ - const char *incverlist[] = { PERL_INC_VERSION_LIST }; - const char **incver; + const char * const incverlist[] = { PERL_INC_VERSION_LIST }; + const char * const *incver; #endif #ifdef VMS char *unix; diff --git a/perlio.c b/perlio.c index 2505614..e9ea0c3 100644 --- a/perlio.c +++ b/perlio.c @@ -469,18 +469,18 @@ PerlIO_debug(const char *fmt, ...) } if (PL_perlio_debug_fd > 0) { dTHX; - const char *s = CopFILE(PL_curcop); STRLEN len; + const char *s = CopFILE(PL_curcop); #ifdef USE_ITHREADS /* Use fixed buffer as sv_catpvf etc. needs SVs */ char buffer[1024]; if (!s) s = "(none)"; - len = sprintf(buffer, "%.40s:%" IVdf " ", s, (IV) CopLINE(PL_curcop)); + len = my_sprintf(buffer, "%.40s:%" IVdf " ", s, (IV) CopLINE(PL_curcop)); vsprintf(buffer+len, fmt, ap); PerlLIO_write(PL_perlio_debug_fd, buffer, strlen(buffer)); #else - SV *sv = newSVpvn("", 0); + SV * const sv = newSVpvn("", 0); if (!s) s = "(none)"; Perl_sv_catpvf(aTHX_ sv, "%s:%" IVdf " ", s, @@ -2646,9 +2646,10 @@ typedef struct { IV PerlIOStdio_fileno(pTHX_ PerlIO *f) { - FILE *s; - if (PerlIOValid(f) && (s = PerlIOSelf(f, PerlIOStdio)->stdio)) { - return PerlSIO_fileno(s); + if (PerlIOValid(f)) { + FILE * const s = PerlIOSelf(f, PerlIOStdio)->stdio; + if (s) + return PerlSIO_fileno(s); } errno = EBADF; return -1; @@ -2967,7 +2968,7 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE *f) IV PerlIOStdio_close(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; if (!stdio) { errno = EBADF; return -1; @@ -3040,7 +3041,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f) SSize_t PerlIOStdio_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) { - FILE *s = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const s = PerlIOSelf(f, PerlIOStdio)->stdio; SSize_t got = 0; for (;;) { if (count == 1) { @@ -3071,7 +3072,7 @@ SSize_t PerlIOStdio_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count) { SSize_t unread = 0; - FILE *s = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const s = PerlIOSelf(f, PerlIOStdio)->stdio; #ifdef STDIO_BUFFER_WRITABLE if (PerlIO_fast_gets(f) && PerlIO_has_base(f)) { @@ -3143,21 +3144,21 @@ PerlIOStdio_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count) IV PerlIOStdio_seek(pTHX_ PerlIO *f, Off_t offset, int whence) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; return PerlSIO_fseek(stdio, offset, whence); } Off_t PerlIOStdio_tell(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; return PerlSIO_ftell(stdio); } IV PerlIOStdio_flush(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE) { return PerlSIO_fflush(stdio); } @@ -3212,14 +3213,14 @@ PerlIOStdio_setlinebuf(pTHX_ PerlIO *f) STDCHAR * PerlIOStdio_get_base(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; return (STDCHAR*)PerlSIO_get_base(stdio); } Size_t PerlIOStdio_get_bufsiz(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; return PerlSIO_get_bufsiz(stdio); } #endif @@ -3228,21 +3229,21 @@ PerlIOStdio_get_bufsiz(pTHX_ PerlIO *f) STDCHAR * PerlIOStdio_get_ptr(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; return (STDCHAR*)PerlSIO_get_ptr(stdio); } SSize_t PerlIOStdio_get_cnt(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; return PerlSIO_get_cnt(stdio); } void PerlIOStdio_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; if (ptr != NULL) { #ifdef STDIO_PTR_LVALUE PerlSIO_set_ptr(stdio, (void*)ptr); /* LHS STDCHAR* cast non-portable */ @@ -3283,7 +3284,7 @@ PerlIOStdio_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt) IV PerlIOStdio_fill(pTHX_ PerlIO *f) { - FILE *stdio = PerlIOSelf(f, PerlIOStdio)->stdio; + FILE * const stdio = PerlIOSelf(f, PerlIOStdio)->stdio; int c; /* * fflush()ing read-only streams can cause trouble on some stdio-s @@ -4929,13 +4930,13 @@ PerlIO_tmpfile(void) SvREFCNT_dec(sv); } # else /* !HAS_MKSTEMP, fallback to stdio tmpfile(). */ - FILE *stdio = PerlSIO_tmpfile(); + FILE * const stdio = PerlSIO_tmpfile(); if (stdio) { if ((f = PerlIO_push(aTHX_(PerlIO_allocate(aTHX)), PERLIO_FUNCS_CAST(&PerlIO_stdio), "w+", Nullsv))) { - PerlIOStdio *s = PerlIOSelf(f, PerlIOStdio); + PerlIOStdio * const s = PerlIOSelf(f, PerlIOStdio); if (s) s->stdio = stdio; @@ -4966,7 +4967,7 @@ PerlIO_setpos(PerlIO *f, SV *pos) dTHX; if (SvOK(pos)) { STRLEN len; - Off_t *posn = (Off_t *) SvPV(pos, len); + const Off_t * const posn = (Off_t *) SvPV(pos, len); if (f && len == sizeof(Off_t)) return PerlIO_seek(f, *posn, SEEK_SET); } @@ -4981,7 +4982,7 @@ PerlIO_setpos(PerlIO *f, SV *pos) dTHX; if (SvOK(pos)) { STRLEN len; - Fpos_t *fpos = (Fpos_t *) SvPV(pos, len); + Fpos_t * const fpos = (Fpos_t *) SvPV(pos, len); if (f && len == sizeof(Fpos_t)) { #if defined(USE_64_BIT_STDIO) && defined(USE_FSETPOS64) return fsetpos64(f, fpos); diff --git a/pp_hot.c b/pp_hot.c index eed2ef9..4a30a13 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -553,7 +553,7 @@ PP(pp_pushre) * We ass_u_me that LvTARGOFF() comes first, and that two STRLENs * will be enough to hold an OP*. */ - SV* sv = sv_newmortal(); + SV* const sv = sv_newmortal(); sv_upgrade(sv, SVt_PVLV); LvTYPE(sv) = '/'; Copy(&PL_op, &LvTARGOFF(sv), 1, OP*); @@ -1159,9 +1159,9 @@ PP(pp_aassign) PP(pp_qr) { dSP; - register PMOP *pm = cPMOP; - SV *rv = sv_newmortal(); - SV *sv = newSVrv(rv, "Regexp"); + register PMOP * const pm = cPMOP; + SV * const rv = sv_newmortal(); + SV * const sv = newSVrv(rv, "Regexp"); if (pm->op_pmdynflags & PMdf_TAINTED) SvTAINTED_on(rv); sv_magic(sv,(SV*)ReREFCNT_inc(PM_GETRE(pm)), PERL_MAGIC_qr,0,0); @@ -2282,7 +2282,7 @@ PP(pp_grepwhile) /* All done yet? */ if (PL_stack_base + *PL_markstack_ptr > SP) { I32 items; - I32 gimme = GIMME_V; + const I32 gimme = GIMME_V; LEAVE; /* exit outer scope */ (void)POPMARK; /* pop src */ @@ -2291,7 +2291,7 @@ PP(pp_grepwhile) SP = PL_stack_base + POPMARK; /* pop original mark */ if (gimme == G_SCALAR) { if (PL_op->op_private & OPpGREP_LEX) { - SV* sv = sv_newmortal(); + SV* const sv = sv_newmortal(); sv_setiv(sv, items); PUSHs(sv); } diff --git a/pp_sys.c b/pp_sys.c index 19a735a..3c5a750 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -250,10 +250,10 @@ void endservent(void); STATIC int S_emulate_eaccess(pTHX_ const char* path, Mode_t mode) { - Uid_t ruid = getuid(); - Uid_t euid = geteuid(); - Gid_t rgid = getgid(); - Gid_t egid = getegid(); + const Uid_t ruid = getuid(); + const Uid_t euid = geteuid(); + const Gid_t rgid = getgid(); + const Gid_t egid = getegid(); int res; LOCK_CRED_MUTEX; @@ -536,31 +536,33 @@ PP(pp_open) dVAR; dSP; dMARK; dORIGMARK; dTARGET; - GV *gv; SV *sv; IO *io; const char *tmps; STRLEN len; - MAGIC *mg; bool ok; - gv = (GV *)*++MARK; + GV * const gv = (GV *)*++MARK; + if (!isGV(gv)) DIE(aTHX_ PL_no_usym, "filehandle"); if ((io = GvIOp(gv))) IoFLAGS(GvIOp(gv)) &= ~IOf_UNTAINT; - if (io && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) { - /* Method's args are same as ours ... */ - /* ... except handle is replaced by the object */ - *MARK-- = SvTIED_obj((SV*)io, mg); - PUSHMARK(MARK); - PUTBACK; - ENTER; - call_method("OPEN", G_SCALAR); - LEAVE; - SPAGAIN; - RETURN; + if (io) { + MAGIC * const mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar); + if (mg) { + /* Method's args are same as ours ... */ + /* ... except handle is replaced by the object */ + *MARK-- = SvTIED_obj((SV*)io, mg); + PUSHMARK(MARK); + PUTBACK; + ENTER; + call_method("OPEN", G_SCALAR); + LEAVE; + SPAGAIN; + RETURN; + } } if (MARK < SP) { @@ -585,14 +587,9 @@ PP(pp_open) PP(pp_close) { dVAR; dSP; - GV *gv; IO *io; MAGIC *mg; - - if (MAXARG == 0) - gv = PL_defoutgv; - else - gv = (GV*)POPs; + GV * const gv = (MAXARG == 0) ? PL_defoutgv : (GV*)POPs; if (gv && (io = GvIO(gv)) && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) @@ -615,14 +612,12 @@ PP(pp_pipe_op) { #ifdef HAS_PIPE dSP; - GV *rgv; - GV *wgv; register IO *rstio; register IO *wstio; int fd[2]; - wgv = (GV*)POPs; - rgv = (GV*)POPs; + GV * const wgv = (GV*)POPs; + GV * const rgv = (GV*)POPs; if (!rgv || !wgv) goto badexit; @@ -794,7 +789,6 @@ PP(pp_binmode) PP(pp_tie) { dVAR; dSP; dMARK; - SV *varsv; HV* stash; GV *gv; SV *sv; @@ -802,8 +796,8 @@ PP(pp_tie) const char *methname; int how = PERL_MAGIC_tied; U32 items; + SV *varsv = *++MARK; - varsv = *++MARK; switch(SvTYPE(varsv)) { case SVt_PVHV: methname = "TIEHASH"; @@ -893,11 +887,10 @@ PP(pp_untie) if ((mg = SvTIED_mg(sv, how))) { SV * const obj = SvRV(SvTIED_obj(sv, mg)); - GV *gv; CV *cv = NULL; if (obj) { - if ((gv = gv_fetchmethod_autoload(SvSTASH(obj), "UNTIE", FALSE)) && - isGV(gv) && (cv = GvCV(gv))) { + GV * const gv = gv_fetchmethod_autoload(SvSTASH(obj), "UNTIE", FALSE); + if (gv && isGV(gv) && (cv = GvCV(gv))) { PUSHMARK(SP); XPUSHs(SvTIED_obj((SV*)gv, mg)); XPUSHs(sv_2mortal(newSViv(SvREFCNT(obj)-1))); @@ -911,7 +904,7 @@ PP(pp_untie) Perl_warner(aTHX_ packWARN(WARN_UNTIE), "untie attempted while %"UVuf" inner references still exist", (UV)SvREFCNT(obj) - 1 ) ; - } + } } } sv_unmagic(sv, how) ; @@ -945,11 +938,10 @@ PP(pp_dbmopen) dPOPPOPssrl; HV* stash; GV *gv; - SV *sv; HV * const hv = (HV*)POPs; + SV * const sv = sv_mortalcopy(&PL_sv_no); - sv = sv_mortalcopy(&PL_sv_no); sv_setpv(sv, "AnyDBM_File"); stash = gv_stashsv(sv, FALSE); if (!stash || !(gv = gv_fetchmethod(stash, "TIEHASH"))) { @@ -1030,7 +1022,7 @@ PP(pp_sselect) SP -= 4; for (i = 1; i <= 3; i++) { - SV *sv = SP[i]; + SV * const sv = SP[i]; if (!SvOK(sv)) continue; if (SvREADONLY(sv)) { @@ -1190,7 +1182,7 @@ PP(pp_select) if (! hv) XPUSHs(&PL_sv_undef); else { - GV ** const gvp = (GV**)hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE); + GV * const * const gvp = (GV**)hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE); if (gvp && *gvp == egv) { gv_efullname4(TARG, PL_defoutgv, Nullch, TRUE); XPUSHTARG; @@ -1455,16 +1447,12 @@ PP(pp_leavewrite) PP(pp_prtf) { dVAR; dSP; dMARK; dORIGMARK; - GV *gv; IO *io; PerlIO *fp; SV *sv; MAGIC *mg; - if (PL_op->op_flags & OPf_STACKED) - gv = (GV*)*++MARK; - else - gv = PL_defoutgv; + GV * const gv = (PL_op->op_flags & OPf_STACKED) ? (GV*)*++MARK : PL_defoutgv; if (gv && (io = GvIO(gv)) && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) @@ -2010,10 +1998,9 @@ PP(pp_tell) IO *io; MAGIC *mg; - if (MAXARG == 0) - gv = PL_last_in_gv; - else - gv = PL_last_in_gv = (GV*)POPs; + if (MAXARG != 0) + PL_last_in_gv = (GV*)POPs; + gv = PL_last_in_gv; if (gv && (io = GvIO(gv)) && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) diff --git a/sv.c b/sv.c index 0589dac..f29434f 100644 --- a/sv.c +++ b/sv.c @@ -3138,7 +3138,7 @@ Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags) } tsv = NEWSV(0,0); if (SvOBJECT(sv)) { - const char *name = HvNAME_get(SvSTASH(sv)); + const char * const name = HvNAME_get(SvSTASH(sv)); Perl_sv_setpvf(aTHX_ tsv, "%s=%s(0x%"UVxf")", name ? name : "__ANON__" , typestr, PTR2UV(sv)); } @@ -3444,7 +3444,7 @@ Perl_sv_utf8_upgrade_flags(pTHX_ register SV *sv, I32 flags) * chars in the PV. Given that there isn't such a flag * make the loop as fast as possible. */ const U8 *s = (U8 *) SvPVX_const(sv); - const U8 *e = (U8 *) SvEND(sv); + const U8 * const e = (U8 *) SvEND(sv); const U8 *t = s; int hibit = 0; @@ -9345,7 +9345,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV && (PL_op->op_type == OP_PRTF || PL_op->op_type == OP_SPRINTF) && ckWARN(WARN_PRINTF)) { - SV *msg = sv_newmortal(); + SV * const msg = sv_newmortal(); Perl_sv_setpvf(aTHX_ msg, "Invalid conversion in %sprintf: ", (PL_op->op_type == OP_PRTF) ? "" : "s"); if (c) { diff --git a/toke.c b/toke.c index 11d5b2f..0ec4e9f 100644 --- a/toke.c +++ b/toke.c @@ -344,7 +344,7 @@ S_tokereport(pTHX_ I32 rv) STATIC void S_printbuf(pTHX_ const char* fmt, const char* s) { - SV* tmp = newSVpvn("", 0); + SV* const tmp = newSVpvn("", 0); PerlIO_printf(Perl_debug_log, fmt, pv_display(tmp, s, strlen(s), 0, 60)); SvREFCNT_dec(tmp); } @@ -680,7 +680,7 @@ S_incline(pTHX_ char *s) *t = '\0'; if (t - s > 0) { #ifndef USE_ITHREADS - const char *cf = CopFILE(PL_curcop); + const char * const cf = CopFILE(PL_curcop); if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) { /* must copy *{"::_<(eval N)[oldfilename:L]"} * to *{"::_ 2) Perl_croak(aTHX_ "Usage: utf8::downgrade(sv, failok=0)"); - { - SV * sv = ST(0); + else { + SV * const sv = ST(0); const bool failok = (items < 2) ? 0 : (int)SvIV(ST(1)); const bool RETVAL = sv_utf8_downgrade(sv, failok); @@ -766,7 +738,7 @@ XS(XS_utf8_unicode_to_native) XS(XS_Internals_SvREADONLY) /* This is dangerous stuff. */ { dXSARGS; - SV *sv = SvRV(ST(0)); + SV * const sv = SvRV(ST(0)); if (items == 1) { if (SvREADONLY(sv)) @@ -791,7 +763,7 @@ XS(XS_Internals_SvREADONLY) /* This is dangerous stuff. */ XS(XS_Internals_SvREFCNT) /* This is dangerous stuff. */ { dXSARGS; - SV *sv = SvRV(ST(0)); + SV * const sv = SvRV(ST(0)); if (items == 1) XSRETURN_IV(SvREFCNT(sv) - 1); /* Minus the ref created for us. */ @@ -806,12 +778,14 @@ XS(XS_Internals_SvREFCNT) /* This is dangerous stuff. */ XS(XS_Internals_hv_clear_placehold) { dXSARGS; - HV *hv = (HV *) SvRV(ST(0)); if (items != 1) Perl_croak(aTHX_ "Usage: UNIVERSAL::hv_clear_placeholders(hv)"); - hv_clear_placeholders(hv); - XSRETURN(0); + else { + HV * const hv = (HV *) SvRV(ST(0)); + hv_clear_placeholders(hv); + XSRETURN(0); + } } XS(XS_Regexp_DESTROY) @@ -833,13 +807,12 @@ XS(XS_PerlIO_get_layers) bool details = FALSE; if (items > 1) { - SV **svp; - + SV * const *svp; for (svp = MARK + 2; svp <= SP; svp += 2) { - SV **varp = svp; - SV **valp = svp + 1; + SV * const * const varp = svp; + SV * const * const valp = svp + 1; STRLEN klen; - const char *key = SvPV_const(*varp, klen); + const char * const key = SvPV_const(*varp, klen); switch (*key) { case 'i': @@ -883,25 +856,20 @@ XS(XS_PerlIO_get_layers) if (gv && (io = GvIO(gv))) { dTARGET; - AV* av = PerlIO_get_layers(aTHX_ input ? + AV* const av = PerlIO_get_layers(aTHX_ input ? IoIFP(io) : IoOFP(io)); I32 i; - I32 last = av_len(av); + const I32 last = av_len(av); I32 nitem = 0; for (i = last; i >= 0; i -= 3) { - SV **namsvp; - SV **argsvp; - SV **flgsvp; - bool namok, argok, flgok; - - namsvp = av_fetch(av, i - 2, FALSE); - argsvp = av_fetch(av, i - 1, FALSE); - flgsvp = av_fetch(av, i, FALSE); + SV * const * const namsvp = av_fetch(av, i - 2, FALSE); + SV * const * const argsvp = av_fetch(av, i - 1, FALSE); + SV * const * const flgsvp = av_fetch(av, i, FALSE); - namok = namsvp && *namsvp && SvPOK(*namsvp); - argok = argsvp && *argsvp && SvPOK(*argsvp); - flgok = flgsvp && *flgsvp && SvIOK(*flgsvp); + const bool namok = namsvp && *namsvp && SvPOK(*namsvp); + const bool argok = argsvp && *argsvp && SvPOK(*argsvp); + const bool flgok = flgsvp && *flgsvp && SvIOK(*flgsvp); if (details) { XPUSHs(namok @@ -926,7 +894,7 @@ XS(XS_PerlIO_get_layers) XPUSHs(&PL_sv_undef); nitem++; if (flgok) { - IV flags = SvIVX(*flgsvp); + const IV flags = SvIVX(*flgsvp); if (flags & PERLIO_F_UTF8) { XPUSHs(newSVpvn("utf8", 4)); @@ -970,7 +938,7 @@ XS(XS_Internals_HvREHASH) /* Subject to change */ { dXSARGS; if (SvROK(ST(0))) { - const HV *hv = (HV *) SvRV(ST(0)); + const HV * const hv = (HV *) SvRV(ST(0)); if (items == 1 && SvTYPE(hv) == SVt_PVHV) { if (HvREHASH(hv)) XSRETURN_YES; diff --git a/util.c b/util.c index 76ca325..ecec110 100644 --- a/util.c +++ b/util.c @@ -552,7 +552,7 @@ Perl_fbm_instr(pTHX_ unsigned char *big, register unsigned char *bigend, SV *lit return Nullch; } if (SvTYPE(littlestr) != SVt_PVBM || !SvVALID(littlestr)) { - char *b = ninstr((char*)big,(char*)bigend, + char * const b = ninstr((char*)big,(char*)bigend, (char*)little, (char*)little + littlelen); if (!b && SvTAIL(littlestr)) { /* Automatically multiline! */ @@ -569,7 +569,7 @@ Perl_fbm_instr(pTHX_ unsigned char *big, register unsigned char *bigend, SV *lit } { /* Do actual FBM. */ - register const unsigned char *table = little + littlelen + FBM_TABLE_OFFSET; + register const unsigned char * const table = little + littlelen + FBM_TABLE_OFFSET; register const unsigned char *oldlittle; if (littlelen > (STRLEN)(bigend - big)) @@ -985,7 +985,7 @@ S_closest_cop(pTHX_ COP *cop, const OP *o) SV * Perl_vmess(pTHX_ const char *pat, va_list *args) { - SV *sv = mess_alloc(); + SV * const sv = mess_alloc(); static const char dgd[] = " during global destruction.\n"; sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); @@ -1510,16 +1510,17 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val) if (val == NULL) { (void)unsetenv(nam); } else { - int nlen = strlen(nam); - int vlen = strlen(val); - char *new_env = + const int nlen = strlen(nam); + const int vlen = strlen(val); + char * const new_env = (char*)safesysmalloc((nlen + vlen + 2) * sizeof(char)); my_setenv_format(new_env, nam, nlen, val, vlen); (void)putenv(new_env); } # else /* ! HAS_UNSETENV */ char *new_env; - int nlen = strlen(nam), vlen; + const int nlen = strlen(nam); + int vlen; if (!val) { val = ""; } @@ -2640,12 +2641,9 @@ Perl_wait4pid(pTHX_ Pid_t pid, int *statusp, int flags) #ifdef PERL_USES_PL_PIDSTATUS { if (pid > 0) { - SV** svp; - /* The keys in PL_pidstatus are now the raw 4 (or 8) bytes of the pid, rather than a string form. */ - - svp = hv_fetch(PL_pidstatus,(const char*) &pid,sizeof(Pid_t),FALSE); + SV * const * const svp = hv_fetch(PL_pidstatus,(const char*) &pid,sizeof(Pid_t),FALSE); if (svp && *svp != &PL_sv_undef) { *statusp = SvIVX(*svp); (void)hv_delete(PL_pidstatus,(const char*) &pid,sizeof(Pid_t), @@ -2658,7 +2656,7 @@ Perl_wait4pid(pTHX_ Pid_t pid, int *statusp, int flags) hv_iterinit(PL_pidstatus); if ((entry = hv_iternext(PL_pidstatus))) { - SV *sv = hv_iterval(PL_pidstatus,entry); + SV * const sv = hv_iterval(PL_pidstatus,entry); I32 len; const char *spid = hv_iterkey(entry,&len); @@ -2740,7 +2738,7 @@ Perl_my_pclose(pTHX_ PerlIO *ptr) #endif { /* Needs work for PerlIO ! */ - FILE *f = PerlIO_findFILE(ptr); + FILE * const f = PerlIO_findFILE(ptr); I32 result = pclose(f); PerlIO_releaseFILE(ptr,f); return result; @@ -2753,7 +2751,7 @@ I32 Perl_my_pclose(pTHX_ PerlIO *ptr) { /* Needs work for PerlIO ! */ - FILE *f = PerlIO_findFILE(ptr); + FILE * const f = PerlIO_findFILE(ptr); I32 result = djgpp_pclose(f); result = (result << 8) & 0xff00; PerlIO_releaseFILE(ptr,f); @@ -2765,7 +2763,7 @@ void Perl_repeatcpy(pTHX_ register char *to, register const char *from, I32 len, register I32 count) { register I32 todo; - register const char *frombase = from; + register const char * const frombase = from; if (len == 1) { register const char c = *from; @@ -2789,7 +2787,7 @@ Perl_same_dirent(pTHX_ const char *a, const char *b) char *fb = strrchr(b,'/'); Stat_t tmpstatbuf1; Stat_t tmpstatbuf2; - SV *tmpsv = sv_newmortal(); + SV * const tmpsv = sv_newmortal(); if (fa) fa++; @@ -2875,16 +2873,16 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, # ifdef ALWAYS_DEFTYPES len = strlen(scriptname); if (!(len == 1 && *scriptname == '-') && scriptname[len-1] != ':') { - int hasdir, idx = 0, deftypes = 1; + int idx = 0, deftypes = 1; bool seen_dot = 1; - hasdir = !dosearch || (strpbrk(scriptname,":[