From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93448 invoked by alias); 9 Oct 2015 17:17:05 -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 93437 invoked by uid 89); 9 Oct 2015 17:17:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg20.ericsson.net Received: from usevmg20.ericsson.net (HELO usevmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 09 Oct 2015 17:17:03 +0000 Received: from EUSAAHC006.ericsson.se (Unknown_Domain [147.117.188.90]) by usevmg20.ericsson.net (Symantec Mail Security) with SMTP id 00.61.32596.09697165; Fri, 9 Oct 2015 12:27:28 +0200 (CEST) Received: from [142.133.110.144] (147.117.188.8) by smtp-am.internal.ericsson.com (147.117.188.92) with Microsoft SMTP Server id 14.3.248.2; Fri, 9 Oct 2015 13:17:00 -0400 Subject: Re: [PATCH] More char constification To: Pedro Alves , References: <1444406100-13086-1-git-send-email-palves@redhat.com> From: Simon Marchi Message-ID: <5617F68B.8070509@ericsson.com> Date: Fri, 09 Oct 2015 17:17:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1444406100-13086-1-git-send-email-palves@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00105.txt.bz2 On 15-10-09 11:55 AM, Pedro Alves wrote: > Trivial constifications flagged by G++. E.g.: >=20 > src/gdb/c-varobj.c: In function =E2=80=98void c_describe_child(const var= obj*, int, char**, value**, type**, char**)=E2=80=99: > src/gdb/c-varobj.c:373:33: error: invalid conversion from =E2=80=98const= char*=E2=80=99 to =E2=80=98char*=E2=80=99 [-fpermissive] > char *join =3D was_ptr ? "->" : "."; > ^ >=20 > gdb/ChangeLog: > 2015-10-09 Pedro Alves >=20 > * ada-lang.c (ada_enum_name): Constify local. > * ada-typeprint.c (print_range_bound): Constify locals. > * c-varobj.c (c_describe_child): Likewise. > * cli/cli-setshow.c (do_set_command): Likewise. > * gdb_vecs.c (delim_string_to_char_ptr_vec_append): Likewise. > * dwarf2read.c (find_file_and_directory): Likewise. > (anonymous_struct_prefix, dwarf2_name): Likewise. > * gnu-v3-abi.c (gnuv3_rtti_type): Likewise. > * go-lang.c (unpack_mangled_go_symbol): Likewise. > * jv-typeprint.c (java_type_print_base): Likewise. > * ser-tcp.c (net_open): Likewise. > * symfile.c (deduce_language_from_filename): Likewise. > * symtab.c (gdb_mangle_name): Likewise. > * tui/tui-io.c (tui_redisplay_readline): Likewise. > --- > gdb/ada-lang.c | 2 +- > gdb/ada-typeprint.c | 8 ++++---- > gdb/c-varobj.c | 6 +++--- > gdb/cli/cli-setshow.c | 2 +- > gdb/common/gdb_vecs.c | 3 ++- > gdb/dwarf2read.c | 6 +++--- > gdb/gnu-v3-abi.c | 2 +- > gdb/go-lang.c | 4 ++-- > gdb/jv-typeprint.c | 3 ++- > gdb/ser-tcp.c | 3 ++- > gdb/symfile.c | 2 +- > gdb/symtab.c | 4 ++-- > gdb/tui/tui-io.c | 2 +- > 13 files changed, 25 insertions(+), 22 deletions(-) >=20 > diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c > index a229fa1..002d0b8 100644 > --- a/gdb/ada-lang.c > +++ b/gdb/ada-lang.c > @@ -9356,7 +9356,7 @@ ada_enum_name (const char *name) > { > static char *result; > static size_t result_len =3D 0; > - char *tmp; > + const char *tmp; >=20=20 > /* First, unqualify the enumeration name: > 1. Search for the last '.' character. If we find one, then skip > diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c > index 11fdc70..4164bb2 100644 > --- a/gdb/ada-typeprint.c > +++ b/gdb/ada-typeprint.c > @@ -203,7 +203,7 @@ print_range (struct type *type, struct ui_file *strea= m, > set *N past the bound and its delimiter, if any. */ >=20=20 > static void > -print_range_bound (struct type *type, char *bounds, int *n, > +print_range_bound (struct type *type, const char *bounds, int *n, > struct ui_file *stream) > { > LONGEST B; > @@ -230,8 +230,8 @@ print_range_bound (struct type *type, char *bounds, i= nt *n, > else > { > int bound_len; > - char *bound =3D bounds + *n; > - char *pend; > + const char *bound =3D bounds + *n; > + const char *pend; >=20=20 > pend =3D strstr (bound, "__"); > if (pend =3D=3D NULL) > @@ -300,7 +300,7 @@ print_range_type (struct type *raw_type, struct ui_fi= le *stream, > else > { > int prefix_len =3D subtype_info - name; > - char *bounds_str; > + const char *bounds_str; > int n; >=20=20 > subtype_info +=3D 5; > diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c > index 59d8b0f..b39a113 100644 > --- a/gdb/c-varobj.c > +++ b/gdb/c-varobj.c > @@ -370,7 +370,7 @@ c_describe_child (const struct varobj *parent, int in= dex, >=20=20 > if (cfull_expression) > { > - char *join =3D was_ptr ? "->" : "."; > + const char *join =3D was_ptr ? "->" : "."; >=20=20 > *cfull_expression =3D xstrprintf ("(%s)%s%s", parent_expression, > join, field_name); > @@ -741,7 +741,7 @@ cplus_describe_child (const struct varobj *parent, in= t index, > if (TYPE_CODE (type) =3D=3D TYPE_CODE_STRUCT > || TYPE_CODE (type) =3D=3D TYPE_CODE_UNION) > { > - char *join =3D was_ptr ? "->" : "."; > + const char *join =3D was_ptr ? "->" : "."; >=20=20 > if (CPLUS_FAKE_CHILD (parent)) > { > @@ -825,7 +825,7 @@ cplus_describe_child (const struct varobj *parent, in= t index, >=20=20 > if (cfull_expression) > { > - char *ptr =3D was_ptr ? "*" : ""; > + const char *ptr =3D was_ptr ? "*" : ""; >=20=20 > /* Cast the parent to the base' type. Note that in gdb, > expression like=20 > diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c > index cb201ca..74d2d00 100644 > --- a/gdb/cli/cli-setshow.c > +++ b/gdb/cli/cli-setshow.c > @@ -523,7 +523,7 @@ do_set_command (const char *arg, int from_tty, struct= cmd_list_element *c) > break; > case var_boolean: > { > - char *opt =3D *(int *) c->var ? "on" : "off"; > + const char *opt =3D *(int *) c->var ? "on" : "off"; >=20=20 > observer_notify_command_param_changed (name, opt); > } > diff --git a/gdb/common/gdb_vecs.c b/gdb/common/gdb_vecs.c > index 63766db..f8c3414 100644 > --- a/gdb/common/gdb_vecs.c > +++ b/gdb/common/gdb_vecs.c > @@ -49,7 +49,8 @@ delim_string_to_char_ptr_vec_append (VEC (char_ptr) **v= ecp, > do > { > size_t this_len; > - char *next_field, *this_field; > + const char *next_field; > + char *this_field; >=20=20 > next_field =3D strchr (str, delimiter); > if (next_field =3D=3D NULL) > diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c > index b45f21b..b05ca7e 100644 > --- a/gdb/dwarf2read.c > +++ b/gdb/dwarf2read.c > @@ -9074,7 +9074,7 @@ find_file_and_directory (struct die_info *die, stru= ct dwarf2_cu *cu, > { > /* Irix 6.2 native cc prepends .: to the compilation > directory, get rid of it. */ > - char *cp =3D strchr (*comp_dir, ':'); > + const char *cp =3D strchr (*comp_dir, ':'); >=20=20 > if (cp && cp !=3D *comp_dir && cp[-1] =3D=3D '.' && cp[1] =3D=3D '= /') > *comp_dir =3D cp + 1; > @@ -19239,7 +19239,7 @@ static char * > anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) > { > struct attribute *attr; > - char *base; > + const char *base; >=20=20 > if (die->tag !=3D DW_TAG_class_type && die->tag !=3D DW_TAG_interface_= type > && die->tag !=3D DW_TAG_structure_type && die->tag !=3D DW_TAG_uni= on_type) > @@ -19621,7 +19621,7 @@ dwarf2_name (struct die_info *die, struct dwarf2_= cu *cu) >=20=20 > if (demangled) > { > - char *base; > + const char *base; >=20=20 > /* FIXME: we already did this for the partial symbol... */ > DW_STRING (attr) > diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c > index b962cd3..09e085b 100644 > --- a/gdb/gnu-v3-abi.c > +++ b/gdb/gnu-v3-abi.c > @@ -296,7 +296,7 @@ gnuv3_rtti_type (struct value *value, > const char *class_name; > struct type *run_time_type; > LONGEST offset_to_top; > - char *atsign; > + const char *atsign; >=20=20 > /* We only have RTTI for class objects. */ > if (TYPE_CODE (values_type) !=3D TYPE_CODE_STRUCT) > diff --git a/gdb/go-lang.c b/gdb/go-lang.c > index f6d731b..6e70c89 100644 > --- a/gdb/go-lang.c > +++ b/gdb/go-lang.c > @@ -195,9 +195,9 @@ unpack_mangled_go_symbol (const char *mangled_name, > /* Pointer to "N" if valid "N_" found. */ > char *method_type; > /* Pointer to the first '.'. */ > - char *first_dot; > + const char *first_dot; > /* Pointer to the last '.'. */ > - char *last_dot; > + const char *last_dot; > /* Non-zero if we saw a pointer indicator. */ > int saw_pointer; >=20=20 > diff --git a/gdb/jv-typeprint.c b/gdb/jv-typeprint.c > index 441f313..5bba39c 100644 > --- a/gdb/jv-typeprint.c > +++ b/gdb/jv-typeprint.c > @@ -223,7 +223,8 @@ java_type_print_base (struct type *type, struct ui_fi= le *stream, int show, > for (j =3D 0; j < n_overloads; j++) > { > const char *real_physname; > - char *physname, *p; > + const char *p; > + char *physname; > int is_full_physname_constructor; >=20=20 > real_physname =3D TYPE_FN_FIELD_PHYSNAME (f, j); > diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c > index 485ed6c..ce40b61 100644 > --- a/gdb/ser-tcp.c > +++ b/gdb/ser-tcp.c > @@ -155,7 +155,8 @@ wait_for_connect (struct serial *scb, unsigned int *p= olls) > int > net_open (struct serial *scb, const char *name) > { > - char *port_str, hostname[100]; > + char hostname[100]; > + const char *port_str; > int n, port, tmp; > int use_udp; > struct hostent *hostent; > diff --git a/gdb/symfile.c b/gdb/symfile.c > index 682e3ca..55a9f5c 100644 > --- a/gdb/symfile.c > +++ b/gdb/symfile.c > @@ -2881,7 +2881,7 @@ enum language > deduce_language_from_filename (const char *filename) > { > int i; > - char *cp; > + const char *cp; >=20=20 > if (filename !=3D NULL) > if ((cp =3D strrchr (filename, '.')) !=3D NULL) > diff --git a/gdb/symtab.c b/gdb/symtab.c > index 6c0c3ef..16190c4 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -515,8 +515,8 @@ gdb_mangle_name (struct type *type, int method_id, in= t signature_id) > int is_constructor; > int is_destructor =3D is_destructor_name (physname); > /* Need a new type prefix. */ > - char *const_prefix =3D method->is_const ? "C" : ""; > - char *volatile_prefix =3D method->is_volatile ? "V" : ""; > + const char *const_prefix =3D method->is_const ? "C" : ""; > + const char *volatile_prefix =3D method->is_volatile ? "V" : ""; > char buf[20]; > int len =3D (newname =3D=3D NULL ? 0 : strlen (newname)); >=20=20 > diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c > index 6f81f09..253d7e9 100644 > --- a/gdb/tui/tui-io.c > +++ b/gdb/tui/tui-io.c > @@ -203,7 +203,7 @@ tui_redisplay_readline (void) > int c_line; > int in; > WINDOW *w; > - char *prompt; > + const char *prompt; > int start_line; >=20=20 > /* Detect when we temporarily left SingleKey and now the readline >=20 LGTM.