From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7816 invoked by alias); 1 Oct 2013 17:48:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 7790 invoked by uid 89); 1 Oct 2013 17:48:10 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Oct 2013 17:48:10 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r91Hm53P029855 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 1 Oct 2013 13:48:05 -0400 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r91Hm3Bk012162 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Tue, 1 Oct 2013 13:48:04 -0400 Message-ID: <524B0AD3.6080600@redhat.com> Date: Tue, 01 Oct 2013 17:48:00 -0000 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: Sergio Durigan Junior CC: "gdb-patches@sourceware.org ml" Subject: Re: [RFA 1/4] Constify LEXPTR References: <5249C947.60604@redhat.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------000903060500050406030200" X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00065.txt.bz2 This is a multi-part message in MIME format. --------------000903060500050406030200 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 7116 Hi, Sergio, On 09/30/2013 09:06 PM, Sergio Durigan Junior wrote: > On Monday, September 30 2013, Keith Seitz wrote: > I don't know how you're planning to commit that, but I'd vote for push > the final result of applying all patches, because I don't see a strong > reason to commit each patch separately in this specific case. WDYT? > But IANAM. Yeah, I would probably commit as one big one. That's how I usually test on patchsets anyway. I just split them up to try and make them more manageable for reviewers. [Notice I said, "try." I seem to seldom succeed lately!] [ChangeLog hasn't changed, so I'm just leaving it in this reply.] >> ChangeLog >> 2013-09-24 Keith Seitz >> >> * c-exp.y (parse_number): Make first argument const. >> Make a copy of the input to manipulate. >> (c_parse_escape): Make first argument const. >> Make local variable 'tokptr' const. >> (parse_string_or_char): Make first two arguments const. >> (macro_original_text): Make const. >> (lex_one_token): Make local variable 'tokstart' const. >> Likewise for local variables named 'p'. >> Cast away const for struct stoken (temporary). >> * c-lang.h (c_parse_escpae): Make first argument const. >> * cli/cli-cmds.c (echo_command): Make local variable 'p' >> const. >> * cli/cli-setshow.c (do_set_command): Likewise for 'p' in >> var_string case. >> * f-exp.y (parse_number): Make first argument const. >> (match_string_literal): Make local variable 'tokstart' >> const. >> (yylex): Make local variable 'p' const. >> Cast away const for struct stoken (temporary). >> * go-exp.y (parse_number): Make first argument const. >> (parse_string_or_char): Likewise. >> Make local variable 'tokstart' const. >> (lex_one_token): Likewise for numerous locals called 'p'. >> Cast away const for struct stoken (temporary). >> * jv-exp.y (parse_number): Make first argument const. >> Make local variables 'tokstart' and 'tokptr' const. >> Cast away const for call to skip_quoted (temporary). >> (yylex): Make local variable 'p' const. >> Cast away const for struct stoken (temporary). >> * m2-exp.y (parse_number): Make local variable 'p' const. >> (yylex): Likewise for 'tokstart'. >> Cast away const for struct stoken (temporary). >> Make local variable 'p' const. >> * macroexp.c (get_character_constant): Pass a const string >> to c_parse_escape. >> (get_string_literal): Likewise. >> (macro_expand_next): Make first argument const. >> Cast away const for init_shared_buffer. >> * macroexp.h (macro_expand_next): Make first argument const. >> * p-exp.y (yylex): Make a local copy of 'lexptr'. >> Pass a const string to c_parse_escape. >> Make local variables 'p' and 'namestart' const. >> * parse.c (lexptr): Make const. >> (prev_lexptr): Likewise. >> (find_template_name_end): Return const. >> Make argument const, too. >> (parse_exp_in_context): Make first argument const. >> Remove the entire const_hack. >> (parse_exp_in_context_1): Make first argument const. >> * parser-defs.h (find_template_name_end): Return const. >> Make argument const, too. >> (lexptr): Make const. >> (prev_lexptr): Likewise. >> * utils.c (parse_escape): Make second argument const. >> * utils.h (parse_escape): Likewise. >> diff --git a/gdb/c-exp.y b/gdb/c-exp.y >> index 3a51878..ea19178 100644 >> --- a/gdb/c-exp.y >> +++ b/gdb/c-exp.y [snip] >> @@ -1699,7 +1699,7 @@ check_parameter_typelist (VEC (type_ptr) *params) >> /*** Needs some error checking for the float case ***/ >> >> static int >> -parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) >> +parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) >> { >> /* FIXME: Shouldn't these be unsigned? We don't deal with negative values >> here, and we do kind of silly things like cast to unsigned. */ >> @@ -1722,6 +1722,9 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) >> struct type *signed_type; >> struct type *unsigned_type; >> >> + char *p = alloca (len); >> + memcpy (p, buf, len); > > I think the declaration of "p" should go together with the other > declarations. And there should be a newline between the declaration and > memcpy. Yes, you are correct! I've fixed this. [See, I *did* warn about the tediousness of these sort of operations. Fortunately, only a handful of things escaped my attention.] >> @@ -2723,7 +2727,7 @@ lex_one_token (void) >> && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t') >> && ! scanning_macro_expansion ()) >> { >> - char *p = tokstart + namelen + 1; >> + const char *p = tokstart + namelen + 1; >> while (*p == ' ' || *p == '\t') > > Newline between declaration and the "while" (you add this in the other > hunks :-)). Fixed. [Yes, I did fix the other occurrences since I was already editing that line anyway.] >> diff --git a/gdb/macroexp.c b/gdb/macroexp.c >> index d88dac3..14c4994 100644 >> --- a/gdb/macroexp.c >> +++ b/gdb/macroexp.c >> @@ -360,8 +360,11 @@ get_character_constant (struct macro_buffer *tok, char *p, char *end) >> } >> else if (*p == '\\') >> { >> - p++; >> - char_count += c_parse_escape (&p, NULL); >> + const char *s, *o; >> + >> + s = o = ++p; > > This line is indented wrongly (only spaces). Fixed. > >> + char_count += c_parse_escape (&s, NULL); >> + p += s - o; >> } >> else >> { >> @@ -414,8 +417,11 @@ get_string_literal (struct macro_buffer *tok, char *p, char *end) >> "constants.")); >> else if (*p == '\\') >> { >> - p++; >> - c_parse_escape (&p, NULL); >> + const char *s, *o; >> + >> + s = o = ++p; >> + c_parse_escape (&s, NULL); > > Wrong indentation (only spaces). > Fixed. >> + p += s - o; >> } >> else >> p++; >> diff --git a/gdb/parse.c b/gdb/parse.c >> index 674342b..07c1765 100644 >> --- a/gdb/parse.c >> +++ b/gdb/parse.c >> @@ -1142,16 +1142,8 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, >> const struct block *block, >> int comma, int void_context_p, int *out_subexp) >> { >> - struct expression *expr; >> - char *const_hack = *stringptr ? xstrdup (*stringptr) : NULL; >> - char *orig = const_hack; >> - struct cleanup *back_to = make_cleanup (xfree, const_hack); >> - >> - expr = parse_exp_in_context_1 (&const_hack, pc, block, comma, >> + return parse_exp_in_context_1 (stringptr, pc, block, comma, >> void_context_p, out_subexp); >> - (*stringptr) += const_hack - orig; >> - do_cleanups (back_to); >> - return expr; > > Nice! :-) > Mission accomplished! :-) >> } >> >> /* As for parse_exp_1, except that if VOID_CONTEXT_P, then > Otherwise, looks good to me (thanks for doing that!), but I can't > approve it :-). For the record, here is update with the aforementioned fixes. Thank you for taking a look! Keith [ChangeLog is above] --------------000903060500050406030200 Content-Type: text/x-patch; name="constify-lexptr-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="constify-lexptr-2.patch" Content-length: 18993 diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 3a51878..a4b1e2a 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -164,7 +164,7 @@ void yyerror (char *); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (char *, int, int, YYSTYPE *); +static int parse_number (const char *, int, int, YYSTYPE *); static struct stoken operator_stoken (const char *); static void check_parameter_typelist (VEC (type_ptr) *); static void write_destructor_name (struct stoken); @@ -1699,7 +1699,7 @@ check_parameter_typelist (VEC (type_ptr) *params) /*** Needs some error checking for the float case ***/ static int -parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere) { /* FIXME: Shouldn't these be unsigned? We don't deal with negative values here, and we do kind of silly things like cast to unsigned. */ @@ -1721,6 +1721,10 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) ULONGEST high_bit; struct type *signed_type; struct type *unsigned_type; + char *p; + + p = alloca (len); + memcpy (p, buf, len); if (parsed_float) { @@ -1941,9 +1945,9 @@ static int tempbuf_init; character was emitted, 0 otherwise. */ int -c_parse_escape (char **ptr, struct obstack *output) +c_parse_escape (const char **ptr, struct obstack *output) { - char *tokptr = *ptr; + const char *tokptr = *ptr; int result = 1; /* Some escape sequences undergo character set conversion. Those we @@ -2102,8 +2106,8 @@ c_parse_escape (char **ptr, struct obstack *output) CHAR, depending on what was parsed. *HOST_CHARS is set to the number of host characters in the literal. */ static int -parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value, - int *host_chars) +parse_string_or_char (const char *tokptr, const char **outptr, + struct typed_stoken *value, int *host_chars) { int quote; enum c_string_type type; @@ -2321,7 +2325,7 @@ static const struct token ident_tokens[] = we evaluate ADDRESS in the scope of the current frame, but we evaluate CONDITION in the scope of the breakpoint's location. So it's simply wrong to try to macro-expand the whole thing at once. */ -static char *macro_original_text; +static const char *macro_original_text; /* We save all intermediate macro expansions on this obstack for the duration of a single parse. The expansion text may sometimes have @@ -2411,7 +2415,7 @@ lex_one_token (void) int c; int namelen; unsigned int i; - char *tokstart; + const char *tokstart; int saw_structop = last_was_structop; char *copy; @@ -2538,7 +2542,7 @@ lex_one_token (void) { /* It's a number. */ int got_dot = 0, got_e = 0, toktype; - char *p = tokstart; + const char *p = tokstart; int hex = input_radix > 10; if (c == '0' && (p[1] == 'x' || p[1] == 'X')) @@ -2590,7 +2594,7 @@ lex_one_token (void) case '@': { - char *p = &tokstart[1]; + const char *p = &tokstart[1]; size_t len = strlen ("entry"); if (parse_language->la_language == language_objc) @@ -2692,7 +2696,8 @@ lex_one_token (void) characters; for comparison expressions, e.g. "a < b > c", there must be spaces before the '<', etc. */ - char * p = find_template_name_end (tokstart + namelen); + const char *p = find_template_name_end (tokstart + namelen); + if (p) namelen = p - tokstart; } @@ -2723,7 +2728,8 @@ lex_one_token (void) && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t') && ! scanning_macro_expansion ()) { - char *p = tokstart + namelen + 1; + const char *p = tokstart + namelen + 1; + while (*p == ' ' || *p == '\t') p++; if (*p >= '0' && *p <= '9') @@ -2734,7 +2740,7 @@ lex_one_token (void) tryname: - yylval.sval.ptr = tokstart; + yylval.sval.ptr = (char *) tokstart; yylval.sval.length = namelen; /* Catch specific keywords. */ diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 6bf6591..9f8f50d 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -61,7 +61,7 @@ extern int c_parse (void); extern void c_error (char *); -extern int c_parse_escape (char **, struct obstack *); +extern int c_parse_escape (const char **, struct obstack *); /* Defined in c-typeprint.c */ extern void c_print_type (struct type *, const char *, diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 4317ea3..886ba7a 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -666,7 +666,7 @@ source_command (char *args, int from_tty) static void echo_command (char *text, int from_tty) { - char *p = text; + const char *p = text; int c; if (text) diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 3e41fd4..45df6f6 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -160,7 +160,7 @@ do_set_command (char *arg, int from_tty, struct cmd_list_element *c) case var_string: { char *new; - char *p; + const char *p; char *q; int ch; diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 296a7fe..9a82230 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -157,7 +157,7 @@ static int match_string_literal (void); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (char *, int, int, YYSTYPE *); +static int parse_number (const char *, int, int, YYSTYPE *); %} %type exp type_exp start variable @@ -669,7 +669,7 @@ name_not_typename : NAME /*** Needs some error checking for the float case ***/ static int -parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) { LONGEST n = 0; LONGEST prevn = 0; @@ -920,7 +920,7 @@ growbuf_by_size (int count) static int match_string_literal (void) { - char *tokptr = lexptr; + const char *tokptr = lexptr; for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++) { @@ -955,7 +955,7 @@ yylex (void) int c; int namelen; unsigned int i,token; - char *tokstart; + const char *tokstart; retry: @@ -1054,7 +1054,7 @@ yylex (void) { /* It's a number. */ int got_dot = 0, got_e = 0, got_d = 0, toktype; - char *p = tokstart; + const char *p = tokstart; int hex = input_radix > 10; if (c == '0' && (p[1] == 'x' || p[1] == 'X')) @@ -1159,7 +1159,7 @@ yylex (void) return f77_keywords[i].token; } - yylval.sval.ptr = tokstart; + yylval.sval.ptr = (char *) tokstart; yylval.sval.length = namelen; if (*tokstart == '$') diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 2ccb394..166d380 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -158,7 +158,7 @@ void yyerror (char *); %{ /* YYSTYPE gets defined by %union. */ -static int parse_number (char *, int, int, YYSTYPE *); +static int parse_number (const char *, int, int, YYSTYPE *); static int parse_go_float (struct gdbarch *gdbarch, const char *p, int len, DOUBLEST *d, struct type **t); %} @@ -704,7 +704,7 @@ parse_go_float (struct gdbarch *gdbarch, const char *p, int len, as our YYSTYPE is different than c-exp.y's */ static int -parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) { /* FIXME: Shouldn't these be unsigned? We don't deal with negative values here, and we do kind of silly things like cast to unsigned. */ @@ -908,8 +908,8 @@ static int tempbuf_init; number of host characters in the literal. */ static int -parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value, - int *host_chars) +parse_string_or_char (const char *tokptr, const char **outptr, + struct typed_stoken *value, int *host_chars) { int quote; @@ -1049,7 +1049,7 @@ lex_one_token (void) int c; int namelen; unsigned int i; - char *tokstart; + const char *tokstart; int saw_structop = last_was_structop; char *copy; @@ -1143,7 +1143,7 @@ lex_one_token (void) { /* It's a number. */ int got_dot = 0, got_e = 0, toktype; - char *p = tokstart; + const char *p = tokstart; int hex = input_radix > 10; if (c == '0' && (p[1] == 'x' || p[1] == 'X')) @@ -1190,7 +1190,7 @@ lex_one_token (void) case '@': { - char *p = &tokstart[1]; + const char *p = &tokstart[1]; size_t len = strlen ("entry"); while (isspace (*p)) @@ -1283,7 +1283,8 @@ lex_one_token (void) && strncmp (tokstart, "thread", namelen) == 0 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')) { - char *p = tokstart + namelen + 1; + const char *p = tokstart + namelen + 1; + while (*p == ' ' || *p == '\t') p++; if (*p >= '0' && *p <= '9') @@ -1294,7 +1295,7 @@ lex_one_token (void) tryname: - yylval.sval.ptr = tokstart; + yylval.sval.ptr = (char *) tokstart; yylval.sval.length = namelen; /* Catch specific keywords. */ diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y index a4e1253..c69caf5 100644 --- a/gdb/jv-exp.y +++ b/gdb/jv-exp.y @@ -154,7 +154,7 @@ static void insert_exp (int, struct expression *); %{ /* YYSTYPE gets defined by %union */ -static int parse_number (char *, int, int, YYSTYPE *); +static int parse_number (const char *, int, int, YYSTYPE *); %} %type rcurly Dims Dims_opt @@ -696,7 +696,7 @@ Expression: /*** Needs some error checking for the float case ***/ static int -parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere) +parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere) { ULONGEST n = 0; ULONGEST limit, limit_div_base; @@ -858,8 +858,8 @@ yylex (void) int c; int namelen; unsigned int i; - char *tokstart; - char *tokptr; + const char *tokstart; + const char *tokptr; int tempbufindex; static char *tempbuf; static int tempbufsize; @@ -915,7 +915,7 @@ yylex (void) c = *lexptr++; if (c != '\'') { - namelen = skip_quoted (tokstart) - tokstart; + namelen = skip_quoted ((char *) tokstart) - tokstart; if (namelen > 2) { lexptr = tokstart + namelen; @@ -966,7 +966,7 @@ yylex (void) { /* It's a number. */ int got_dot = 0, got_e = 0, toktype; - char *p = tokstart; + const char *p = tokstart; int hex = input_radix > 10; if (c == '0' && (p[1] == 'x' || p[1] == 'X')) @@ -1175,7 +1175,7 @@ yylex (void) break; } - yylval.sval.ptr = tokstart; + yylval.sval.ptr = (char *) tokstart; yylval.sval.length = namelen; if (*tokstart == '$') diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index eaa5a23..47ea640 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -662,7 +662,7 @@ type static int parse_number (int olen) { - char *p = lexptr; + const char *p = lexptr; LONGEST n = 0; LONGEST prevn = 0; int c,i,ischar=0; @@ -814,7 +814,7 @@ yylex (void) int c; int namelen; int i; - char *tokstart; + const char *tokstart; char quote; retry: @@ -907,7 +907,7 @@ yylex (void) } if(c != quote) error (_("Unterminated string or character constant.")); - yylval.sval.ptr = tokstart + 1; + yylval.sval.ptr = (char *) (tokstart + 1); yylval.sval.length = namelen - 1; lexptr += namelen + 1; @@ -927,7 +927,7 @@ yylex (void) { /* It's a number. */ int got_dot = 0, got_e = 0; - char *p = tokstart; + const char *p = tokstart; int toktype; for (++p ;; ++p) @@ -987,7 +987,7 @@ yylex (void) && strncmp (tokstart, keytab[i].keyw, namelen) == 0) return keytab[i].token; - yylval.sval.ptr = tokstart; + yylval.sval.ptr = (char *) tokstart; yylval.sval.length = namelen; if (*tokstart == '$') diff --git a/gdb/macroexp.c b/gdb/macroexp.c index d88dac3..3d98550 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -360,8 +360,11 @@ get_character_constant (struct macro_buffer *tok, char *p, char *end) } else if (*p == '\\') { - p++; - char_count += c_parse_escape (&p, NULL); + const char *s, *o; + + s = o = ++p; + char_count += c_parse_escape (&s, NULL); + p += s - o; } else { @@ -414,8 +417,11 @@ get_string_literal (struct macro_buffer *tok, char *p, char *end) "constants.")); else if (*p == '\\') { - p++; - c_parse_escape (&p, NULL); + const char *s, *o; + + s = o = ++p; + c_parse_escape (&s, NULL); + p += s - o; } else p++; @@ -1434,7 +1440,7 @@ macro_expand_once (const char *source, char * -macro_expand_next (char **lexptr, +macro_expand_next (const char **lexptr, macro_lookup_ftype *lookup_func, void *lookup_baton) { @@ -1442,7 +1448,7 @@ macro_expand_next (char **lexptr, struct cleanup *back_to; /* Set up SRC to refer to the input text, pointed to by *lexptr. */ - init_shared_buffer (&src, *lexptr, strlen (*lexptr)); + init_shared_buffer (&src, (char *) *lexptr, strlen (*lexptr)); /* Set up DEST to receive the expansion, if there is one. */ init_buffer (&dest, 0); diff --git a/gdb/macroexp.h b/gdb/macroexp.h index cbe9629..8bf4b7f 100644 --- a/gdb/macroexp.h +++ b/gdb/macroexp.h @@ -80,7 +80,7 @@ char *macro_expand_once (const char *source, much have to do tokenization to find the end of the string that needs to be macro-expanded. Our C/C++ tokenizer isn't really designed to be called by anything but the yacc parser engine. */ -char *macro_expand_next (char **lexptr, +char *macro_expand_next (const char **lexptr, macro_lookup_ftype *lookup_func, void *lookup_baton); diff --git a/gdb/p-exp.y b/gdb/p-exp.y index da8d5f7..e0abd07 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -1141,8 +1141,10 @@ yylex (void) prev_lexptr = lexptr; - tokstart = lexptr; explen = strlen (lexptr); + tokstart = alloca (explen + 1); + memcpy (tokstart, lexptr, explen + 1); + /* See if it is a special token of length 3. */ if (explen > 2) for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++) @@ -1361,13 +1363,18 @@ yylex (void) /* Do nothing, loop will terminate. */ break; case '\\': - tokptr++; - c = parse_escape (parse_gdbarch, &tokptr); - if (c == -1) - { - continue; - } - tempbuf[tempbufindex++] = c; + { + const char *s, *o; + + o = s = ++tokptr; + c = parse_escape (parse_gdbarch, &s); + *tokptr += s - o; + if (c == -1) + { + continue; + } + tempbuf[tempbufindex++] = c; + } break; default: tempbuf[tempbufindex++] = *tokptr++; @@ -1623,8 +1630,8 @@ yylex (void) distinction) named x, then this code incorrectly thinks we are dealing with nested types rather than a member function. */ - char *p; - char *namestart; + const char *p; + const char *namestart; struct symbol *best_sym; /* Look ahead to detect nested types. This probably should be diff --git a/gdb/parse.c b/gdb/parse.c index 674342b..07c1765 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -75,8 +75,8 @@ CORE_ADDR expression_context_pc; const struct block *innermost_block; int arglist_len; static struct type_stack type_stack; -char *lexptr; -char *prev_lexptr; +const char *lexptr; +const char *prev_lexptr; int paren_depth; int comma_terminates; @@ -123,7 +123,7 @@ static int prefixify_subexp (struct expression *, struct expression *, int, static struct expression *parse_exp_in_context (const char **, CORE_ADDR, const struct block *, int, int, int *); -static struct expression *parse_exp_in_context_1 (char **, CORE_ADDR, +static struct expression *parse_exp_in_context_1 (const char **, CORE_ADDR, const struct block *, int, int, int *); @@ -733,8 +733,8 @@ handle_register: } -char * -find_template_name_end (char *p) +const char * +find_template_name_end (const char *p) { int depth = 1; int just_seen_right = 0; @@ -1142,16 +1142,8 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, const struct block *block, int comma, int void_context_p, int *out_subexp) { - struct expression *expr; - char *const_hack = *stringptr ? xstrdup (*stringptr) : NULL; - char *orig = const_hack; - struct cleanup *back_to = make_cleanup (xfree, const_hack); - - expr = parse_exp_in_context_1 (&const_hack, pc, block, comma, + return parse_exp_in_context_1 (stringptr, pc, block, comma, void_context_p, out_subexp); - (*stringptr) += const_hack - orig; - do_cleanups (back_to); - return expr; } /* As for parse_exp_1, except that if VOID_CONTEXT_P, then @@ -1162,7 +1154,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc, is left untouched. */ static struct expression * -parse_exp_in_context_1 (char **stringptr, CORE_ADDR pc, +parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc, const struct block *block, int comma, int void_context_p, int *out_subexp) { diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h index 92daca9..aaefe3f 100644 --- a/gdb/parser-defs.h +++ b/gdb/parser-defs.h @@ -201,7 +201,7 @@ extern void write_dollar_variable (struct stoken str); extern void mark_struct_expression (void); -extern char *find_template_name_end (char *); +extern const char *find_template_name_end (const char *); extern void start_arglist (void); @@ -264,11 +264,11 @@ extern int parse_c_float (struct gdbarch *gdbarch, const char *p, int len, /* During parsing of a C expression, the pointer to the next character is in this variable. */ -extern char *lexptr; +extern const char *lexptr; /* After a token has been recognized, this variable points to it. Currently used only for error reporting. */ -extern char *prev_lexptr; +extern const char *prev_lexptr; /* Current depth in parentheses within the expression. */ diff --git a/gdb/utils.c b/gdb/utils.c index 0652197..26879ec 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1412,7 +1412,7 @@ host_char_to_target (struct gdbarch *gdbarch, int c, int *target_c) after the zeros. A value of 0 does not mean end of string. */ int -parse_escape (struct gdbarch *gdbarch, char **string_ptr) +parse_escape (struct gdbarch *gdbarch, const char **string_ptr) { int target_char = -2; /* Initialize to avoid GCC warnings. */ int c = *(*string_ptr)++; diff --git a/gdb/utils.h b/gdb/utils.h index 143cd6b..3492f09 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -64,7 +64,7 @@ struct timeval get_prompt_for_continue_wait_time (void); extern int parse_pid_to_attach (char *args); -extern int parse_escape (struct gdbarch *, char **); +extern int parse_escape (struct gdbarch *, const char **); char **gdb_buildargv (const char *); --------------000903060500050406030200--