From 5d7488b2fd9fa6515201f39bec25777d9fccd7db Mon Sep 17 00:00:00 2001 From: Andy Lester Date: Sat, 28 May 2005 19:19:06 -0500 Subject: [PATCH] [PATCH] Minor warning squashings Date: Sun, 29 May 2005 00:19:06 -0500 Message-Id: <740ea3aca85400c6d03e945323badad4@petdance.com> Subject: [PATCH] Consting in Opcode.xs From: Andy Lester Date: Sun, 29 May 2005 11:23:50 -0500 Message-ID: <20050529162350.GA13965@petdance.com> Subject: [PATCH] consting attrs.xs From: Andy Lester Date: Sun, 29 May 2005 14:15:46 -0500 Message-ID: <20050529191546.GA15581@petdance.com> Subject: [PATCH] consting B.xs From: Andy Lester Date: Sun, 29 May 2005 15:09:24 -0500 Message-ID: <20050529200924.GA15873@petdance.com> p4raw-id: //depot/perl@24622 --- embed.fnc | 2 +- ext/B/B.xs | 78 +++++++++++++++++++++++++--------------------------- ext/Opcode/Opcode.xs | 65 +++++++++++++++++++++---------------------- ext/attrs/attrs.xs | 10 +++---- perlio.c | 1 + pp_sys.c | 2 ++ proto.h | 4 ++- regcomp.c | 11 +++++--- utf8.c | 6 ++-- 9 files changed, 90 insertions(+), 89 deletions(-) diff --git a/embed.fnc b/embed.fnc index 56232cd..b55b324 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1141,7 +1141,7 @@ s |SV* |method_common |SV* meth|U32* hashp #if defined(PERL_IN_PP_SYS_C) || defined(PERL_DECL_PROT) s |OP* |doform |CV *cv|GV *gv|OP *retop -s |int |emulate_eaccess|const char* path|Mode_t mode +sr |int |emulate_eaccess|const char* path|Mode_t mode # if !defined(HAS_MKDIR) || !defined(HAS_RMDIR) s |int |dooneliner |char *cmd|char *filename # endif diff --git a/ext/B/B.xs b/ext/B/B.xs index 782ba9f..c49e4d7 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -101,7 +101,7 @@ START_MY_CXT #define specialsv_list (MY_CXT.x_specialsv_list) static opclass -cc_opclass(pTHX_ OP *o) +cc_opclass(pTHX_ const OP *o) { if (!o) return OPc_NULL; @@ -209,7 +209,7 @@ cc_opclass(pTHX_ OP *o) } static char * -cc_opclassname(pTHX_ OP *o) +cc_opclassname(pTHX_ const OP *o) { return (char *)opclassnames[cc_opclass(aTHX_ o)]; } @@ -246,32 +246,28 @@ static SV * cstring(pTHX_ SV *sv, bool perlstyle) { SV *sstr = newSVpvn("", 0); - STRLEN len; - char *s; - char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */ if (!SvOK(sv)) sv_setpvn(sstr, "0", 1); - else if (perlstyle && SvUTF8(sv)) - { + else if (perlstyle && SvUTF8(sv)) { SV *tmpsv = sv_newmortal(); /* Temporary SV to feed sv_uni_display */ - len = SvCUR(sv); - s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ); + const STRLEN len = SvCUR(sv); + const char *s = sv_uni_display(tmpsv, sv, 8*len, UNI_DISPLAY_QQ); sv_setpvn(sstr,"\"",1); while (*s) { if (*s == '"') - sv_catpv(sstr, "\\\""); + sv_catpvn(sstr, "\\\"", 2); else if (*s == '$') - sv_catpv(sstr, "\\$"); + sv_catpvn(sstr, "\\$", 2); else if (*s == '@') - sv_catpv(sstr, "\\@"); + sv_catpvn(sstr, "\\@", 2); else if (*s == '\\') { if (strchr("nrftax\\",*(s+1))) sv_catpvn(sstr, s++, 2); else - sv_catpv(sstr, "\\\\"); + sv_catpvn(sstr, "\\\\", 2); } else /* should always be printable */ sv_catpvn(sstr, s, 1); @@ -283,7 +279,8 @@ cstring(pTHX_ SV *sv, bool perlstyle) else { /* XXX Optimise? */ - s = SvPV(sv, len); + STRLEN len; + const char *s = SvPV(sv, len); sv_catpv(sstr, "\""); for (; len; len--, s++) { @@ -293,8 +290,8 @@ cstring(pTHX_ SV *sv, bool perlstyle) else if (*s == '\\') sv_catpv(sstr, "\\\\"); /* trigraphs - bleagh */ - else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') - { + else if (!perlstyle && *s == '?' && len>=3 && s[1] == '?') { + char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */ sprintf(escbuff, "\\%03o", '?'); sv_catpv(sstr, escbuff); } @@ -325,7 +322,8 @@ cstring(pTHX_ SV *sv, bool perlstyle) else { /* Don't want promotion of a signed -1 char in sprintf args */ - unsigned char c = (unsigned char) *s; + char escbuff[5]; /* to fit backslash, 3 octals + trailing \0 */ + const unsigned char c = (unsigned char) *s; sprintf(escbuff, "\\%03o", c); sv_catpv(sstr, escbuff); } @@ -340,13 +338,12 @@ static SV * cchar(pTHX_ SV *sv) { SV *sstr = newSVpvn("'", 1); - STRLEN n_a; - char *s = SvPV(sv, n_a); + const char *s = SvPV_nolen(sv); if (*s == '\'') - sv_catpv(sstr, "\\'"); + sv_catpvn(sstr, "\\'", 2); else if (*s == '\\') - sv_catpv(sstr, "\\\\"); + sv_catpvn(sstr, "\\\\", 2); #ifdef EBCDIC else if (isPRINT(*s)) #else @@ -354,19 +351,19 @@ cchar(pTHX_ SV *sv) #endif /* EBCDIC */ sv_catpvn(sstr, s, 1); else if (*s == '\n') - sv_catpv(sstr, "\\n"); + sv_catpvn(sstr, "\\n", 2); else if (*s == '\r') - sv_catpv(sstr, "\\r"); + sv_catpvn(sstr, "\\r", 2); else if (*s == '\t') - sv_catpv(sstr, "\\t"); + sv_catpvn(sstr, "\\t", 2); else if (*s == '\a') - sv_catpv(sstr, "\\a"); + sv_catpvn(sstr, "\\a", 2); else if (*s == '\b') - sv_catpv(sstr, "\\b"); + sv_catpvn(sstr, "\\b", 2); else if (*s == '\f') - sv_catpv(sstr, "\\f"); + sv_catpvn(sstr, "\\f", 2); else if (*s == '\v') - sv_catpv(sstr, "\\v"); + sv_catpvn(sstr, "\\v", 2); else { /* no trigraph support */ @@ -376,12 +373,12 @@ cchar(pTHX_ SV *sv) sprintf(escbuff, "\\%03o", c); sv_catpv(sstr, escbuff); } - sv_catpv(sstr, "'"); + sv_catpvn(sstr, "'", 1); return sstr; } -void -walkoptree(pTHX_ SV *opsv, char *method) +static void +walkoptree(pTHX_ SV *opsv, const char *method) { dSP; OP *o, *kid; @@ -416,7 +413,7 @@ walkoptree(pTHX_ SV *opsv, char *method) } } -SV ** +static SV ** oplist(pTHX_ OP *o, SV **SP) { for(; o; o = o->op_next) { @@ -605,7 +602,7 @@ MODULE = B PACKAGE = B void walkoptree(opsv, method) SV * opsv - char * method + const char * method CODE: walkoptree(aTHX_ opsv, method); @@ -637,7 +634,7 @@ svref_2object(sv) void opnumber(name) -char * name +const char * name CODE: { int i; @@ -670,11 +667,10 @@ void hash(sv) SV * sv CODE: - char *s; STRLEN len; U32 hash = 0; char hexhash[19]; /* must fit "0xffffffffffffffff" plus trailing \0 */ - s = SvPV(sv, len); + const char *s = SvPV(sv, len); PERL_HASH(hash, s, len); sprintf(hexhash, "0x%"UVxf, (UV)hash); ST(0) = sv_2mortal(newSVpv(hexhash, 0)); @@ -724,7 +720,7 @@ threadsv_names() #if PERL_VERSION <= 8 # ifdef USE_5005THREADS int i; - STRLEN len = strlen(PL_threadsv_names); + const STRLEN len = strlen(PL_threadsv_names); EXTEND(sp, len); for (i = 0; i < len; i++) @@ -1011,8 +1007,8 @@ PVOP_pv(o) (o->op_private & OPpTRANS_COMPLEMENT) && !(o->op_private & OPpTRANS_DELETE)) { - short* tbl = (short*)o->op_pv; - short entries = 257 + tbl[256]; + const short* const tbl = (short*)o->op_pv; + const short entries = 257 + tbl[256]; ST(0) = sv_2mortal(newSVpv(o->op_pv, entries * sizeof(short))); } else if (o->op_type == OP_TRANS) { @@ -1158,7 +1154,7 @@ packiv(sv) CODE: if (sizeof(IV) == 8) { U32 wp[2]; - IV iv = SvIVX(sv); + const IV iv = SvIVX(sv); /* * The following way of spelling 32 is to stop compilers on * 32-bit architectures from moaning about the shift count @@ -1519,7 +1515,7 @@ IoSUBPROCESS(io) bool IsSTD(io,name) B::IO io - char* name + const char* name PREINIT: PerlIO* handle = 0; CODE: diff --git a/ext/Opcode/Opcode.xs b/ext/Opcode/Opcode.xs index 78c7605..62b4d05 100644 --- a/ext/Opcode/Opcode.xs +++ b/ext/Opcode/Opcode.xs @@ -25,9 +25,9 @@ START_MY_CXT static SV *new_opset (pTHX_ SV *old_opset); static int verify_opset (pTHX_ SV *opset, int fatal); -static void set_opset_bits (pTHX_ char *bitmap, SV *bitspec, int on, char *opname); -static void put_op_bitspec (pTHX_ char *optag, STRLEN len, SV *opset); -static SV *get_op_bitspec (pTHX_ char *opname, STRLEN len, int fatal); +static void set_opset_bits (pTHX_ char *bitmap, SV *bitspec, int on, const char *opname); +static void put_op_bitspec (pTHX_ const char *optag, STRLEN len, SV *opset); +static SV *get_op_bitspec (pTHX_ const char *opname, STRLEN len, int fatal); /* Initialise our private op_named_bits HV. @@ -50,8 +50,7 @@ op_names_init(pTHX) op_named_bits = newHV(); op_names = get_op_names(); for(i=0; i < PL_maxo; ++i) { - SV *sv; - sv = newSViv(i); + SV * const sv = newSViv(i); SvREADONLY_on(sv); hv_store(op_named_bits, op_names[i], strlen(op_names[i]), sv, 0); } @@ -75,7 +74,7 @@ op_names_init(pTHX) */ static void -put_op_bitspec(pTHX_ char *optag, STRLEN len, SV *mask) +put_op_bitspec(pTHX_ const char *optag, STRLEN len, SV *mask) { SV **svp; dMY_CXT; @@ -98,7 +97,7 @@ put_op_bitspec(pTHX_ char *optag, STRLEN len, SV *mask) */ static SV * -get_op_bitspec(pTHX_ char *opname, STRLEN len, int fatal) +get_op_bitspec(pTHX_ const char *opname, STRLEN len, int fatal) { SV **svp; dMY_CXT; @@ -146,7 +145,7 @@ new_opset(pTHX_ SV *old_opset) static int verify_opset(pTHX_ SV *opset, int fatal) { - char *err = Nullch; + const char *err = Nullch; dMY_CXT; if (!SvOK(opset)) err = "undefined"; @@ -160,14 +159,14 @@ verify_opset(pTHX_ SV *opset, int fatal) static void -set_opset_bits(pTHX_ char *bitmap, SV *bitspec, int on, char *opname) +set_opset_bits(pTHX_ char *bitmap, SV *bitspec, int on, const char *opname) { dMY_CXT; if (SvIOK(bitspec)) { - int myopcode = SvIV(bitspec); - int offset = myopcode >> 3; - int bit = myopcode & 0x07; + const int myopcode = SvIV(bitspec); + const int offset = myopcode >> 3; + const int bit = myopcode & 0x07; if (myopcode >= PL_maxo || myopcode < 0) croak("panic: opcode \"%s\" value %d is invalid", opname, myopcode); if (opcode_debug >= 2) @@ -181,7 +180,7 @@ set_opset_bits(pTHX_ char *bitmap, SV *bitspec, int on, char *opname) else if (SvPOK(bitspec) && SvCUR(bitspec) == (STRLEN)opset_len) { STRLEN len; - char *specbits = SvPV(bitspec, len); + const char * const specbits = SvPV(bitspec, len); if (opcode_debug >= 2) warn("set_opset_bits opset %s %s\n", opname, (on)?"on":"off"); if (on) @@ -213,7 +212,7 @@ opmask_add(pTHX_ SV *opset) /* THE ONLY FUNCTION TO EDIT PL_op_mask ITSELF */ bitmask = SvPV(opset, len); for (i=0; i < opset_len; i++) { - U16 bits = bitmask[i]; + const U16 bits = bitmask[i]; if (!bits) { /* optimise for sparse masks */ myopcode += 8; continue; @@ -261,7 +260,7 @@ BOOT: void _safe_pkg_prep(Package) - char * Package + const char *Package PPCODE: HV *hv; ENTER; @@ -359,13 +358,13 @@ PPCODE: { STRLEN len; int i, j, myopcode; - char *bitmap = SvPV(opset, len); + const char * const bitmap = SvPV(opset, len); char **names = (desc) ? get_op_descs() : get_op_names(); dMY_CXT; verify_opset(aTHX_ opset,1); for (myopcode=0, i=0; i < opset_len; i++) { - U16 bits = bitmap[i]; + const U16 bits = bitmap[i]; for (j=0; j < 8 && myopcode < PL_maxo; j++, myopcode++) { if ( bits & (1 << j) ) XPUSHs(sv_2mortal(newSVpv(names[myopcode], 0))); @@ -378,14 +377,13 @@ void opset(...) CODE: int i; - SV *bitspec, *opset; - char *bitmap; + SV *bitspec; STRLEN len, on; - opset = sv_2mortal(new_opset(aTHX_ Nullsv)); - bitmap = SvPVX(opset); + SV * const opset = sv_2mortal(new_opset(aTHX_ Nullsv)); + char * const bitmap = SvPVX(opset); for (i = 0; i < items; i++) { - char *opname; + const char *opname; on = 1; if (verify_opset(aTHX_ ST(i),0)) { opname = "(opset)"; @@ -412,9 +410,9 @@ ALIAS: deny_only = 2 deny = 3 CODE: - int i, on; + int i; SV *bitspec, *mask; - char *bitmap, *opname; + char *bitmap; STRLEN len; dMY_CXT; @@ -427,7 +425,8 @@ CODE: verify_opset(aTHX_ mask,1); /* croaks */ bitmap = SvPVX(mask); for (i = 1; i < items; i++) { - on = PERMITING ? 0 : 1; /* deny = mask bit on */ + const char *opname; + int on = PERMITING ? 0 : 1; /* deny = mask bit on */ if (verify_opset(aTHX_ ST(i),0)) { /* it's a valid mask */ opname = "(opset)"; bitspec = ST(i); @@ -447,7 +446,7 @@ CODE: void opdesc(...) PPCODE: - int i, myopcode; + int i; STRLEN len; SV **args; char **op_desc = get_op_descs(); @@ -457,10 +456,10 @@ PPCODE: /* the stack faster than we read values off it if masks are used. */ args = (SV**)SvPVX(sv_2mortal(newSVpvn((char*)&ST(0), items*sizeof(SV*)))); for (i = 0; i < items; i++) { - char *opname = SvPV(args[i], len); + const char * const opname = SvPV(args[i], len); SV *bitspec = get_op_bitspec(aTHX_ opname, len, 1); if (SvIOK(bitspec)) { - myopcode = SvIV(bitspec); + const int myopcode = SvIV(bitspec); if (myopcode < 0 || myopcode >= PL_maxo) croak("panic: opcode %d (%s) out of range",myopcode,opname); XPUSHs(sv_2mortal(newSVpv(op_desc[myopcode], 0))); @@ -468,10 +467,10 @@ PPCODE: else if (SvPOK(bitspec) && SvCUR(bitspec) == (STRLEN)opset_len) { int b, j; STRLEN n_a; - char *bitmap = SvPV(bitspec,n_a); - myopcode = 0; + const char * const bitmap = SvPV(bitspec,n_a); + int myopcode = 0; for (b=0; b < opset_len; b++) { - U16 bits = bitmap[b]; + const U16 bits = bitmap[b]; for (j=0; j < 8 && myopcode < PL_maxo; j++, myopcode++) if (bits & (1 << j)) XPUSHs(sv_2mortal(newSVpv(op_desc[myopcode], 0))); @@ -489,7 +488,7 @@ define_optag(optagsv, mask) SV *mask CODE: STRLEN len; - char *optag = SvPV(optagsv, len); + const char *optag = SvPV(optagsv, len); put_op_bitspec(aTHX_ optag, len, mask); /* croaks */ ST(0) = &PL_sv_yes; @@ -530,7 +529,7 @@ opmask() CODE: ST(0) = sv_2mortal(new_opset(aTHX_ Nullsv)); if (PL_op_mask) { - char *bitmap = SvPVX(ST(0)); + char * const bitmap = SvPVX(ST(0)); int myopcode; for(myopcode=0; myopcode < PL_maxo; ++myopcode) { if (PL_op_mask[myopcode]) diff --git a/ext/attrs/attrs.xs b/ext/attrs/attrs.xs index 73f100d..e3ba012 100644 --- a/ext/attrs/attrs.xs +++ b/ext/attrs/attrs.xs @@ -4,7 +4,7 @@ #include "XSUB.h" static cv_flags_t -get_flag(char *attr) +get_flag(const char *attr) { if (strnEQ(attr, "method", 6)) return CVf_METHOD; @@ -32,9 +32,8 @@ import(...) "pragma \"attrs\" is deprecated, " "use \"sub NAME : ATTRS\" instead"); for (i = 1; i < items; i++) { - STRLEN n_a; - char *attr = SvPV(ST(i), n_a); - cv_flags_t flag = get_flag(attr); + const char * const attr = SvPV_nolen(ST(i)); + const cv_flags_t flag = get_flag(attr); if (!flag) croak("invalid attribute name %s", attr); if (ix) @@ -53,8 +52,7 @@ SV * sub sub = Nullsv; } else { - STRLEN n_a; - char *name = SvPV(sub, n_a); + const char * const name = SvPV_nolen(sub); sub = (SV*)perl_get_cv(name, FALSE); } if (!sub) diff --git a/perlio.c b/perlio.c index 5415db3..c52458e 100644 --- a/perlio.c +++ b/perlio.c @@ -2946,6 +2946,7 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE *f) */ # error "Don't know how to set FILE.fileno on your platform" #endif + (void)f; return 0; # endif } diff --git a/pp_sys.c b/pp_sys.c index 542eca2..25acd78 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -309,6 +309,8 @@ S_emulate_eaccess(pTHX_ const char* path, Mode_t mode) STATIC int S_emulate_eaccess(pTHX_ const char* path, Mode_t mode) { + (void)path; + (void)mode; Perl_croak(aTHX_ "switching effective uid is not implemented"); /*NOTREACHED*/ return -1; diff --git a/proto.h b/proto.h index b2436b1..c52d760 100644 --- a/proto.h +++ b/proto.h @@ -2159,7 +2159,9 @@ STATIC SV* S_method_common(pTHX_ SV* meth, U32* hashp); #if defined(PERL_IN_PP_SYS_C) || defined(PERL_DECL_PROT) STATIC OP* S_doform(pTHX_ CV *cv, GV *gv, OP *retop); -STATIC int S_emulate_eaccess(pTHX_ const char* path, Mode_t mode); +STATIC int S_emulate_eaccess(pTHX_ const char* path, Mode_t mode) + __attribute__noreturn__; + # if !defined(HAS_MKDIR) || !defined(HAS_RMDIR) STATIC int S_dooneliner(pTHX_ char *cmd, char *filename); # endif diff --git a/regcomp.c b/regcomp.c index 6f1b2b6..e600885 100644 --- a/regcomp.c +++ b/regcomp.c @@ -935,7 +935,7 @@ S_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch, regnode *firs DEBUG_TRIE_COMPILE_r( PerlIO_printf( Perl_debug_log, "TRIE(%s): W:%d C:%d Uq:%d \n", ( trie->widecharmap ? "UTF8" : "NATIVE" ), trie->wordcount, - trie->charcount, trie->uniquecharcount ) + (int)trie->charcount, trie->uniquecharcount ) ); @@ -1414,7 +1414,9 @@ S_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch, regnode *firs DEBUG_TRIE_COMPILE_MORE_r( PerlIO_printf( Perl_debug_log, " Alloc: %d Orig: %"IVdf" elements, Final:%"IVdf". Savings of %%%5.2f\n", - ( ( trie->charcount + 1 ) * trie->uniquecharcount + 1 ), (IV)next_alloc, (IV)pos, + (int)( ( trie->charcount + 1 ) * trie->uniquecharcount + 1 ), + (IV)next_alloc, + (IV)pos, ( ( next_alloc - pos ) * 100 ) / (double)next_alloc ); ); @@ -5717,9 +5719,10 @@ S_dumpuntil(pTHX_ regnode *start, regnode *node, regnode *last, SV* sv, I32 l) I32 word_idx; PerlIO_printf(Perl_debug_log, "%*s[Words:%d Chars Stored:%d Unique Chars:%d States:%"IVdf"%s]\n", - (int)(2*(l+3)), "", + (int)(2*(l+3)), + "", trie->wordcount, - trie->charcount, + (int)trie->charcount, trie->uniquecharcount, (IV)trie->laststate-1, node->flags ? " EVAL mode" : ""); diff --git a/utf8.c b/utf8.c index 02e202d..be75891 100644 --- a/utf8.c +++ b/utf8.c @@ -490,7 +490,7 @@ malformed: (UV)s[1], startbyte); else Perl_sv_catpvf(aTHX_ sv, "(unexpected non-continuation byte 0x%02"UVxf", %d byte%s after start byte 0x%02"UVxf", expected %d bytes)", - (UV)s[1], s - s0, s - s0 > 1 ? "s" : "", startbyte, expectlen); + (UV)s[1], s - s0, s - s0 > 1 ? "s" : "", startbyte, (int)expectlen); break; case UTF8_WARN_FE_FF: @@ -498,7 +498,7 @@ malformed: break; case UTF8_WARN_SHORT: Perl_sv_catpvf(aTHX_ sv, "(%d byte%s, need %d, after start byte 0x%02"UVxf")", - curlen, curlen == 1 ? "" : "s", expectlen, startbyte); + (int)curlen, curlen == 1 ? "" : "s", (int)expectlen, startbyte); expectlen = curlen; /* distance for caller to skip */ break; case UTF8_WARN_OVERFLOW: @@ -510,7 +510,7 @@ malformed: break; case UTF8_WARN_LONG: Perl_sv_catpvf(aTHX_ sv, "(%d byte%s, need %d, after start byte 0x%02"UVxf")", - expectlen, expectlen == 1 ? "": "s", UNISKIP(uv), startbyte); + (int)expectlen, expectlen == 1 ? "": "s", UNISKIP(uv), startbyte); break; case UTF8_WARN_FFFF: Perl_sv_catpvf(aTHX_ sv, "(character 0x%04"UVxf")", uv); -- 2.7.4