From: Andy Lester Date: Thu, 10 Nov 2005 22:47:00 +0000 (-0600) Subject: Const & local: Special Victims Unit X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0bcc34c2b0b0cb62c0df3d5e562b779fb96595ba;p=p5sagit%2Fp5-mst-13.2.git Const & local: Special Victims Unit Message-ID: <20051111044700.GA24161@petdance.com> p4raw-id: //depot/perl@26082 --- diff --git a/cop.h b/cop.h index 618da4d..ff09420 100644 --- a/cop.h +++ b/cop.h @@ -741,9 +741,9 @@ See L. #define PUSH_MULTICALL(the_cv) \ STMT_START { \ - CV *_nOnclAshIngNamE_ = the_cv; \ - CV *cv = _nOnclAshIngNamE_; \ - AV* padlist = CvPADLIST(cv); \ + CV * const _nOnclAshIngNamE_ = the_cv; \ + CV * const cv = _nOnclAshIngNamE_; \ + AV * const padlist = CvPADLIST(cv); \ ENTER; \ multicall_oldcatch = CATCH_GET; \ SAVETMPS; SAVEVPTR(PL_op); \ diff --git a/doio.c b/doio.c index be67c6e..e1ddfcb 100644 --- a/doio.c +++ b/doio.c @@ -686,7 +686,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, } #if defined(HAS_FCNTL) && defined(F_SETFD) if (fd >= 0) { - int save_errno = errno; + const int save_errno = errno; fcntl(fd,F_SETFD,fd > PL_maxsysfd); /* can change errno */ errno = save_errno; } @@ -990,12 +990,12 @@ Perl_io_close(pTHX_ IO *io, bool not_implicit) retval = TRUE; else { if (IoOFP(io) && IoOFP(io) != IoIFP(io)) { /* a socket */ - bool prev_err = PerlIO_error(IoOFP(io)); + const bool prev_err = PerlIO_error(IoOFP(io)); retval = (PerlIO_close(IoOFP(io)) != EOF && !prev_err); PerlIO_close(IoIFP(io)); /* clear stdio, fd already closed */ } else { - bool prev_err = PerlIO_error(IoIFP(io)); + const bool prev_err = PerlIO_error(IoIFP(io)); retval = (PerlIO_close(IoIFP(io)) != EOF && !prev_err); } } @@ -1011,10 +1011,7 @@ Perl_io_close(pTHX_ IO *io, bool not_implicit) bool Perl_do_eof(pTHX_ GV *gv) { - register IO *io; - int ch; - - io = GvIO(gv); + register IO * const io = GvIO(gv); if (!io) return TRUE; @@ -1023,6 +1020,7 @@ Perl_do_eof(pTHX_ GV *gv) while (IoIFP(io)) { int saverrno; + int ch; if (PerlIO_has_cntptr(IoIFP(io))) { /* (the code works without this) */ if (PerlIO_get_cnt(IoIFP(io)) > 0) /* cheat a little, since */ @@ -1297,7 +1295,7 @@ Perl_my_stat(pTHX) return PL_laststatval; } else { - SV* sv = POPs; + SV* const sv = POPs; const char *s; STRLEN len; PUTBACK; @@ -1428,10 +1426,9 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) register char **a; register char *s; char *cmd; - int cmdlen; /* Make a copy so we can change it */ - cmdlen = strlen(incmd); + const int cmdlen = strlen(incmd); Newx(cmd, cmdlen+1, char); strncpy(cmd, incmd, cmdlen); cmd[cmdlen] = 0; @@ -1463,7 +1460,7 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) if (*s == ' ') s++; if (*s++ == '\'') { - char *ncmd = s; + char * const ncmd = s; while (*s) s++; @@ -1738,7 +1735,7 @@ nothing in the core. if (val < 0) { val = -val; while (++mark <= sp) { - I32 proc = SvIVx(*mark); + const I32 proc = SvIVx(*mark); APPLY_TAINT_PROPER(); #ifdef HAS_KILLPG if (PerlProc_killpg(proc,val)) /* BSD */ @@ -1750,7 +1747,7 @@ nothing in the core. } else { while (++mark <= sp) { - I32 proc = SvIVx(*mark); + const I32 proc = SvIVx(*mark); APPLY_TAINT_PROPER(); if (PerlProc_kill(proc, val)) tot--; @@ -1798,8 +1795,8 @@ nothing in the core. void *utbufp = &utbuf; #endif - SV* accessed = *++mark; - SV* modified = *++mark; + SV* const accessed = *++mark; + SV* const modified = *++mark; /* Be like C, and if both times are undefined, let the C * library figure out what to do. This usually means @@ -1847,7 +1844,7 @@ nothing in the core. goto do_futimes; } else { - const char *name = SvPV_nolen_const(*mark); + const char * const name = SvPV_nolen_const(*mark); APPLY_TAINT_PROPER(); #ifdef HAS_FUTIMES if (utimes(name, utbufp)) @@ -1958,7 +1955,7 @@ Perl_ingroup(pTHX_ Gid_t testgid, bool effective) I32 Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp) { - key_t key = (key_t)SvNVx(*++mark); + const key_t key = (key_t)SvNVx(*++mark); const I32 n = (optype == OP_MSGGET) ? 0 : SvIVx(*++mark); const I32 flags = SvIVx(*++mark); (void)sp; @@ -1989,19 +1986,16 @@ Perl_do_ipcget(pTHX_ I32 optype, SV **mark, SV **sp) I32 Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp) { - SV *astr; char *a; - STRLEN infosize; - I32 getinfo; I32 ret = -1; const I32 id = SvIVx(*++mark); const I32 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0; const I32 cmd = SvIVx(*++mark); - PERL_UNUSED_ARG(sp); + SV * const astr = *++mark; + STRLEN infosize = 0; + I32 getinfo = (cmd == IPC_STAT); - astr = *++mark; - infosize = 0; - getinfo = (cmd == IPC_STAT); + PERL_UNUSED_ARG(sp); switch (optype) { @@ -2069,7 +2063,7 @@ Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp) } else { - IV i = SvIV(astr); + const IV i = SvIV(astr); a = INT2PTR(char *,i); /* ouch */ } SETERRNO(0,0); @@ -2115,17 +2109,16 @@ I32 Perl_do_msgsnd(pTHX_ SV **mark, SV **sp) { #ifdef HAS_MSG - SV *mstr; - const char *mbuf; - I32 msize, flags; STRLEN len; const I32 id = SvIVx(*++mark); + SV * const mstr = *++mark; + const I32 flags = SvIVx(*++mark); + const char * const mbuf = SvPV_const(mstr, len); + const I32 msize = len - sizeof(long); + PERL_UNUSED_ARG(sp); - mstr = *++mark; - flags = SvIVx(*++mark); - mbuf = SvPV_const(mstr, len); - if ((msize = len - sizeof(long)) < 0) + if (msize < 0) Perl_croak(aTHX_ "Arg too short for msgsnd"); SETERRNO(0,0); return msgsnd(id, (struct msgbuf *)mbuf, msize, flags); @@ -2138,14 +2131,13 @@ I32 Perl_do_msgrcv(pTHX_ SV **mark, SV **sp) { #ifdef HAS_MSG - SV *mstr; char *mbuf; long mtype; I32 msize, flags, ret; const I32 id = SvIVx(*++mark); + SV * const mstr = *++mark; PERL_UNUSED_ARG(sp); - mstr = *++mark; /* suppress warning when reading into undef var --jhi */ if (! SvOK(mstr)) sv_setpvn(mstr, "", 0); @@ -2175,14 +2167,12 @@ I32 Perl_do_semop(pTHX_ SV **mark, SV **sp) { #ifdef HAS_SEM - SV *opstr; - const char *opbuf; STRLEN opsize; const I32 id = SvIVx(*++mark); + SV * const opstr = *++mark; + const char * const opbuf = SvPV_const(opstr, opsize); PERL_UNUSED_ARG(sp); - opstr = *++mark; - opbuf = SvPV_const(opstr, opsize); if (opsize < 3 * SHORTSIZE || (opsize % (3 * SHORTSIZE))) { SETERRNO(EINVAL,LIB_INVARG); @@ -2193,7 +2183,7 @@ Perl_do_semop(pTHX_ SV **mark, SV **sp) { const int nsops = opsize / (3 * sizeof (short)); int i = nsops; - short *ops = (short *) opbuf; + short * const ops = (short *) opbuf; short *o = ops; struct sembuf *temps, *t; I32 result; @@ -2228,16 +2218,14 @@ I32 Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) { #ifdef HAS_SHM - SV *mstr; char *shm; - I32 mpos, msize; struct shmid_ds shmds; const I32 id = SvIVx(*++mark); + SV * const mstr = *++mark; + const I32 mpos = SvIVx(*++mark); + const I32 msize = SvIVx(*++mark); PERL_UNUSED_ARG(sp); - mstr = *++mark; - mpos = SvIVx(*++mark); - msize = SvIVx(*++mark); SETERRNO(0,0); if (shmctl(id, IPC_STAT, &shmds) == -1) return -1; diff --git a/doop.c b/doop.c index ec8fab2..8733816 100644 --- a/doop.c +++ b/doop.c @@ -311,7 +311,6 @@ S_do_trans_simple_utf8(pTHX_ SV *sv) const UV none = svp ? SvUV(*svp) : 0x7fffffff; const UV extra = none + 1; UV final = 0; - UV uv; I32 isutf8; U8 hibit = 0; @@ -347,7 +346,8 @@ S_do_trans_simple_utf8(pTHX_ SV *sv) } while (s < send) { - if ((uv = swash_fetch(rv, s, TRUE)) < none) { + const UV uv = swash_fetch(rv, s, TRUE); + if (uv < none) { s += UTF8SKIP(s); matches++; d = uvuni_to_utf8(d, uv); @@ -973,7 +973,7 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv) if (DO_UTF8(sv)) { if (s && len) { char * const send = s + len; - char *start = s; + char * const start = s; s = send - 1; while (s > start && UTF8_IS_CONTINUATION(*s)) s--; diff --git a/pp_hot.c b/pp_hot.c index 0f13d5a..24af67e 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -794,7 +794,7 @@ PP(pp_rv2av) if (SvRMAGICAL(av)) { U32 i; for (i=0; i < (U32)maxarg; i++) { - SV **svp = av_fetch(av, i, FALSE); + SV ** const svp = av_fetch(av, i, FALSE); /* See note in pp_helem, and bug id #27839 */ SP[i+1] = svp ? SvGMAGICAL(*svp) ? sv_mortalcopy(*svp) : *svp @@ -1395,7 +1395,7 @@ yup: /* Confirmed by INTUIT */ rx->subbeg = (char *) truebase; rx->startp[0] = s - truebase; if (RX_MATCH_UTF8(rx)) { - char *t = (char*)utf8_hop((U8*)s, rx->minlen); + char * const t = (char*)utf8_hop((U8*)s, rx->minlen); rx->endp[0] = t - truebase; } else { @@ -1888,11 +1888,8 @@ PP(pp_iter) RETPUSHNO; if (SvMAGICAL(av) || AvREIFY(av)) { - SV **svp = av_fetch(av, cx->blk_loop.iterix--, FALSE); - if (svp) - sv = *svp; - else - sv = Nullsv; + SV ** const svp = av_fetch(av, cx->blk_loop.iterix--, FALSE); + sv = svp ? *svp : Nullsv; } else { sv = AvARRAY(av)[cx->blk_loop.iterix--]; @@ -1904,11 +1901,8 @@ PP(pp_iter) RETPUSHNO; if (SvMAGICAL(av) || AvREIFY(av)) { - SV **svp = av_fetch(av, ++cx->blk_loop.iterix, FALSE); - if (svp) - sv = *svp; - else - sv = Nullsv; + SV ** const svp = av_fetch(av, ++cx->blk_loop.iterix, FALSE); + sv = svp ? *svp : Nullsv; } else { sv = AvARRAY(av)[++cx->blk_loop.iterix]; @@ -1973,7 +1967,7 @@ PP(pp_subst) register REGEXP *rx = PM_GETRE(pm); STRLEN len; int force_on_match = 0; - I32 oldsave = PL_savestack_ix; + const I32 oldsave = PL_savestack_ix; STRLEN slen; bool doutf8 = FALSE; #ifdef PERL_OLD_COPY_ON_WRITE @@ -2571,7 +2565,7 @@ PP(pp_leavesublv) STATIC CV * S_get_db_sub(pTHX_ SV **svp, CV *cv) { - SV *dbsv = GvSVn(PL_DBsub); + SV * const dbsv = GvSVn(PL_DBsub); save_item(dbsv); if (!PERLDB_SUB_NN) { @@ -2693,7 +2687,7 @@ PP(pp_entersub) /* This path taken at least 75% of the time */ dMARK; register I32 items = SP - MARK; - AV* padlist = CvPADLIST(cv); + AV* const padlist = CvPADLIST(cv); PUSHBLOCK(cx, CXt_SUB, MARK); PUSHSUB(cx); cx->blk_sub.retop = PL_op->op_next; @@ -2711,12 +2705,7 @@ PP(pp_entersub) PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv)); if (hasargs) { - AV* av; -#if 0 - DEBUG_S(PerlIO_printf(Perl_debug_log, - "%p entersub preparing @_\n", thr)); -#endif - av = (AV*)PAD_SVl(0); + AV* const av = (AV*)PAD_SVl(0); if (AvREAL(av)) { /* @_ is normally not REAL--this should only ever * happen when DB::sub() calls things that modify @_ */ @@ -2884,7 +2873,7 @@ PP(pp_aelem) SV** svp; SV* const elemsv = POPs; IV elem = SvIV(elemsv); - AV* av = (AV*)POPs; + AV* const av = (AV*)POPs; const U32 lval = PL_op->op_flags & OPf_MOD || LVRET; const U32 defer = (PL_op->op_private & OPpLVAL_DEFER) && (elem > av_len(av)); SV *sv; diff --git a/pp_pack.c b/pp_pack.c index b8e94a1..89b1a1c 100644 --- a/pp_pack.c +++ b/pp_pack.c @@ -179,7 +179,7 @@ S_mul128(pTHX_ SV *sv, U8 m) char *t; if (!strnEQ(s, "0000", 4)) { /* need to grow sv */ - SV *tmpNew = newSVpvn("0000000000", 10); + SV * const tmpNew = newSVpvn("0000000000", 10); sv_catsv(tmpNew, sv); SvREFCNT_dec(sv); /* free old sv */ @@ -612,9 +612,8 @@ STATIC const packprops_t packprops[512] = { STATIC U8 uni_to_byte(pTHX_ const char **s, const char *end, I32 datumtype) { - UV val; STRLEN retlen; - val = utf8n_to_uvchr((U8 *) *s, end-*s, &retlen, + UV val = utf8n_to_uvchr((U8 *) *s, end-*s, &retlen, ckWARN(WARN_UTF8) ? 0 : UTF8_ALLOW_ANY); /* We try to process malformed UTF-8 as much as possible (preferrably with warnings), but these two mean we make no progress in the string and @@ -685,9 +684,8 @@ uni_to_bytes(pTHX_ const char **s, const char *end, const char *buf, int buf_len STATIC bool next_uni_uu(pTHX_ const char **s, const char *end, I32 *out) { - UV val; STRLEN retlen; - val = utf8n_to_uvchr((U8 *) *s, end-*s, &retlen, UTF8_CHECK_ONLY); + const UV val = utf8n_to_uvchr((U8 *) *s, end-*s, &retlen, UTF8_CHECK_ONLY); if (val >= 0x100 || !ISUUCHAR(val) || retlen == (STRLEN) -1 || retlen == 0) { *out = 0; @@ -701,7 +699,7 @@ next_uni_uu(pTHX_ const char **s, const char *end, I32 *out) STATIC void bytes_to_uni(pTHX_ const U8 *start, STRLEN len, char **dest) { U8 buffer[UTF8_MAXLEN]; - const U8 *end = start + len; + const U8 * const end = start + len; char *d = *dest; while (start < end) { const int length = @@ -943,7 +941,7 @@ STATIC bool S_next_symbol(pTHX_ tempsym_t* symptr ) { const char* patptr = symptr->patptr; - const char* patend = symptr->patend; + const char* const patend = symptr->patend; symptr->flags &= ~FLAG_SLASH; diff --git a/pp_sort.c b/pp_sort.c index 245426e..7580bf3 100644 --- a/pp_sort.c +++ b/pp_sort.c @@ -1322,24 +1322,24 @@ S_qsortsvu(pTHX_ SV ** array, size_t num_elts, SVCOMPARE_t compare) static I32 cmpindir(pTHX_ gptr a, gptr b) { - I32 sense; gptr * const ap = (gptr *)a; gptr * const bp = (gptr *)b; + const I32 sense = PL_sort_RealCmp(aTHX_ *ap, *bp); - if ((sense = PL_sort_RealCmp(aTHX_ *ap, *bp)) == 0) - sense = (ap > bp) ? 1 : ((ap < bp) ? -1 : 0); - return sense; + if (sense) + return sense; + return (ap > bp) ? 1 : ((ap < bp) ? -1 : 0); } static I32 cmpindir_desc(pTHX_ gptr a, gptr b) { - I32 sense; gptr * const ap = (gptr *)a; gptr * const bp = (gptr *)b; + const I32 sense = PL_sort_RealCmp(aTHX_ *ap, *bp); /* Reverse the default */ - if ((sense = PL_sort_RealCmp(aTHX_ *ap, *bp))) + if (sense) return -sense; /* But don't reverse the stability test. */ return (ap > bp) ? 1 : ((ap < bp) ? -1 : 0); @@ -1491,7 +1491,7 @@ PP(pp_sort) GV *gv; CV *cv = 0; I32 gimme = GIMME; - OP* nextop = PL_op->op_next; + OP* const nextop = PL_op->op_next; I32 overloading = 0; bool hasargs = FALSE; I32 is_xsub = 0; @@ -1660,7 +1660,7 @@ PP(pp_sort) cx->blk_gimme = G_SCALAR; PUSHSUB(cx); if (!is_xsub) { - AV* padlist = CvPADLIST(cv); + AV* const padlist = CvPADLIST(cv); if (++CvDEPTH(cv) >= 2) { PERL_STACK_OVERFLOW_CHECK(); @@ -1714,7 +1714,7 @@ PP(pp_sort) if (priv & OPpSORT_REVERSE) { SV **q = start+max-1; while (start < q) { - SV *tmp = *start; + SV * const tmp = *start; *start++ = *q; *q-- = tmp; } diff --git a/pp_sys.c b/pp_sys.c index 4d22a82..3bfff96 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -479,7 +479,7 @@ PP(pp_die) tmps = SvROK(tmpsv) ? Nullch : SvPV_const(tmpsv, len); } if (!tmps || !len) { - SV *error = ERRSV; + SV * const error = ERRSV; SvUPGRADE(error, SVt_PV); if (multiarg ? SvROK(error) : SvROK(tmpsv)) { if (!multiarg) @@ -877,7 +877,7 @@ PP(pp_untie) if ((mg = SvTIED_mg(sv, how))) { SV * const obj = SvRV(SvTIED_obj(sv, mg)); - CV *cv; + CV *cv = NULL; if (obj) { GV * const gv = gv_fetchmethod_autoload(SvSTASH(obj), "UNTIE", FALSE); if (gv && isGV(gv) && (cv = GvCV(gv))) { @@ -2036,7 +2036,7 @@ PP(pp_sysseek) if (PL_op->op_type == OP_SEEK) PUSHs(boolSV(do_seek(gv, offset, whence))); else { - Off_t sought = do_sysseek(gv, offset, whence); + const Off_t sought = do_sysseek(gv, offset, whence); if (sought < 0) PUSHs(&PL_sv_undef); else { @@ -2061,11 +2061,12 @@ PP(pp_truncate) * general one would think that when using large files, off_t is * at least as wide as size_t, so using an off_t should be okay. */ /* XXX Configure probe for the length type of *truncate() needed XXX */ + Off_t len; #if Off_t_size > IVSIZE - const Off_t len = (Off_t)POPn; + len = (Off_t)POPn; #else - const Off_t len = (Off_t)POPi; + len = (Off_t)POPi; #endif /* Checking for length < 0 is problematic as the type might or * might not be signed: if it is not, clever compilers will moan. */ @@ -2237,6 +2238,7 @@ PP(pp_flock) fp = Nullfp; io = NULL; } + /* XXX Looks to me like io is always NULL at this point */ if (fp) { (void)PerlIO_flush(fp); value = (I32)(PerlLIO_flock(PerlIO_fileno(fp), argtype) >= 0); @@ -3512,7 +3514,7 @@ S_dooneliner(pTHX_ const char *cmd, const char *filename) Safefree(cmdline); if (myfp) { - SV *tmpsv = sv_newmortal(); + SV * const tmpsv = sv_newmortal(); /* Need to save/restore 'PL_rs' ?? */ s = sv_gets(tmpsv, myfp, 0); (void)PerlProc_pclose(myfp); @@ -3600,9 +3602,6 @@ S_dooneliner(pTHX_ const char *cmd, const char *filename) PP(pp_mkdir) { dSP; dTARGET; -#ifndef HAS_MKDIR - int oldumask; -#endif STRLEN len; const char *tmps; bool copy = FALSE; @@ -3614,10 +3613,13 @@ PP(pp_mkdir) #ifdef HAS_MKDIR SETi( PerlDir_mkdir(tmps, mode) >= 0 ); #else + { + int oldumask; SETi( dooneliner("mkdir", tmps) ); oldumask = PerlLIO_umask(0); PerlLIO_umask(oldumask); PerlLIO_chmod(tmps, (mode & ~oldumask) & 0777); + } #endif if (copy) Safefree(tmps); @@ -3903,13 +3905,11 @@ PP(pp_waitpid) { #if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) dSP; dTARGET; - Pid_t pid; + const int optype = POPi; + const Pid_t pid = TOPi; Pid_t result; - int optype; int argflags; - optype = POPi; - pid = TOPi; if (PL_signals & PERL_SIGNALS_UNSAFE_FLAG) result = wait4pid(pid, &argflags, optype); else { @@ -4019,7 +4019,7 @@ PP(pp_system) #endif } if (PL_op->op_flags & OPf_STACKED) { - SV *really = *++MARK; + SV * const really = *++MARK; value = (I32)do_aexec5(really, MARK, SP, pp[1], did_pipes); } else if (SP - MARK != 1) @@ -4033,7 +4033,7 @@ PP(pp_system) PL_statusvalue = 0; result = 0; if (PL_op->op_flags & OPf_STACKED) { - SV *really = *++MARK; + SV * const really = *++MARK; # if defined(WIN32) || defined(OS2) || defined(__SYMBIAN32__) value = (I32)do_aspawn(really, MARK, SP); # else @@ -4077,7 +4077,7 @@ PP(pp_exec) } PERL_FLUSHALL_FOR_CHILD; if (PL_op->op_flags & OPf_STACKED) { - SV *really = *++MARK; + SV * const really = *++MARK; value = (I32)do_aexec(really, MARK, SP); } else if (SP - MARK != 1) @@ -4133,13 +4133,9 @@ PP(pp_getpgrp) { #ifdef HAS_GETPGRP dSP; dTARGET; - Pid_t pid; Pid_t pgrp; + const Pid_t pid = (MAXARG < 1) ? 0 : SvIVx(POPs); - if (MAXARG < 1) - pid = 0; - else - pid = SvIVx(POPs); #ifdef BSD_GETPGRP pgrp = (I32)BSD_GETPGRP(pid); #else @@ -4190,8 +4186,8 @@ PP(pp_getpriority) { #ifdef HAS_GETPRIORITY dSP; dTARGET; - int who = POPi; - int which = TOPi; + const int who = POPi; + const int which = TOPi; SETi( getpriority(which, who) ); RETURN; #else @@ -4203,9 +4199,9 @@ PP(pp_setpriority) { #ifdef HAS_SETPRIORITY dSP; dTARGET; - int niceval = POPi; - int who = POPi; - int which = TOPi; + const int niceval = POPi; + const int who = POPi; + const int which = TOPi; TAINT_PROPER("setpriority"); SETi( setpriority(which, who, niceval) >= 0 ); RETURN; @@ -4440,7 +4436,7 @@ PP(pp_semget) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) dSP; dMARK; dTARGET; - int anum = do_ipcget(PL_op->op_type, MARK, SP); + const int anum = do_ipcget(PL_op->op_type, MARK, SP); SP = MARK; if (anum == -1) RETPUSHUNDEF; @@ -4455,7 +4451,7 @@ PP(pp_semctl) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) dSP; dMARK; dTARGET; - int anum = do_ipcctl(PL_op->op_type, MARK, SP); + const int anum = do_ipcctl(PL_op->op_type, MARK, SP); SP = MARK; if (anum == -1) RETSETUNDEF; @@ -4491,7 +4487,7 @@ PP(pp_ghostent) EXTEND(SP, 10); if (which == OP_GHBYNAME) { #ifdef HAS_GETHOSTBYNAME - char* name = POPpbytex; + const char* const name = POPpbytex; hent = PerlSock_gethostbyname(name); #else DIE(aTHX_ PL_no_sock_func, "gethostbyname"); @@ -4499,10 +4495,10 @@ PP(pp_ghostent) } else if (which == OP_GHBYADDR) { #ifdef HAS_GETHOSTBYADDR - int addrtype = POPi; - SV *addrsv = POPs; + const int addrtype = POPi; + SV * const addrsv = POPs; STRLEN addrlen; - Netdb_host_t addr = (Netdb_host_t) SvPVbyte(addrsv, addrlen); + const Netdb_host_t addr = (Netdb_host_t) SvPVbyte(addrsv, addrlen); hent = PerlSock_gethostbyaddr(addr, (Netdb_hlen_t) addrlen, addrtype); #else @@ -4587,7 +4583,7 @@ PP(pp_gnetent) if (which == OP_GNBYNAME){ #ifdef HAS_GETNETBYNAME - char *name = POPpbytex; + const char * const name = POPpbytex; nent = PerlSock_getnetbyname(name); #else DIE(aTHX_ PL_no_sock_func, "getnetbyname"); @@ -4595,8 +4591,8 @@ PP(pp_gnetent) } else if (which == OP_GNBYADDR) { #ifdef HAS_GETNETBYADDR - int addrtype = POPi; - Netdb_net_t addr = (Netdb_net_t) (U32)POPu; + const int addrtype = POPi; + const Netdb_net_t addr = (Netdb_net_t) (U32)POPu; nent = PerlSock_getnetbyaddr(addr, addrtype); #else DIE(aTHX_ PL_no_sock_func, "getnetbyaddr"); @@ -4669,7 +4665,7 @@ PP(pp_gprotoent) if (which == OP_GPBYNAME) { #ifdef HAS_GETPROTOBYNAME - char* name = POPpbytex; + const char* const name = POPpbytex; pent = PerlSock_getprotobyname(name); #else DIE(aTHX_ PL_no_sock_func, "getprotobyname"); @@ -4677,7 +4673,7 @@ PP(pp_gprotoent) } else if (which == OP_GPBYNUMBER) { #ifdef HAS_GETPROTOBYNUMBER - int number = POPi; + const int number = POPi; pent = PerlSock_getprotobynumber(number); #else DIE(aTHX_ PL_no_sock_func, "getprotobynumber"); @@ -4737,29 +4733,21 @@ PP(pp_gservent) if (which == OP_GSBYNAME) { #ifdef HAS_GETSERVBYNAME - char *proto = POPpbytex; - char *name = POPpbytex; - - if (proto && !*proto) - proto = Nullch; - - sent = PerlSock_getservbyname(name, proto); + const char * const proto = POPpbytex; + const char * const name = POPpbytex; + sent = PerlSock_getservbyname(name, (proto && !*proto) ? Nullch : proto); #else DIE(aTHX_ PL_no_sock_func, "getservbyname"); #endif } else if (which == OP_GSBYPORT) { #ifdef HAS_GETSERVBYPORT - char *proto = POPpbytex; + const char * const proto = POPpbytex; unsigned short port = (unsigned short)POPu; - - if (proto && !*proto) - proto = Nullch; - #ifdef HAS_HTONS port = PerlSock_htons(port); #endif - sent = PerlSock_getservbyport(port, proto); + sent = PerlSock_getservbyport(port, (proto && !*proto) ? Nullch : proto); #else DIE(aTHX_ PL_no_sock_func, "getservbyport"); #endif @@ -4981,7 +4969,7 @@ PP(pp_gpwent) switch (which) { case OP_GPWNAM: { - char* name = POPpbytex; + const char* const name = POPpbytex; pwent = getpwnam(name); } break; @@ -5045,14 +5033,12 @@ PP(pp_gpwent) * has a different API than the Solaris/IRIX one. */ # if defined(HAS_GETSPNAM) && !defined(_AIX) { - struct spwd *spwent; - int saverrno; /* Save and restore errno so that + const int saverrno = errno; + const struct spwd * const spwent = getspnam(pwent->pw_name); + /* Save and restore errno so that * underprivileged attempts seem * to have never made the unsccessful * attempt to retrieve the shadow password. */ - - saverrno = errno; - spwent = getspnam(pwent->pw_name); errno = saverrno; if (spwent && spwent->sp_pwdp) sv_setpv(sv, spwent->sp_pwdp); @@ -5173,11 +5159,11 @@ PP(pp_ggrent) struct group *grent; if (which == OP_GGRNAM) { - char* name = POPpbytex; + const char* const name = POPpbytex; grent = (struct group *)getgrnam(name); } else if (which == OP_GGRGID) { - Gid_t gid = POPi; + const Gid_t gid = POPi; grent = (struct group *)getgrgid(gid); } else @@ -5437,11 +5423,10 @@ static int lockf_emulate_flock(int fd, int operation) { int i; - int save_errno; + const int save_errno = errno; Off_t pos; /* flock locks entire file so for lockf we need to do the same */ - save_errno = errno; pos = PerlLIO_lseek(fd, (Off_t)0, SEEK_CUR); /* get pos to restore later */ if (pos > 0) /* is seekable and needs to be repositioned */ if (PerlLIO_lseek(fd, (Off_t)0, SEEK_SET) < 0) diff --git a/sv.c b/sv.c index 4b83f13..04585ea 100644 --- a/sv.c +++ b/sv.c @@ -9703,8 +9703,8 @@ Perl_mg_dup(pTHX_ MAGIC *mg, CLONE_PARAMS* param) if (mg->mg_type == PERL_MAGIC_overload_table && AMT_AMAGIC((AMT*)mg->mg_ptr)) { - AMT *amtp = (AMT*)mg->mg_ptr; - AMT *namtp = (AMT*)nmg->mg_ptr; + AMT * const amtp = (AMT*)mg->mg_ptr; + AMT * const namtp = (AMT*)nmg->mg_ptr; I32 i; for (i = 1; i < NofAMmeth; i++) { namtp->table[i] = cv_dup_inc(amtp->table[i], param); diff --git a/util.c b/util.c index e549221..67ed393 100644 --- a/util.c +++ b/util.c @@ -2654,7 +2654,7 @@ Perl_wait4pid(pTHX_ Pid_t pid, int *statusp, int flags) if ((entry = hv_iternext(PL_pidstatus))) { SV * const sv = hv_iterval(PL_pidstatus,entry); I32 len; - const char *spid = hv_iterkey(entry,&len); + const char * const spid = hv_iterkey(entry,&len); assert (len == sizeof(Pid_t)); memcpy((char *)&pid, spid, len); @@ -2836,7 +2836,7 @@ Perl_find_script(pTHX_ const char *scriptname, bool dosearch, #endif /* additional extensions to try in each dir if scriptname not found */ #ifdef SEARCH_EXTS - const char *const exts[] = { SEARCH_EXTS }; + static const char *const exts[] = { SEARCH_EXTS }; const char *const *const ext = search_ext ? search_ext : exts; int extidx = 0, i = 0; const char *curext = Nullch;