From: Nicholas Clark Date: Sat, 6 Oct 2007 23:44:50 +0000 (+0000) Subject: Finally! Worked out how to const Perl_moreswitches(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c7030b8198b0e74c565e901a90ca7061aebbf5ad;p=p5sagit%2Fp5-mst-13.2.git Finally! Worked out how to const Perl_moreswitches(). Although I've committed crimes against indenting to avoid losing blame annotation history. Revisit this when we have version control that can easily see through whitespace changes. [Can probably now propagate consting inside S_parse_body(), Perl_moreswitches() and Perl_yylex(), but that will not affect the external API, so can wait until after 5.10] p4raw-id: //depot/perl@32057 --- diff --git a/embed.fnc b/embed.fnc index 16a8574..f861bfe 100644 --- a/embed.fnc +++ b/embed.fnc @@ -501,7 +501,7 @@ Ap |I32 |mg_size |NN SV* sv Ap |void |mini_mktime |NN struct tm *pm EXp |OP* |mod |NULLOK OP* o|I32 type p |int |mode_from_discipline|NULLOK SV* discp -Ap |char* |moreswitches |NN char* s +Ap |const char* |moreswitches |NN const char* s p |OP* |my |NN OP* o Ap |NV |my_atof |NN const char *s #if (!defined(HAS_MEMCPY) && !defined(HAS_BCOPY)) || (!defined(HAS_MEMMOVE) && !defined(HAS_SAFE_MEMCPY) && !defined(HAS_SAFE_BCOPY)) diff --git a/perl.c b/perl.c index 158526a..8b29386 100644 --- a/perl.c +++ b/perl.c @@ -1686,7 +1686,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) VOL bool dosearch = FALSE; const char *validarg = ""; register SV *sv; - register char *s, c; + register char c; const char *cddir = NULL; #ifdef USE_SITECUSTOMIZE bool minus_f = FALSE; @@ -1701,6 +1701,8 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) SAVEFREESV(sv); init_main_stash(); + { + const char *s; for (argc--,argv++; argc > 0; argc--,argv++) { if (argv[0][0] != '-' || !argv[0][1]) break; @@ -1953,8 +1955,13 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) Perl_croak(aTHX_ "Unrecognized switch: -%s (-h will show valid options)",s); } } + } + switch_end: + { + char *s; + if ( #ifndef SECURE_INTERNAL_GETENV !PL_tainting && @@ -2007,6 +2014,7 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) } } } + } #ifdef USE_SITECUSTOMIZE if (!minus_f) { @@ -2159,6 +2167,8 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) } } + { + const char *s; if ((s = PerlEnv_getenv("PERL_SIGNALS"))) { if (strEQ(s, "unsafe")) PL_signals |= PERL_SIGNALS_UNSAFE_FLAG; @@ -2167,8 +2177,11 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) else Perl_croak(aTHX_ "PERL_SIGNALS illegal: \"%s\"", s); } + } #ifdef PERL_MAD + { + const char *s; if ((s = PerlEnv_getenv("PERL_XMLDUMP"))) { PL_madskills = 1; PL_minus_c = 1; @@ -2181,10 +2194,15 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit) } my_setenv("PERL_XMLDUMP", NULL); /* hide from subprocs */ } + } + + { + const char *s; if ((s = PerlEnv_getenv("PERL_MADSKILLS"))) { PL_madskills = atoi(s); my_setenv("PERL_MADSKILLS", NULL); /* hide from subprocs */ } + } #endif lex_start(linestr_sv, rsfp, TRUE); @@ -2944,8 +2962,8 @@ Perl_get_debug_opts(pTHX_ const char **s, bool givehelp) /* This routine handles any switches that can be given during run */ -char * -Perl_moreswitches(pTHX_ char *s) +const char * +Perl_moreswitches(pTHX_ const char *s) { dVAR; UV rschar; @@ -3092,7 +3110,7 @@ Perl_moreswitches(pTHX_ char *s) while (*s && isSPACE(*s)) ++s; if (*s) { - char *e, *p; + const char *e, *p; p = s; /* ignore trailing spaces (possibly followed by other switches) */ do { @@ -3141,7 +3159,7 @@ Perl_moreswitches(pTHX_ char *s) case 'm': forbid_setid('m', -1); /* XXX ? */ if (*++s) { - char *start; + const char *start; SV *sv; const char *use = "use "; /* -M-foo == 'no foo' */ @@ -4251,7 +4269,7 @@ STATIC void S_find_beginning(pTHX_ SV* linestr_sv, PerlIO *rsfp) { dVAR; - register char *s; + const char *s; register const char *s2; #ifdef MACOS_TRADITIONAL int maclines = 0; diff --git a/proto.h b/proto.h index 2c891d2..86ac3e8 100644 --- a/proto.h +++ b/proto.h @@ -1347,7 +1347,7 @@ PERL_CALLCONV void Perl_mini_mktime(pTHX_ struct tm *pm) PERL_CALLCONV OP* Perl_mod(pTHX_ OP* o, I32 type); PERL_CALLCONV int Perl_mode_from_discipline(pTHX_ SV* discp); -PERL_CALLCONV char* Perl_moreswitches(pTHX_ char* s) +PERL_CALLCONV const char* Perl_moreswitches(pTHX_ const char* s) __attribute__nonnull__(pTHX_1); PERL_CALLCONV OP* Perl_my(pTHX_ OP* o) diff --git a/toke.c b/toke.c index 95be7d4..9b61cee 100644 --- a/toke.c +++ b/toke.c @@ -3890,17 +3890,18 @@ Perl_yylex(pTHX) const U32 oldpdb = PL_perldb; const bool oldn = PL_minus_n; const bool oldp = PL_minus_p; + const char *d1 = d; do { - if (*d == 'M' || *d == 'm' || *d == 'C') { - const char * const m = d; - while (*d && !isSPACE(*d)) - d++; + if (*d1 == 'M' || *d1 == 'm' || *d1 == 'C') { + const char * const m = d1; + while (*d1 && !isSPACE(*d1)) + d1++; Perl_croak(aTHX_ "Too late for \"-%.*s\" option", - (int)(d - m), m); + (int)(d1 - m), m); } - d = moreswitches(d); - } while (d); + d1 = moreswitches(d1); + } while (d1); if (PL_doswitches && !switches_done) { int argc = PL_origargc; char **argv = PL_origargv;