From: Andy Lester Date: Tue, 6 Jun 2006 00:25:01 +0000 (-0500) Subject: more accumulated cleanups X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=35da51f7f2e09d38719c2d96d9f3eacd4f9f796a;p=p5sagit%2Fp5-mst-13.2.git more accumulated cleanups Message-ID: <20060606052501.GA30469@petdance.com> p4raw-id: //depot/perl@28358 --- diff --git a/av.c b/av.c index 4692e6b..3dfdf9a 100644 --- a/av.c +++ b/av.c @@ -395,8 +395,7 @@ Perl_av_make(pTHX_ register I32 size, register SV **strp) Newx(ary,size,SV*); AvALLOC(av) = ary; SvPV_set(av, (char*)ary); - AvFILLp(av) = size - 1; - AvMAX(av) = size - 1; + AvFILLp(av) = AvMAX(av) = size - 1; for (i = 0; i < size; i++) { assert (*strp); ary[i] = newSV(0); @@ -482,7 +481,7 @@ Perl_av_undef(pTHX_ register AV *av) SvREFCNT_dec(AvARRAY(av)[--key]); } Safefree(AvALLOC(av)); - AvALLOC(av) = 0; + AvALLOC(av) = NULL; SvPV_set(av, NULL); AvMAX(av) = AvFILLp(av) = -1; } diff --git a/doio.c b/doio.c index 39ba56d..f5f59a3 100644 --- a/doio.c +++ b/doio.c @@ -188,7 +188,6 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, STRLEN olen = len; char *tend; int dodup = 0; - PerlIO *that_fp = NULL; type = savepvn(oname, len); tend = type+len; @@ -321,6 +320,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, fp = supplied_fp; } else { + PerlIO *that_fp = NULL; if (num_svs > 1) { Perl_croak(aTHX_ "More than one argument to '%c&' open",IoTYPE(io)); } @@ -339,8 +339,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, thatio = sv_2io(*svp); } else { - GV *thatgv; - thatgv = gv_fetchpvn_flags(type, tend - type, + GV * const thatgv = gv_fetchpvn_flags(type, tend - type, 0, SVt_PVIO); thatio = GvIO(thatgv); } @@ -939,7 +938,7 @@ Perl_nextargv(pTHX_ register GV *gv) if (io && (IoFLAGS(io) & IOf_ARGV) && PL_argvout_stack && AvFILLp(PL_argvout_stack) >= 0) { - GV *oldout = (GV*)av_pop(PL_argvout_stack); + GV * const oldout = (GV*)av_pop(PL_argvout_stack); setdefout(oldout); SvREFCNT_dec(oldout); return NULL; @@ -1184,7 +1183,6 @@ my_chsize(int fd, Off_t length) /* code courtesy of William Kucharski */ #define HAS_CHSIZE - struct flock fl; Stat_t filebuf; if (PerlLIO_fstat(fd, &filebuf) < 0) @@ -1204,7 +1202,7 @@ my_chsize(int fd, Off_t length) } else { /* truncate length */ - + struct flock fl; fl.l_whence = 0; fl.l_len = 0; fl.l_start = length; @@ -1270,7 +1268,7 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) else if (DO_UTF8(sv)) { STRLEN tmplen = len; bool utf8 = TRUE; - U8 *result = bytes_from_utf8((const U8*) tmps, &tmplen, &utf8); + U8 * const result = bytes_from_utf8((const U8*) tmps, &tmplen, &utf8); if (!utf8) { tmpbuf = result; tmps = (char *) tmpbuf; @@ -1294,8 +1292,7 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp) * io the write failure can be delayed until the flush/close. --jhi */ if (len && (PerlIO_write(fp,tmps,len) == 0)) happy = FALSE; - if (tmpbuf) - Safefree(tmpbuf); + Safefree(tmpbuf); return happy ? !PerlIO_error(fp) : FALSE; } @@ -1508,7 +1505,7 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) if (s[-1] == '\'') { *--s = '\0'; PERL_FPU_PRE_EXEC - PerlProc_execl(PL_cshname,"csh", flags, ncmd, (char*)0); + PerlProc_execl(PL_cshname, "csh", flags, ncmd, NULL); PERL_FPU_POST_EXEC *s = '\''; Safefree(cmd); @@ -1556,7 +1553,7 @@ Perl_do_exec3(pTHX_ const char *incmd, int fd, int do_report) } doshell: PERL_FPU_PRE_EXEC - PerlProc_execl(PL_sh_path, "sh", "-c", cmd, (char*)0); + PerlProc_execl(PL_sh_path, "sh", "-c", cmd, NULL); PERL_FPU_POST_EXEC Safefree(cmd); return FALSE; @@ -2308,12 +2305,10 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp) #endif } else { - I32 n; STRLEN len; const char *mbuf = SvPV_const(mstr, len); - if ((n = len) > msize) - n = msize; + const I32 n = (len > msize) ? msize : len; Copy(mbuf, shm + mpos, n, char); if (n < msize) memzero(shm + mpos + n, msize - n); diff --git a/utf8.c b/utf8.c index dad7920..b62e552 100644 --- a/utf8.c +++ b/utf8.c @@ -262,13 +262,10 @@ See also is_utf8_string_loclen() and is_utf8_string_loc(). bool Perl_is_utf8_string(pTHX_ const U8 *s, STRLEN len) { + const U8* const send = s + (len ? len : strlen((const char *)s)); const U8* x = s; - const U8* send; PERL_UNUSED_CONTEXT; - if (!len) - len = strlen((const char *)s); - send = s + len; while (x < send) { STRLEN c; @@ -329,16 +326,12 @@ See also is_utf8_string_loc() and is_utf8_string(). bool Perl_is_utf8_string_loclen(pTHX_ const U8 *s, STRLEN len, const U8 **ep, STRLEN *el) { + const U8* const send = s + (len ? len : strlen((const char *)s)); const U8* x = s; - const U8* send; STRLEN c; STRLEN outlen = 0; PERL_UNUSED_CONTEXT; - if (!len) - len = strlen((const char *)s); - send = s + len; - while (x < send) { /* Inline the easy bits of is_utf8_char() here for speed... */ if (UTF8_IS_INVARIANT(*x)) @@ -820,7 +813,7 @@ Perl_bytes_from_utf8(pTHX_ const U8 *s, STRLEN *len, bool *is_utf8) } } - *is_utf8 = 0; + *is_utf8 = FALSE; Newx(d, (*len) - count + 1, U8); s = start; start = d; @@ -1389,10 +1382,10 @@ Perl_to_utf8_case(pTHX_ const U8 *p, U8* ustrp, STRLEN *lenp, if (special && (uv1 == 0xDF || uv1 > 0xFF)) { /* It might be "special" (sometimes, but not always, * a multicharacter mapping) */ - HV *hv; + HV * const hv = get_hv(special, FALSE); SV **svp; - if ((hv = get_hv(special, FALSE)) && + if (hv && (svp = hv_fetch(hv, (const char*)tmpbuf, UNISKIP(uv1), FALSE)) && (*svp)) { const char *s; @@ -1648,7 +1641,7 @@ Perl_swash_fetch(pTHX_ SV *swash, const U8 *ptr, bool do_utf8) U32 bit; SV *swatch; U8 tmputf8[2]; - UV c = NATIVE_TO_ASCII(*ptr); + const UV c = NATIVE_TO_ASCII(*ptr); if (!do_utf8 && !UNI_IS_INVARIANT(c)) { tmputf8[0] = (U8)UTF8_EIGHT_BIT_HI(c); @@ -1810,7 +1803,7 @@ S_swash_get(pTHX_ SV* swash, UV start, UV span) l = (U8*)SvPV(*listsvp, lcur); lend = l + lcur; while (l < lend) { - UV min, max, val, key; + UV min, max, val; STRLEN numlen; I32 flags = PERL_SCAN_SILENT_ILLDIGIT | PERL_SCAN_DISALLOW_PREFIX; @@ -1883,6 +1876,7 @@ S_swash_get(pTHX_ SV* swash, UV start, UV span) continue; if (octets) { + UV key; if (min < start) { if (!none || val < none) { val += start - min; @@ -1913,6 +1907,7 @@ S_swash_get(pTHX_ SV* swash, UV start, UV span) } } else { /* bits == 1, then val should be ignored */ + UV key; if (min < start) min = start; for (key = min; key <= max; key++) { @@ -1938,7 +1933,7 @@ S_swash_get(pTHX_ SV* swash, UV start, UV span) U8 *s, *o, *nl; STRLEN slen, olen; - U8 opc = *x++; + const U8 opc = *x++; if (opc == '\n') continue; @@ -2008,7 +2003,7 @@ S_swash_get(pTHX_ SV* swash, UV start, UV span) else { STRLEN otheroctets = otherbits >> 3; STRLEN offset = 0; - U8* send = s + slen; + U8* const send = s + slen; while (s < send) { UV otherval = 0; diff --git a/util.c b/util.c index 407d86f..e4832de 100644 --- a/util.c +++ b/util.c @@ -341,16 +341,15 @@ Perl_delimcpy(pTHX_ register char *to, register const char *toend, register cons { register I32 tolen; PERL_UNUSED_CONTEXT; + for (tolen = 0; from < fromend; from++, tolen++) { if (*from == '\\') { - if (from[1] == delim) - from++; - else { + if (from[1] != delim) { if (to < toend) *to++ = *from; tolen++; - from++; } + from++; } else if (*from == delim) break; @@ -1536,6 +1535,7 @@ STRLEN * Perl_new_warnings_bitfield(pTHX_ STRLEN *buffer, const char *const bits, STRLEN size) { const MEM_SIZE len_wanted = sizeof(STRLEN) + size; + PERL_UNUSED_CONTEXT; buffer = specialWARN(buffer) ? PerlMemShared_malloc(len_wanted) : PerlMemShared_realloc(buffer, len_wanted); @@ -1577,7 +1577,9 @@ Perl_my_setenv(pTHX_ const char *nam, const char *val) I32 max; char **tmpenv; - for (max = i; environ[max]; max++) ; + max = i; + while (environ[max]) + max++; tmpenv = (char**)safesysmalloc((max+2) * sizeof(char*)); for (j=0; j= 0; i++) ; - return i ? 0 : -1; + while (PerlLIO_unlink(f) >= 0) + retries++; + return retries ? 0 : -1; } #endif @@ -4906,7 +4909,8 @@ Perl_parse_unicode_opts(pTHX_ const char **popt) if (*p) { if (isDIGIT(*p)) { opt = (U32) atoi(p); - while (isDIGIT(*p)) p++; + while (isDIGIT(*p)) + p++; if (*p && *p != '\n' && *p != '\r') Perl_croak(aTHX_ "Unknown Unicode option letter '%c'", *p); } @@ -5043,7 +5047,8 @@ Perl_get_hash_seed(pTHX) UV myseed = 0; if (s) - while (isSPACE(*s)) s++; + while (isSPACE(*s)) + s++; if (s && isDIGIT(*s)) myseed = (UV)Atoul(s); else