summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAndy Lester <andy@petdance.com>2005-05-28 19:19:06 -0500
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-05-30 07:45:09 +0000
commit5d7488b2fd9fa6515201f39bec25777d9fccd7db (patch)
treea657f5ce875a7991aff4b680574bdb785fc5f34a /ext
parent0b4b7f425bbb7f4f6f4a885d16efb0978cf3643f (diff)
downloadperl-5d7488b2fd9fa6515201f39bec25777d9fccd7db.tar.gz
[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 <andy@petdance.com> Date: Sun, 29 May 2005 11:23:50 -0500 Message-ID: <20050529162350.GA13965@petdance.com> Subject: [PATCH] consting attrs.xs From: Andy Lester <andy@petdance.com> Date: Sun, 29 May 2005 14:15:46 -0500 Message-ID: <20050529191546.GA15581@petdance.com> Subject: [PATCH] consting B.xs From: Andy Lester <andy@petdance.com> Date: Sun, 29 May 2005 15:09:24 -0500 Message-ID: <20050529200924.GA15873@petdance.com> p4raw-id: //depot/perl@24622
Diffstat (limited to 'ext')
-rw-r--r--ext/B/B.xs78
-rw-r--r--ext/Opcode/Opcode.xs65
-rw-r--r--ext/attrs/attrs.xs10
3 files changed, 73 insertions, 80 deletions
diff --git a/ext/B/B.xs b/ext/B/B.xs
index 782ba9fb96..c49e4d7cb6 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 78c7605331..62b4d059d8 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 73f100decc..e3ba012d69 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)