From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12425 invoked by alias); 24 Jul 2014 01:27:06 -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 12414 invoked by uid 89); 24 Jul 2014 01:27:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 24 Jul 2014 01:27:03 +0000 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 s6O1R2hl001495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 23 Jul 2014 21:27:02 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6O1R0X7002926; Wed, 23 Jul 2014 21:27:01 -0400 Message-ID: <53D060E4.3030405@redhat.com> Date: Thu, 24 Jul 2014 01:32:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [PATCH 2/3] constify some cli-utils stuff References: <1406150844-17134-1-git-send-email-tromey@redhat.com> <1406150844-17134-3-git-send-email-tromey@redhat.com> In-Reply-To: <1406150844-17134-3-git-send-email-tromey@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2014-07/txt/msg00599.txt.bz2 Looks good. Thanks, Pedro Alves On 07/23/2014 10:27 PM, Tom Tromey wrote: > This constifies a few functions in cli-utils -- get_number_trailer and > friends -- and then fixes the fallout. > > 2014-07-22 Tom Tromey > > * breakpoint.c (map_breakpoint_numbers): Update. > * cli/cli-utils.c (get_number_trailer): Make "pp" const. Update. > (get_number_const): New function. > (get_number): Rewrite using get_number_const. > (init_number_or_range): Make "string" const. > (number_is_in_list): Make "list" const. > * cli/cli-utils.h (get_number_const): Declare. > (struct get_number_or_range_state) : Now const. > (init_number_or_range, number_is_in_list): Update. > * printcmd.c (map_display_numbers): Update. > * value.c (value_from_history_ref): Constify. > * value.h (value_from_history_ref): Update. > --- > gdb/ChangeLog | 15 +++++++++++++++ > gdb/breakpoint.c | 2 +- > gdb/cli/cli-utils.c | 33 +++++++++++++++++++++++---------- > gdb/cli/cli-utils.h | 12 ++++++++---- > gdb/printcmd.c | 2 +- > gdb/value.c | 16 +++++++++++++--- > gdb/value.h | 2 +- > 7 files changed, 62 insertions(+), 20 deletions(-) > > diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c > index 908a1ea..775d555 100644 > --- a/gdb/breakpoint.c > +++ b/gdb/breakpoint.c > @@ -14790,7 +14790,7 @@ map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, > > while (!state.finished) > { > - char *p = state.string; > + const char *p = state.string; > > match = 0; > > diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c > index a0ebc11..819c94c 100644 > --- a/gdb/cli/cli-utils.c > +++ b/gdb/cli/cli-utils.c > @@ -35,10 +35,10 @@ > commonly this is `-'. If you don't want a trailer, use \0. */ > > static int > -get_number_trailer (char **pp, int trailer) > +get_number_trailer (const char **pp, int trailer) > { > int retval = 0; /* default */ > - char *p = *pp; > + const char *p = *pp; > > if (*p == '$') > { > @@ -59,7 +59,7 @@ get_number_trailer (char **pp, int trailer) > /* Internal variable. Make a copy of the name, so we can > null-terminate it to pass to lookup_internalvar(). */ > char *varname; > - char *start = ++p; > + const char *start = ++p; > LONGEST val; > > while (isalnum (*p) || *p == '_') > @@ -102,7 +102,7 @@ get_number_trailer (char **pp, int trailer) > ++p; > retval = 0; > } > - p = skip_spaces (p); > + p = skip_spaces_const (p); > *pp = p; > return retval; > } > @@ -110,16 +110,29 @@ get_number_trailer (char **pp, int trailer) > /* See documentation in cli-utils.h. */ > > int > -get_number (char **pp) > +get_number_const (const char **pp) > { > return get_number_trailer (pp, '\0'); > } > > /* See documentation in cli-utils.h. */ > > +int > +get_number (char **pp) > +{ > + int result; > + const char *p = *pp; > + > + result = get_number_trailer (&p, '\0'); > + *pp = (char *) p; > + return result; > +} > + > +/* See documentation in cli-utils.h. */ > + > void > init_number_or_range (struct get_number_or_range_state *state, > - char *string) > + const char *string) > { > memset (state, 0, sizeof (*state)); > state->string = string; > @@ -137,15 +150,15 @@ get_number_or_range (struct get_number_or_range_state *state) > state->last_retval = get_number_trailer (&state->string, '-'); > if (*state->string == '-') > { > - char **temp; > + const char **temp; > > /* This is the start of a range ( - ). > Skip the '-', parse and remember the second number, > and also remember the end of the final token. */ > > temp = &state->end_ptr; > - state->end_ptr = skip_spaces (state->string + 1); > - state->end_value = get_number (temp); > + state->end_ptr = skip_spaces_const (state->string + 1); > + state->end_value = get_number_const (temp); > if (state->end_value < state->last_retval) > { > error (_("inverted range")); > @@ -191,7 +204,7 @@ get_number_or_range (struct get_number_or_range_state *state) > no arguments. */ > > int > -number_is_in_list (char *list, int number) > +number_is_in_list (const char *list, int number) > { > struct get_number_or_range_state state; > > diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h > index fed876b..1f0f3df 100644 > --- a/gdb/cli/cli-utils.h > +++ b/gdb/cli/cli-utils.h > @@ -26,6 +26,10 @@ > Currently the string can either be a number, or "$" followed by the > name of a convenience variable, or ("$" or "$$") followed by digits. */ > > +extern int get_number_const (const char **); > + > +/* Like get_number_const, but takes a non-const "char **". */ > + > extern int get_number (char **); > > /* An object of this type is passed to get_number_or_range. It must > @@ -40,7 +44,7 @@ struct get_number_or_range_state > > /* The string being parsed. When parsing has finished, this points > past the last parsed token. */ > - char *string; > + const char *string; > > /* Last value returned. */ > int last_retval; > @@ -50,7 +54,7 @@ struct get_number_or_range_state > > /* When parsing a range, a pointer past the final token in the > range. */ > - char *end_ptr; > + const char *end_ptr; > > /* Non-zero when parsing a range. */ > int in_range; > @@ -60,7 +64,7 @@ struct get_number_or_range_state > get_number_or_range_state. STRING is the string to be parsed. */ > > extern void init_number_or_range (struct get_number_or_range_state *state, > - char *string); > + const char *string); > > /* Parse a number or a range. > A number will be of the form handled by get_number. > @@ -87,7 +91,7 @@ extern int get_number_or_range (struct get_number_or_range_state *state); > be interpreted as typing a command such as "delete break" with > no arguments. */ > > -extern int number_is_in_list (char *list, int number); > +extern int number_is_in_list (const char *list, int number); > > /* Skip leading whitespace characters in INP, returning an updated > pointer. If INP is NULL, return NULL. */ > diff --git a/gdb/printcmd.c b/gdb/printcmd.c > index 228d4ad..b4fd894 100644 > --- a/gdb/printcmd.c > +++ b/gdb/printcmd.c > @@ -1618,7 +1618,7 @@ map_display_numbers (char *args, > > while (!state.finished) > { > - char *p = state.string; > + const char *p = state.string; > > num = get_number_or_range (&state); > if (num == 0) > diff --git a/gdb/value.c b/gdb/value.c > index 29abe5f..5666aa3 100644 > --- a/gdb/value.c > +++ b/gdb/value.c > @@ -3446,7 +3446,7 @@ value_from_decfloat (struct type *type, const gdb_byte *dec) > for details. */ > > struct value * > -value_from_history_ref (char *h, char **endp) > +value_from_history_ref (const char *h, const char **endp) > { > int index, len; > > @@ -3477,7 +3477,12 @@ value_from_history_ref (char *h, char **endp) > *endp += len; > } > else > - index = -strtol (&h[2], endp, 10); > + { > + char *local_end; > + > + index = -strtol (&h[2], &local_end, 10); > + *endp = local_end; > + } > } > else > { > @@ -3488,7 +3493,12 @@ value_from_history_ref (char *h, char **endp) > *endp += len; > } > else > - index = strtol (&h[1], endp, 10); > + { > + char *local_end; > + > + index = strtol (&h[1], &local_end, 10); > + *endp = local_end; > + } > } > > return access_value_history (index); > diff --git a/gdb/value.h b/gdb/value.h > index 86ebd70..4654042 100644 > --- a/gdb/value.h > +++ b/gdb/value.h > @@ -569,7 +569,7 @@ extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr); > extern struct value *value_from_double (struct type *type, DOUBLEST num); > extern struct value *value_from_decfloat (struct type *type, > const gdb_byte *decbytes); > -extern struct value *value_from_history_ref (char *, char **); > +extern struct value *value_from_history_ref (const char *, const char **); > > extern struct value *value_at (struct type *type, CORE_ADDR addr); > extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr); >