From: Andy Lester Date: Sun, 13 Mar 2005 14:20:05 +0000 (-0600) Subject: Adding const qualifiers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=35a4481cfdbca4941ab3a4206dc266f3e71c2385;p=p5sagit%2Fp5-mst-13.2.git Adding const qualifiers Message-ID: <20050313202005.GA23535@petdance.com> p4raw-id: //depot/perl@24037 --- diff --git a/av.c b/av.c index b616a20..df2cf23 100644 --- a/av.c +++ b/av.c @@ -193,7 +193,7 @@ Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval) return 0; if (SvRMAGICAL(av)) { - MAGIC *tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); + const MAGIC * const tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); if (tied_magic || mg_find((SV*)av, PERL_MAGIC_regdata)) { U32 adjust_index = 1; @@ -281,7 +281,7 @@ Perl_av_store(pTHX_ register AV *av, I32 key, SV *val) val = &PL_sv_undef; if (SvRMAGICAL(av)) { - MAGIC *tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); + const MAGIC * const tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); if (tied_magic) { /* Handle negative array indices 20020222 MJD */ if (key < 0) { @@ -723,7 +723,7 @@ empty. */ I32 -Perl_av_len(pTHX_ register AV *av) +Perl_av_len(pTHX_ const register AV *av) { return AvFILL(av); } @@ -803,10 +803,10 @@ Perl_av_delete(pTHX_ AV *av, I32 key, I32 flags) Perl_croak(aTHX_ PL_no_modify); if (SvRMAGICAL(av)) { - MAGIC *tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); - SV **svp; + const MAGIC * const tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); if ((tied_magic || mg_find((SV*)av, PERL_MAGIC_regdata))) { /* Handle negative array indices 20020222 MJD */ + SV **svp; if (key < 0) { unsigned adjust_index = 1; if (tied_magic) { @@ -887,7 +887,7 @@ Perl_av_exists(pTHX_ AV *av, I32 key) if (SvRMAGICAL(av)) { - MAGIC *tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); + const MAGIC * const tied_magic = mg_find((SV*)av, PERL_MAGIC_tied); if (tied_magic || mg_find((SV*)av, PERL_MAGIC_regdata)) { SV *sv = sv_newmortal(); MAGIC *mg; diff --git a/embed.fnc b/embed.fnc index fc400ee..3658881 100644 --- a/embed.fnc +++ b/embed.fnc @@ -90,7 +90,7 @@ Apd |void |av_extend |AV* ar|I32 key p |AV* |av_fake |I32 size|SV** svp Apd |SV** |av_fetch |AV* ar|I32 key|I32 lval Apd |void |av_fill |AV* ar|I32 fill -Apd |I32 |av_len |AV* ar +Apd |I32 |av_len |const AV* ar Apd |AV* |av_make |I32 size|SV** svp Apd |SV* |av_pop |AV* ar Apd |void |av_push |AV* ar|SV* val @@ -134,7 +134,7 @@ Afnp |void |sv_setpvf_mg_nocontext|SV* sv|const char* pat|... Afnp |int |fprintf_nocontext|PerlIO* stream|const char* fmt|... Afnp |int |printf_nocontext|const char* fmt|... #endif -p |void |cv_ckproto |CV* cv|GV* gv|char* p +p |void |cv_ckproto |const CV* cv|const GV* gv|const char* p pd |CV* |cv_clone |CV* proto Apd |SV* |cv_const_sv |CV* cv p |SV* |op_const_sv |OP* o|CV* cv @@ -161,7 +161,7 @@ p |void |deprecate |char* s p |void |deprecate_old |char* s Afp |OP* |die |const char* pat|... p |OP* |vdie |const char* pat|va_list* args -p |OP* |die_where |char* message|STRLEN msglen +p |OP* |die_where |const char* message|STRLEN msglen Ap |void |dounwind |I32 cxix p |bool |do_aexec |SV* really|SV** mark|SV** sp p |bool |do_aexec5 |SV* really|SV** mark|SV** sp|int fd|int flag @@ -244,9 +244,9 @@ Ap |GV* |gv_IOadd |GV* gv Ap |GV* |gv_autoload4 |HV* stash|const char* name|STRLEN len \ |I32 method Ap |void |gv_check |HV* stash -Ap |void |gv_efullname |SV* sv|GV* gv -Amb |void |gv_efullname3 |SV* sv|GV* gv|const char* prefix -Ap |void |gv_efullname4 |SV* sv|GV* gv|const char* prefix|bool keepmain +Ap |void |gv_efullname |SV* sv|const GV* gv +Amb |void |gv_efullname3 |SV* sv|const GV* gv|const char* prefix +Ap |void |gv_efullname4 |SV* sv|const GV* gv|const char* prefix|bool keepmain Ap |GV* |gv_fetchfile |const char* name Apd |GV* |gv_fetchmeth |HV* stash|const char* name|STRLEN len \ |I32 level @@ -256,9 +256,9 @@ Apd |GV* |gv_fetchmethod |HV* stash|const char* name Apd |GV* |gv_fetchmethod_autoload|HV* stash|const char* name \ |I32 autoload Ap |GV* |gv_fetchpv |const char* name|I32 add|I32 sv_type -Ap |void |gv_fullname |SV* sv|GV* gv -Amb |void |gv_fullname3 |SV* sv|GV* gv|const char* prefix -Ap |void |gv_fullname4 |SV* sv|GV* gv|const char* prefix|bool keepmain +Ap |void |gv_fullname |SV* sv|const GV* gv +Amb |void |gv_fullname3 |SV* sv|const GV* gv|const char* prefix +Ap |void |gv_fullname4 |SV* sv|const GV* gv|const char* prefix|bool keepmain Ap |void |gv_init |GV* gv|HV* stash|const char* name \ |STRLEN len|int multi Apd |HV* |gv_stashpv |const char* name|I32 create @@ -439,7 +439,7 @@ p |void |qerror |SV* err Apd |void |sortsv |SV ** array|size_t num_elts|SVCOMPARE_t cmp Apd |int |mg_clear |SV* sv Apd |int |mg_copy |SV* sv|SV* nsv|const char* key|I32 klen -Apd |MAGIC* |mg_find |SV* sv|int type +Apd |MAGIC* |mg_find |const SV* sv|int type Apd |int |mg_free |SV* sv Apd |int |mg_get |SV* sv Apd |U32 |mg_length |SV* sv @@ -637,7 +637,7 @@ Apd |char* |savesharedpv |const char* pv Apd |char* |savepvn |const char* pv|I32 len Ap |void |savestack_grow Ap |void |savestack_grow_cnt |I32 need -Ap |void |save_aelem |AV* av|I32 idx|SV **sptr +Ap |void |save_aelem |const AV* av|I32 idx|SV **sptr Ap |I32 |save_alloc |I32 size|I32 pad Ap |void |save_aptr |AV** aptr Ap |AV* |save_ary |GV* gv @@ -654,7 +654,7 @@ Ap |void |save_generic_pvref|char** str Ap |void |save_shared_pvref|char** str Ap |void |save_gp |GV* gv|I32 empty Ap |HV* |save_hash |GV* gv -Ap |void |save_helem |HV* hv|SV *key|SV **sptr +Ap |void |save_helem |const HV* hv|SV *key|SV **sptr Ap |void |save_hints Ap |void |save_hptr |HV** hptr Ap |void |save_I16 |I16* intp @@ -824,12 +824,12 @@ p |void |unshare_hek |HEK* hek p |void |utilize |int aver|I32 floor|OP* version|OP* idop|OP* arg Ap |U8* |utf16_to_utf8 |U8* p|U8 *d|I32 bytelen|I32 *newlen Ap |U8* |utf16_to_utf8_reversed|U8* p|U8 *d|I32 bytelen|I32 *newlen -Adp |STRLEN |utf8_length |U8* s|U8 *e -Apd |IV |utf8_distance |U8 *a|U8 *b +Adp |STRLEN |utf8_length |const U8* s|const U8 *e +Apd |IV |utf8_distance |const U8 *a|const U8 *b Apd |U8* |utf8_hop |U8 *s|I32 off ApMd |U8* |utf8_to_bytes |U8 *s|STRLEN *len ApMd |U8* |bytes_from_utf8|U8 *s|STRLEN *len|bool *is_utf8 -ApMd |U8* |bytes_to_utf8 |U8 *s|STRLEN *len +ApMd |U8* |bytes_to_utf8 |const U8 *s|STRLEN *len Apd |UV |utf8_to_uvchr |U8 *s|STRLEN* retlen Apd |UV |utf8_to_uvuni |U8 *s|STRLEN* retlen Adp |UV |utf8n_to_uvchr |U8 *s|STRLEN curlen|STRLEN* retlen|U32 flags @@ -854,7 +854,7 @@ Ap |void |vwarn |const char* pat|va_list* args Afp |void |warner |U32 err|const char* pat|... Ap |void |vwarner |U32 err|const char* pat|va_list* args p |void |watch |char** addr -Ap |I32 |whichsig |char* sig +Ap |I32 |whichsig |const char* sig p |void |write_to_stderr|const char* message|int msglen p |int |yyerror |char* s p |int |yylex diff --git a/gv.c b/gv.c index 83ec0ee..3ff4176 100644 --- a/gv.c +++ b/gv.c @@ -1102,7 +1102,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags, break; case '\026': /* $^V */ { - SV *sv = GvSV(gv); + SV * const sv = GvSV(gv); GvSV(gv) = new_version(PL_patchlevel); SvREADONLY_on(GvSV(gv)); SvREFCNT_dec(sv); @@ -1114,10 +1114,10 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags, } void -Perl_gv_fullname4(pTHX_ SV *sv, GV *gv, const char *prefix, bool keepmain) +Perl_gv_fullname4(pTHX_ SV *sv, const GV *gv, const char *prefix, bool keepmain) { - char *name; - HV *hv = GvSTASH(gv); + const char *name; + const HV * const hv = GvSTASH(gv); if (!hv) { SvOK_off(sv); return; @@ -1136,36 +1136,36 @@ Perl_gv_fullname4(pTHX_ SV *sv, GV *gv, const char *prefix, bool keepmain) } void -Perl_gv_fullname3(pTHX_ SV *sv, GV *gv, const char *prefix) +Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix) { gv_fullname4(sv, gv, prefix, TRUE); } void -Perl_gv_efullname4(pTHX_ SV *sv, GV *gv, const char *prefix, bool keepmain) +Perl_gv_efullname4(pTHX_ SV *sv, const GV *gv, const char *prefix, bool keepmain) { - GV *egv = GvEGV(gv); + const GV *egv = GvEGV(gv); if (!egv) egv = gv; gv_fullname4(sv, egv, prefix, keepmain); } void -Perl_gv_efullname3(pTHX_ SV *sv, GV *gv, const char *prefix) +Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix) { gv_efullname4(sv, gv, prefix, TRUE); } -/* XXX compatibility with versions <= 5.003. */ +/* compatibility with versions <= 5.003. */ void -Perl_gv_fullname(pTHX_ SV *sv, GV *gv) +Perl_gv_fullname(pTHX_ SV *sv, const GV *gv) { - gv_fullname3(sv, gv, sv == (SV*)gv ? "*" : ""); + gv_fullname3(sv, gv, sv == (const SV*)gv ? "*" : ""); } -/* XXX compatibility with versions <= 5.003. */ +/* compatibility with versions <= 5.003. */ void -Perl_gv_efullname(pTHX_ SV *sv, GV *gv) +Perl_gv_efullname(pTHX_ SV *sv, const GV *gv) { gv_efullname3(sv, gv, sv == (SV*)gv ? "*" : ""); } diff --git a/hv.c b/hv.c index bb8cef6..58fd5fc 100644 --- a/hv.c +++ b/hv.c @@ -90,7 +90,7 @@ S_more_he(pTHX) STATIC HEK * S_save_hek_flags(pTHX_ const char *str, I32 len, U32 hash, int flags) { - int flags_masked = flags & HVhek_MASK; + const int flags_masked = flags & HVhek_MASK; char *k; register HEK *hek; @@ -1999,7 +1999,7 @@ S_unshare_hek_or_pvn(pTHX_ HEK *hek, const char *str, I32 len, U32 hash) break; } } else { - int flags_masked = k_flags & HVhek_MASK; + const int flags_masked = k_flags & HVhek_MASK; for (entry = *oentry; entry; i=0, oentry = &HeNEXT(entry), entry = *oentry) { if (HeHASH(entry) != hash) /* strings can't be equal */ continue; @@ -2075,7 +2075,7 @@ S_share_hek_flags(pTHX_ const char *str, I32 len, register U32 hash, int flags) register HE **oentry; register I32 i = 1; I32 found = 0; - int flags_masked = flags & HVhek_MASK; + const int flags_masked = flags & HVhek_MASK; /* what follows is the moral equivalent of: diff --git a/mg.c b/mg.c index c24bf6d..6cd1c6f 100644 --- a/mg.c +++ b/mg.c @@ -63,8 +63,8 @@ Signal_t Perl_csighandler(int sig); # define FAKE_DEFAULT_SIGNAL_HANDLERS #endif -static void restore_magic(pTHX_ void *p); -static void unwind_handler_stack(pTHX_ void *p); +static void restore_magic(pTHX_ const void *p); +static void unwind_handler_stack(pTHX_ const void *p); #ifdef __Lynx__ /* Missing protos on LynxOS */ @@ -121,7 +121,7 @@ Perl_mg_magical(pTHX_ SV *sv) { MAGIC* mg; for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { - MGVTBL* vtbl = mg->mg_virtual; + const MGVTBL* const vtbl = mg->mg_virtual; if (vtbl) { if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP)) SvGMAGICAL_on(sv); @@ -144,10 +144,10 @@ Do magic after a value is retrieved from the SV. See C. int Perl_mg_get(pTHX_ SV *sv) { + const I32 mgs_ix = SSNEW(sizeof(MGS)); + const bool was_temp = SvTEMP(sv); int new = 0; MAGIC *newmg, *head, *cur, *mg; - I32 mgs_ix = SSNEW(sizeof(MGS)); - int was_temp = SvTEMP(sv); /* guard against sv having being freed midway by holding a private reference. */ @@ -168,7 +168,7 @@ Perl_mg_get(pTHX_ SV *sv) newmg = cur = head = mg = SvMAGIC(sv); while (mg) { - MGVTBL *vtbl = mg->mg_virtual; + const MGVTBL * const vtbl = mg->mg_virtual; if (!(mg->mg_flags & MGf_GSKIP) && vtbl && vtbl->svt_get) { CALL_FPTR(vtbl->svt_get)(aTHX_ sv, mg); @@ -224,11 +224,10 @@ Do magic after a value is assigned to the SV. See C. int Perl_mg_set(pTHX_ SV *sv) { - I32 mgs_ix; + const I32 mgs_ix = SSNEW(sizeof(MGS)); MAGIC* mg; MAGIC* nextmg; - mgs_ix = SSNEW(sizeof(MGS)); save_magic(mgs_ix, sv); for (mg = SvMAGIC(sv); mg; mg = nextmg) { @@ -261,11 +260,9 @@ Perl_mg_length(pTHX_ SV *sv) STRLEN len; for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { - MGVTBL* vtbl = mg->mg_virtual; + const MGVTBL * const vtbl = mg->mg_virtual; if (vtbl && vtbl->svt_len) { - I32 mgs_ix; - - mgs_ix = SSNEW(sizeof(MGS)); + const I32 mgs_ix = SSNEW(sizeof(MGS)); save_magic(mgs_ix, sv); /* omit MGf_GSKIP -- not changed here */ len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg); @@ -274,8 +271,7 @@ Perl_mg_length(pTHX_ SV *sv) } } - if (DO_UTF8(sv)) - { + if (DO_UTF8(sv)) { U8 *s = (U8*)SvPV(sv, len); len = Perl_utf8_length(aTHX_ s, s + len); } @@ -288,14 +284,12 @@ I32 Perl_mg_size(pTHX_ SV *sv) { MAGIC* mg; - I32 len; for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { - MGVTBL* vtbl = mg->mg_virtual; + const MGVTBL* const vtbl = mg->mg_virtual; if (vtbl && vtbl->svt_len) { - I32 mgs_ix; - - mgs_ix = SSNEW(sizeof(MGS)); + const I32 mgs_ix = SSNEW(sizeof(MGS)); + I32 len; save_magic(mgs_ix, sv); /* omit MGf_GSKIP -- not changed here */ len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg); @@ -306,8 +300,7 @@ Perl_mg_size(pTHX_ SV *sv) switch(SvTYPE(sv)) { case SVt_PVAV: - len = AvFILLp((AV *) sv); /* Fallback to non-tied array */ - return len; + return AvFILLp((AV *) sv); /* Fallback to non-tied array */ case SVt_PVHV: /* FIXME */ default: @@ -328,14 +321,13 @@ Clear something magical that the SV represents. See C. int Perl_mg_clear(pTHX_ SV *sv) { - I32 mgs_ix; + const I32 mgs_ix = SSNEW(sizeof(MGS)); MAGIC* mg; - mgs_ix = SSNEW(sizeof(MGS)); save_magic(mgs_ix, sv); for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { - MGVTBL* vtbl = mg->mg_virtual; + const MGVTBL* const vtbl = mg->mg_virtual; /* omit GSKIP -- never set here */ if (vtbl && vtbl->svt_clear) @@ -355,14 +347,14 @@ Finds the magic pointer for type matching the SV. See C. */ MAGIC* -Perl_mg_find(pTHX_ SV *sv, int type) +Perl_mg_find(pTHX_ const SV *sv, int type) { - MAGIC* mg; - if (!sv) - return 0; - for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { - if (mg->mg_type == type) - return mg; + if (sv) { + MAGIC *mg; + for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { + if (mg->mg_type == type) + return mg; + } } return 0; } @@ -381,7 +373,7 @@ Perl_mg_copy(pTHX_ SV *sv, SV *nsv, const char *key, I32 klen) int count = 0; MAGIC* mg; for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { - MGVTBL* vtbl = mg->mg_virtual; + const MGVTBL* const vtbl = mg->mg_virtual; if ((mg->mg_flags & MGf_COPY) && vtbl->svt_copy){ count += CALL_FPTR(vtbl->svt_copy)(aTHX_ sv, mg, nsv, key, klen); } @@ -411,7 +403,7 @@ Perl_mg_free(pTHX_ SV *sv) MAGIC* mg; MAGIC* moremagic; for (mg = SvMAGIC(sv); mg; mg = moremagic) { - MGVTBL* vtbl = mg->mg_virtual; + const MGVTBL* const vtbl = mg->mg_virtual; moremagic = mg->mg_moremagic; if (vtbl && vtbl->svt_free) CALL_FPTR(vtbl->svt_free)(aTHX_ sv, mg); @@ -434,7 +426,7 @@ Perl_mg_free(pTHX_ SV *sv) U32 Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg) { - register REGEXP *rx; + register const REGEXP *rx; if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { if (mg->mg_obj) /* @+ */ @@ -449,20 +441,19 @@ Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg) int Perl_magic_regdatum_get(pTHX_ SV *sv, MAGIC *mg) { - register I32 paren; - register I32 s; - register I32 i; register REGEXP *rx; - I32 t; if (PL_curpm && (rx = PM_GETRE(PL_curpm))) { - paren = mg->mg_len; + register const I32 paren = mg->mg_len; + register I32 s; + register I32 t; if (paren < 0) return 0; if (paren <= (I32)rx->nparens && (s = rx->startp[paren]) != -1 && (t = rx->endp[paren]) != -1) { + register I32 i; if (mg->mg_obj) /* @+ */ i = t; else /* @- */ @@ -1159,10 +1150,9 @@ Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg) /* XXX Some of this code was copied from Perl_magic_setsig. A little * refactoring might be in order. */ - register char *s; STRLEN n_a; SV* to_dec; - s = MgPV(mg,n_a); + register const char *s = MgPV(mg,n_a); if (*s == '_') { SV** svp; if (strEQ(s,"__DIE__")) @@ -1298,7 +1288,6 @@ Perl_despatch_signals(pTHX) int Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg) { - register char *s; I32 i; SV** svp = 0; /* Need to be careful with SvREFCNT_dec(), because that can have side @@ -1312,7 +1301,7 @@ Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg) SV* save_sv; #endif - s = MgPV(mg,len); + register const char *s = MgPV(mg,len); if (*s == '_') { if (strEQ(s,"__DIE__")) svp = &PL_diehook; @@ -1578,7 +1567,7 @@ int Perl_magic_nextpack(pTHX_ SV *sv, MAGIC *mg, SV *key) { dSP; - const char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY"; + const char * const meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY"; ENTER; SAVETMPS; @@ -1781,8 +1770,8 @@ int Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg) { STRLEN len; - SV *lsv = LvTARG(sv); - char *tmps = SvPV(lsv,len); + SV * const lsv = LvTARG(sv); + const char * const tmps = SvPV(lsv,len); I32 offs = LvTARGOFF(sv); I32 rem = LvTARGLEN(sv); @@ -1857,7 +1846,7 @@ Perl_magic_settaint(pTHX_ SV *sv, MAGIC *mg) int Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg) { - SV *lsv = LvTARG(sv); + SV * const lsv = LvTARG(sv); if (!lsv) { SvOK_off(sv); @@ -2004,7 +1993,7 @@ Perl_magic_setfm(pTHX_ SV *sv, MAGIC *mg) int Perl_magic_setuvar(pTHX_ SV *sv, MAGIC *mg) { - struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr; + const struct ufuncs * const uf = (struct ufuncs *)mg->mg_ptr; if (uf && uf->uf_set) (*uf->uf_set)(aTHX_ uf->uf_index, sv); @@ -2172,7 +2161,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) STRLEN len, i; int accumulate = 0 ; int any_fatals = 0 ; - char * ptr = (char*)SvPV(sv, len) ; + const char * const ptr = (char*)SvPV(sv, len) ; for (i = 0 ; i < len ; ++i) { accumulate |= ptr[i] ; any_fatals |= (ptr[i] & 0xAA) ; @@ -2389,7 +2378,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) case ')': #ifdef HAS_SETGROUPS { - char *p = SvPV(sv, len); + const char *p = SvPV(sv, len); Groups_t gary[NGROUPS]; while (isSPACE(*p)) @@ -2503,7 +2492,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) } I32 -Perl_whichsig(pTHX_ char *sig) +Perl_whichsig(pTHX_ const char *sig) { register char **sigv; @@ -2636,7 +2625,7 @@ cleanup: static void -restore_magic(pTHX_ void *p) +restore_magic(pTHX_ const void *p) { MGS* mgs = SSPTR(PTR2IV(p), MGS*); SV* sv = mgs->mgs_sv; @@ -2684,9 +2673,9 @@ restore_magic(pTHX_ void *p) } static void -unwind_handler_stack(pTHX_ void *p) +unwind_handler_stack(pTHX_ const void *p) { - U32 flags = *(U32*)p; + const U32 flags = *(U32*)p; if (flags & 1) PL_savestack_ix -= 5; /* Unprotect save in progress. */ diff --git a/op.c b/op.c index 77a213e..6631fe3 100644 --- a/op.c +++ b/op.c @@ -4031,7 +4031,7 @@ Perl_cv_undef(pTHX_ CV *cv) } void -Perl_cv_ckproto(pTHX_ CV *cv, GV *gv, char *p) +Perl_cv_ckproto(pTHX_ const CV *cv, const GV *gv, const char *p) { if (((!p != !SvPOK(cv)) || (p && strNE(p, SvPVX(cv)))) && ckWARN_d(WARN_PROTOTYPE)) { SV* msg = sv_newmortal(); diff --git a/pod/perlapi.pod b/pod/perlapi.pod index 1c33761..bf1256f 100644 --- a/pod/perlapi.pod +++ b/pod/perlapi.pod @@ -179,7 +179,7 @@ Found in file av.c Returns the highest index in the array. Returns -1 if the array is empty. - I32 av_len(AV* ar) + I32 av_len(const AV* ar) =for hackers Found in file av.c @@ -1411,7 +1411,7 @@ Found in file mg.c Finds the magic pointer for type matching the SV. See C. - MAGIC* mg_find(SV* sv, int type) + MAGIC* mg_find(const SV* sv, int type) =for hackers Found in file mg.c @@ -5160,7 +5160,7 @@ Found in file sv.c =item bytes_from_utf8 Converts a string C of length C from UTF-8 into byte encoding. -Unlike but like C, returns a pointer to +Unlike C but like C, returns a pointer to the newly-created string, and updates C to contain the new length. Returns the original string if no conversion occurs, C is unchanged. Do nothing if C points to 0. Sets C to @@ -5186,7 +5186,7 @@ see sv_recode_to_utf8(). NOTE: this function is experimental and may change or be removed without notice. - U8* bytes_to_utf8(U8 *s, STRLEN *len) + U8* bytes_to_utf8(const U8 *s, STRLEN *len) =for hackers Found in file utf8.c @@ -5457,7 +5457,7 @@ and C. WARNING: use only if you *know* that the pointers point inside the same UTF-8 buffer. - IV utf8_distance(U8 *a, U8 *b) + IV utf8_distance(const U8 *a, const U8 *b) =for hackers Found in file utf8.c @@ -5482,7 +5482,7 @@ Return the length of the UTF-8 char encoded string C in characters. Stops at C (inclusive). If C s> or if the scan would end up past C, croaks. - STRLEN utf8_length(U8* s, U8 *e) + STRLEN utf8_length(const U8* s, const U8 *e) =for hackers Found in file utf8.c diff --git a/pp_ctl.c b/pp_ctl.c index fe03eeb..40c3b22 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1392,13 +1392,12 @@ Perl_qerror(pTHX_ SV *err) } OP * -Perl_die_where(pTHX_ char *message, STRLEN msglen) +Perl_die_where(pTHX_ const char *message, STRLEN msglen) { STRLEN n_a; if (PL_in_eval) { I32 cxix; - register PERL_CONTEXT *cx; I32 gimme; SV **newsp; @@ -1439,6 +1438,7 @@ Perl_die_where(pTHX_ char *message, STRLEN msglen) if (cxix >= 0) { I32 optype; + register PERL_CONTEXT *cx; if (cxix < cxstack_ix) dounwind(cxix); @@ -1466,9 +1466,9 @@ Perl_die_where(pTHX_ char *message, STRLEN msglen) PL_curcop = cx->blk_oldcop; if (optype == OP_REQUIRE) { - char* msg = SvPVx(ERRSV, n_a); - SV *nsv = cx->blk_eval.old_namesv; - (void)hv_store(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), + const char* msg = SvPVx(ERRSV, n_a); + SV *nsv = cx->blk_eval.old_namesv; + (void)hv_store(GvHVn(PL_incgv), SvPVX(nsv), SvCUR(nsv), &PL_sv_undef, 0); DIE(aTHX_ "%sCompilation failed in require", *msg ? msg : "Unknown error\n"); diff --git a/proto.h b/proto.h index 8ab2155..41513ad 100644 --- a/proto.h +++ b/proto.h @@ -64,7 +64,7 @@ PERL_CALLCONV void Perl_av_extend(pTHX_ AV* ar, I32 key); PERL_CALLCONV AV* Perl_av_fake(pTHX_ I32 size, SV** svp); PERL_CALLCONV SV** Perl_av_fetch(pTHX_ AV* ar, I32 key, I32 lval); PERL_CALLCONV void Perl_av_fill(pTHX_ AV* ar, I32 fill); -PERL_CALLCONV I32 Perl_av_len(pTHX_ AV* ar); +PERL_CALLCONV I32 Perl_av_len(pTHX_ const AV* ar); PERL_CALLCONV AV* Perl_av_make(pTHX_ I32 size, SV** svp); PERL_CALLCONV SV* Perl_av_pop(pTHX_ AV* ar); PERL_CALLCONV void Perl_av_push(pTHX_ AV* ar, SV* val); @@ -123,7 +123,7 @@ PERL_CALLCONV int Perl_fprintf_nocontext(PerlIO* stream, const char* fmt, ...) PERL_CALLCONV int Perl_printf_nocontext(const char* fmt, ...) __attribute__format__(__printf__,1,2); #endif -PERL_CALLCONV void Perl_cv_ckproto(pTHX_ CV* cv, GV* gv, char* p); +PERL_CALLCONV void Perl_cv_ckproto(pTHX_ const CV* cv, const GV* gv, const char* p); PERL_CALLCONV CV* Perl_cv_clone(pTHX_ CV* proto); PERL_CALLCONV SV* Perl_cv_const_sv(pTHX_ CV* cv); PERL_CALLCONV SV* Perl_op_const_sv(pTHX_ OP* o, CV* cv); @@ -151,7 +151,7 @@ PERL_CALLCONV void Perl_deprecate_old(pTHX_ char* s); PERL_CALLCONV OP* Perl_die(pTHX_ const char* pat, ...) __attribute__format__(__printf__,pTHX_1,pTHX_2); PERL_CALLCONV OP* Perl_vdie(pTHX_ const char* pat, va_list* args); -PERL_CALLCONV OP* Perl_die_where(pTHX_ char* message, STRLEN msglen); +PERL_CALLCONV OP* Perl_die_where(pTHX_ const char* message, STRLEN msglen); PERL_CALLCONV void Perl_dounwind(pTHX_ I32 cxix); PERL_CALLCONV bool Perl_do_aexec(pTHX_ SV* really, SV** mark, SV** sp); PERL_CALLCONV bool Perl_do_aexec5(pTHX_ SV* really, SV** mark, SV** sp, int fd, int flag); @@ -227,18 +227,18 @@ PERL_CALLCONV GV* Perl_gv_HVadd(pTHX_ GV* gv); PERL_CALLCONV GV* Perl_gv_IOadd(pTHX_ GV* gv); PERL_CALLCONV GV* Perl_gv_autoload4(pTHX_ HV* stash, const char* name, STRLEN len, I32 method); PERL_CALLCONV void Perl_gv_check(pTHX_ HV* stash); -PERL_CALLCONV void Perl_gv_efullname(pTHX_ SV* sv, GV* gv); -/* PERL_CALLCONV void gv_efullname3(pTHX_ SV* sv, GV* gv, const char* prefix); */ -PERL_CALLCONV void Perl_gv_efullname4(pTHX_ SV* sv, GV* gv, const char* prefix, bool keepmain); +PERL_CALLCONV void Perl_gv_efullname(pTHX_ SV* sv, const GV* gv); +/* PERL_CALLCONV void gv_efullname3(pTHX_ SV* sv, const GV* gv, const char* prefix); */ +PERL_CALLCONV void Perl_gv_efullname4(pTHX_ SV* sv, const GV* gv, const char* prefix, bool keepmain); PERL_CALLCONV GV* Perl_gv_fetchfile(pTHX_ const char* name); PERL_CALLCONV GV* Perl_gv_fetchmeth(pTHX_ HV* stash, const char* name, STRLEN len, I32 level); PERL_CALLCONV GV* Perl_gv_fetchmeth_autoload(pTHX_ HV* stash, const char* name, STRLEN len, I32 level); PERL_CALLCONV GV* Perl_gv_fetchmethod(pTHX_ HV* stash, const char* name); PERL_CALLCONV GV* Perl_gv_fetchmethod_autoload(pTHX_ HV* stash, const char* name, I32 autoload); PERL_CALLCONV GV* Perl_gv_fetchpv(pTHX_ const char* name, I32 add, I32 sv_type); -PERL_CALLCONV void Perl_gv_fullname(pTHX_ SV* sv, GV* gv); -/* PERL_CALLCONV void gv_fullname3(pTHX_ SV* sv, GV* gv, const char* prefix); */ -PERL_CALLCONV void Perl_gv_fullname4(pTHX_ SV* sv, GV* gv, const char* prefix, bool keepmain); +PERL_CALLCONV void Perl_gv_fullname(pTHX_ SV* sv, const GV* gv); +/* PERL_CALLCONV void gv_fullname3(pTHX_ SV* sv, const GV* gv, const char* prefix); */ +PERL_CALLCONV void Perl_gv_fullname4(pTHX_ SV* sv, const GV* gv, const char* prefix, bool keepmain); PERL_CALLCONV void Perl_gv_init(pTHX_ GV* gv, HV* stash, const char* name, STRLEN len, int multi); PERL_CALLCONV HV* Perl_gv_stashpv(pTHX_ const char* name, I32 create); PERL_CALLCONV HV* Perl_gv_stashpvn(pTHX_ const char* name, U32 namelen, I32 create); @@ -417,7 +417,7 @@ PERL_CALLCONV void Perl_qerror(pTHX_ SV* err); PERL_CALLCONV void Perl_sortsv(pTHX_ SV ** array, size_t num_elts, SVCOMPARE_t cmp); PERL_CALLCONV int Perl_mg_clear(pTHX_ SV* sv); PERL_CALLCONV int Perl_mg_copy(pTHX_ SV* sv, SV* nsv, const char* key, I32 klen); -PERL_CALLCONV MAGIC* Perl_mg_find(pTHX_ SV* sv, int type); +PERL_CALLCONV MAGIC* Perl_mg_find(pTHX_ const SV* sv, int type); PERL_CALLCONV int Perl_mg_free(pTHX_ SV* sv); PERL_CALLCONV int Perl_mg_get(pTHX_ SV* sv); PERL_CALLCONV U32 Perl_mg_length(pTHX_ SV* sv); @@ -606,7 +606,7 @@ PERL_CALLCONV char* Perl_savesharedpv(pTHX_ const char* pv); PERL_CALLCONV char* Perl_savepvn(pTHX_ const char* pv, I32 len); PERL_CALLCONV void Perl_savestack_grow(pTHX); PERL_CALLCONV void Perl_savestack_grow_cnt(pTHX_ I32 need); -PERL_CALLCONV void Perl_save_aelem(pTHX_ AV* av, I32 idx, SV **sptr); +PERL_CALLCONV void Perl_save_aelem(pTHX_ const AV* av, I32 idx, SV **sptr); PERL_CALLCONV I32 Perl_save_alloc(pTHX_ I32 size, I32 pad); PERL_CALLCONV void Perl_save_aptr(pTHX_ AV** aptr); PERL_CALLCONV AV* Perl_save_ary(pTHX_ GV* gv); @@ -623,7 +623,7 @@ PERL_CALLCONV void Perl_save_generic_pvref(pTHX_ char** str); PERL_CALLCONV void Perl_save_shared_pvref(pTHX_ char** str); PERL_CALLCONV void Perl_save_gp(pTHX_ GV* gv, I32 empty); PERL_CALLCONV HV* Perl_save_hash(pTHX_ GV* gv); -PERL_CALLCONV void Perl_save_helem(pTHX_ HV* hv, SV *key, SV **sptr); +PERL_CALLCONV void Perl_save_helem(pTHX_ const HV* hv, SV *key, SV **sptr); PERL_CALLCONV void Perl_save_hints(pTHX); PERL_CALLCONV void Perl_save_hptr(pTHX_ HV** hptr); PERL_CALLCONV void Perl_save_I16(pTHX_ I16* intp); @@ -783,12 +783,12 @@ PERL_CALLCONV void Perl_unshare_hek(pTHX_ HEK* hek); PERL_CALLCONV void Perl_utilize(pTHX_ int aver, I32 floor, OP* version, OP* idop, OP* arg); PERL_CALLCONV U8* Perl_utf16_to_utf8(pTHX_ U8* p, U8 *d, I32 bytelen, I32 *newlen); PERL_CALLCONV U8* Perl_utf16_to_utf8_reversed(pTHX_ U8* p, U8 *d, I32 bytelen, I32 *newlen); -PERL_CALLCONV STRLEN Perl_utf8_length(pTHX_ U8* s, U8 *e); -PERL_CALLCONV IV Perl_utf8_distance(pTHX_ U8 *a, U8 *b); +PERL_CALLCONV STRLEN Perl_utf8_length(pTHX_ const U8* s, const U8 *e); +PERL_CALLCONV IV Perl_utf8_distance(pTHX_ const U8 *a, const U8 *b); PERL_CALLCONV U8* Perl_utf8_hop(pTHX_ U8 *s, I32 off); PERL_CALLCONV U8* Perl_utf8_to_bytes(pTHX_ U8 *s, STRLEN *len); PERL_CALLCONV U8* Perl_bytes_from_utf8(pTHX_ U8 *s, STRLEN *len, bool *is_utf8); -PERL_CALLCONV U8* Perl_bytes_to_utf8(pTHX_ U8 *s, STRLEN *len); +PERL_CALLCONV U8* Perl_bytes_to_utf8(pTHX_ const U8 *s, STRLEN *len); PERL_CALLCONV UV Perl_utf8_to_uvchr(pTHX_ U8 *s, STRLEN* retlen); PERL_CALLCONV UV Perl_utf8_to_uvuni(pTHX_ U8 *s, STRLEN* retlen); PERL_CALLCONV UV Perl_utf8n_to_uvchr(pTHX_ U8 *s, STRLEN curlen, STRLEN* retlen, U32 flags); @@ -814,7 +814,7 @@ PERL_CALLCONV void Perl_warner(pTHX_ U32 err, const char* pat, ...) __attribute__format__(__printf__,pTHX_2,pTHX_3); PERL_CALLCONV void Perl_vwarner(pTHX_ U32 err, const char* pat, va_list* args); PERL_CALLCONV void Perl_watch(pTHX_ char** addr); -PERL_CALLCONV I32 Perl_whichsig(pTHX_ char* sig); +PERL_CALLCONV I32 Perl_whichsig(pTHX_ const char* sig); PERL_CALLCONV void Perl_write_to_stderr(pTHX_ const char* message, int msglen); PERL_CALLCONV int Perl_yyerror(pTHX_ char* s); PERL_CALLCONV int Perl_yylex(pTHX); diff --git a/scope.c b/scope.c index b2dc422..c4edd17 100644 --- a/scope.c +++ b/scope.c @@ -90,15 +90,15 @@ Perl_push_scope(pTHX) void Perl_pop_scope(pTHX) { - I32 oldsave = PL_scopestack[--PL_scopestack_ix]; + const I32 oldsave = PL_scopestack[--PL_scopestack_ix]; LEAVE_SCOPE(oldsave); } void Perl_markstack_grow(pTHX) { - I32 oldmax = PL_markstack_max - PL_markstack; - I32 newmax = GROW(oldmax); + const I32 oldmax = PL_markstack_max - PL_markstack; + const I32 newmax = GROW(oldmax); Renew(PL_markstack, newmax, I32); PL_markstack_ptr = PL_markstack + oldmax; @@ -137,7 +137,7 @@ void Perl_free_tmps(pTHX) { /* XXX should tmps_floor live in cxstack? */ - I32 myfloor = PL_tmps_floor; + const I32 myfloor = PL_tmps_floor; while (PL_tmps_ix > myfloor) { /* clean up after last statement */ SV* sv = PL_tmps_stack[PL_tmps_ix]; PL_tmps_stack[PL_tmps_ix--] = Nullsv; @@ -159,7 +159,7 @@ S_save_scalar_at(pTHX_ SV **sptr) MAGIC *mg; sv_upgrade(sv, SvTYPE(osv)); if (SvGMAGICAL(osv)) { - bool oldtainted = PL_tainted; + const bool oldtainted = PL_tainted; mg_get(osv); /* note, can croak! */ if (PL_tainting && PL_tainted && (mg = mg_find(osv, PERL_MAGIC_taint))) { @@ -582,7 +582,7 @@ Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p) } void -Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr) +Perl_save_aelem(pTHX_ const AV *av, I32 idx, SV **sptr) { SV *sv; SSCHECK(4); @@ -604,7 +604,7 @@ Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr) } void -Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr) +Perl_save_helem(pTHX_ const HV *hv, SV *key, SV **sptr) { SV *sv; SSCHECK(4); @@ -633,9 +633,9 @@ Perl_save_op(pTHX) I32 Perl_save_alloc(pTHX_ I32 size, I32 pad) { - register I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix] + register const I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix] - (char*)PL_savestack); - register I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack)); + register const I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack)); /* SSCHECK may not be good enough */ while (PL_savestack_ix + elems + 2 > PL_savestack_max) @@ -751,7 +751,7 @@ Perl_leave_scope(pTHX_ I32 base) av = (AV*)SSPOPPTR; gv = (GV*)SSPOPPTR; if (GvAV(gv)) { - AV *goner = GvAV(gv); + AV * const goner = GvAV(gv); SvMAGIC(av) = SvMAGIC(goner); SvFLAGS((SV*)av) |= SvMAGICAL(goner); SvMAGICAL_off(goner); @@ -769,7 +769,7 @@ Perl_leave_scope(pTHX_ I32 base) hv = (HV*)SSPOPPTR; gv = (GV*)SSPOPPTR; if (GvHV(gv)) { - HV *goner = GvHV(gv); + HV * const goner = GvHV(gv); SvMAGIC(hv) = SvMAGIC(goner); SvFLAGS(hv) |= SvMAGICAL(goner); SvMAGICAL_off(goner); @@ -908,7 +908,7 @@ Perl_leave_scope(pTHX_ I32 base) SvPADSTALE_on(sv); /* mark as no longer live */ } else { /* Someone has a claim on this, so abandon it. */ - U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP); + const U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP); switch (SvTYPE(sv)) { /* Console ourselves with a new value */ case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break; case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break; @@ -969,7 +969,7 @@ Perl_leave_scope(pTHX_ I32 base) hv = (HV*)SSPOPPTR; ptr = hv_fetch_ent(hv, sv, 1, 0); if (ptr) { - SV *oval = HeVAL((HE*)ptr); + const SV * const oval = HeVAL((HE*)ptr); if (oval && oval != &PL_sv_undef) { ptr = &HeVAL((HE*)ptr); if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied)) @@ -1007,7 +1007,7 @@ Perl_leave_scope(pTHX_ I32 base) break; case SAVEt_PADSV: { - PADOFFSET off = (PADOFFSET)SSPOPLONG; + const PADOFFSET off = (PADOFFSET)SSPOPLONG; ptr = SSPOPPTR; if (ptr) AvARRAY((PAD*)ptr)[off] = (SV*)SSPOPPTR; @@ -1024,8 +1024,8 @@ Perl_leave_scope(pTHX_ I32 base) break; case SAVEt_SET_SVFLAGS: { - U32 val = (U32)SSPOPINT; - U32 mask = (U32)SSPOPINT; + const U32 val = (U32)SSPOPINT; + const U32 mask = (U32)SSPOPINT; sv = (SV*)SSPOPPTR; SvFLAGS(sv) &= ~mask; SvFLAGS(sv) |= val; diff --git a/utf8.c b/utf8.c index b110614..ab49b9e 100644 --- a/utf8.c +++ b/utf8.c @@ -581,7 +581,7 @@ Perl_utf8_to_uvuni(pTHX_ U8 *s, STRLEN *retlen) } /* -=for apidoc A|STRLEN|utf8_length|U8 *s|U8 *e +=for apidoc A|STRLEN|utf8_length|const U8 *s|const U8 *e Return the length of the UTF-8 char encoded string C in characters. Stops at C (inclusive). If C s> or if the scan would end @@ -591,7 +591,7 @@ up past C, croaks. */ STRLEN -Perl_utf8_length(pTHX_ U8 *s, U8 *e) +Perl_utf8_length(pTHX_ const U8 *s, const U8 *e) { STRLEN len = 0; @@ -630,7 +630,7 @@ Perl_utf8_length(pTHX_ U8 *s, U8 *e) } /* -=for apidoc A|IV|utf8_distance|U8 *a|U8 *b +=for apidoc A|IV|utf8_distance|const U8 *a|const U8 *b Returns the number of UTF-8 characters between the UTF-8 pointers C and C. @@ -642,7 +642,7 @@ same UTF-8 buffer. */ IV -Perl_utf8_distance(pTHX_ U8 *a, U8 *b) +Perl_utf8_distance(pTHX_ const U8 *a, const U8 *b) { IV off = 0; @@ -652,7 +652,7 @@ Perl_utf8_distance(pTHX_ U8 *a, U8 *b) if (a < b) { while (a < b) { - U8 c = UTF8SKIP(a); + const U8 c = UTF8SKIP(a); if (b - a < c) { if (ckWARN_d(WARN_UTF8)) { @@ -769,7 +769,7 @@ Perl_utf8_to_bytes(pTHX_ U8 *s, STRLEN *len) =for apidoc A|U8 *|bytes_from_utf8|U8 *s|STRLEN *len|bool *is_utf8 Converts a string C of length C from UTF-8 into byte encoding. -Unlike but like C, returns a pointer to +Unlike C but like C, returns a pointer to the newly-created string, and updates C to contain the new length. Returns the original string if no conversion occurs, C is unchanged. Do nothing if C points to 0. Sets C to @@ -820,7 +820,7 @@ Perl_bytes_from_utf8(pTHX_ U8 *s, STRLEN *len, bool *is_utf8) } /* -=for apidoc A|U8 *|bytes_to_utf8|U8 *s|STRLEN *len +=for apidoc A|U8 *|bytes_to_utf8|const U8 *s|STRLEN *len Converts a string C of length C from ASCII into UTF-8 encoding. Returns a pointer to the newly-created string, and sets C to @@ -833,18 +833,17 @@ see sv_recode_to_utf8(). */ U8* -Perl_bytes_to_utf8(pTHX_ U8 *s, STRLEN *len) +Perl_bytes_to_utf8(pTHX_ const U8 *s, STRLEN *len) { - U8 *send; + const U8 * const send = s + (*len); U8 *d; U8 *dst; - send = s + (*len); Newz(801, d, (*len) * 2 + 1, U8); dst = d; while (s < send) { - UV uv = NATIVE_TO_ASCII(*s++); + const UV uv = NATIVE_TO_ASCII(*s++); if (UNI_IS_INVARIANT(uv)) *d++ = (U8)UTF_TO_NATIVE(uv); else {