From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55214 invoked by alias); 26 Oct 2015 05:24:15 -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 55194 invoked by uid 89); 26 Oct 2015 05:24:14 -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,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f49.google.com Received: from mail-pa0-f49.google.com (HELO mail-pa0-f49.google.com) (209.85.220.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 26 Oct 2015 05:24:13 +0000 Received: by padhk11 with SMTP id hk11so177006394pad.1 for ; Sun, 25 Oct 2015 22:24:11 -0700 (PDT) X-Received: by 10.66.255.3 with SMTP id am3mr20489921pad.120.1445837051001; Sun, 25 Oct 2015 22:24:11 -0700 (PDT) Received: from seba.sebabeach.org.gmail.com (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by smtp.gmail.com with ESMTPSA id qd5sm31364957pbc.73.2015.10.25.22.24.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Oct 2015 22:24:10 -0700 (PDT) From: Doug Evans To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH c++ 05/12] guile: Constify gdbscm_with_guile return value References: <1445831204-16588-1-git-send-email-simon.marchi@polymtl.ca> <1445831204-16588-5-git-send-email-simon.marchi@polymtl.ca> Date: Mon, 26 Oct 2015 11:45:00 -0000 In-Reply-To: <1445831204-16588-5-git-send-email-simon.marchi@polymtl.ca> (Simon Marchi's message of "Sun, 25 Oct 2015 23:46:37 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-10/txt/msg00544.txt.bz2 Simon Marchi writes: > Initially fixess: > > /home/simark/src/binutils-gdb/gdb/guile/scm-disasm.c: In function =E2=80= =98void* gdbscm_disasm_read_memory_worker(void*)=E2=80=99: > /home/simark/src/binutils-gdb/gdb/guile/scm-disasm.c:93:12: error: invali= d conversion from =E2=80=98const void*=E2=80=99 to =E2=80=98void*=E2=80=99 = [-fpermissive] > return "seek error"; > > This makes const the whole path that leads to the return of > gdbscm_with_guile. > > gdb/ChangeLog: > > * guile/guile-internal.h (gdbscm_with_guile): Constify function > pointer return value and self return value. > * guile/scm-safe-call.c (gdbscm_with_guile): Likewise. > (struct c_data) : Constify return value. > (struct c_data) : Constify. > (scscm_eval_scheme_string): Constify return value. > (gdbscm_safe_eval_string): Constify status variable. > (scscm_source_scheme_script): Constify return value. > (gdbscm_safe_source_script): Constify status variable. > * guile/scm-disasm.c (gdbscm_disasm_read_memory_worker): > Constify returrn value. > (gdbscm_disasm_read_memory): Constify status variable. Hi. How about instead having gdbscm_with_guile return a const char *. That should, for example, remove the need for any cast here in gdbscm_safe_source_script (and presumably elsewhere): if (result !=3D NULL) return xstrdup ((char *) result); > > diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h > index 017309a..0af01d2 100644 > --- a/gdb/guile/guile-internal.h > +++ b/gdb/guile/guile-internal.h > @@ -384,7 +384,7 @@ extern void gdbscm_memory_error (const char *subr, co= nst char *msg, SCM args) >=20=20 > /* scm-safe-call.c */ >=20=20 > -extern void *gdbscm_with_guile (void *(*func) (void *), void *data); > +extern const void *gdbscm_with_guile (const void *(*func) (void *), void= *data); >=20=20 > extern SCM gdbscm_call_guile (SCM (*func) (void *), void *data, > excp_matcher_func *ok_excps); > diff --git a/gdb/guile/scm-disasm.c b/gdb/guile/scm-disasm.c > index d1572c7..63889c1 100644 > --- a/gdb/guile/scm-disasm.c > +++ b/gdb/guile/scm-disasm.c > @@ -76,7 +76,7 @@ dascm_make_insn (CORE_ADDR pc, const char *assembly, in= t insn_len) > Scheme port. Called via gdbscm_call_guile. > The result is a statically allocated error message or NULL if success= . */ >=20=20 > -static void * > +static const void * > gdbscm_disasm_read_memory_worker (void *datap) > { > struct gdbscm_disasm_read_data *data > @@ -109,7 +109,7 @@ gdbscm_disasm_read_memory (bfd_vma memaddr, bfd_byte = *myaddr, > struct disassemble_info *dinfo) > { > struct gdbscm_disasm_read_data data; > - void *status; > + const void *status; >=20=20 > data.memaddr =3D memaddr; > data.myaddr =3D myaddr; > diff --git a/gdb/guile/scm-safe-call.c b/gdb/guile/scm-safe-call.c > index 62aec0f..85a2a5b 100644 > --- a/gdb/guile/scm-safe-call.c > +++ b/gdb/guile/scm-safe-call.c > @@ -28,10 +28,10 @@ >=20=20 > struct c_data > { > - void *(*func) (void *); > + const void *(*func) (void *); > void *data; > /* An error message or NULL for success. */ > - void *result; > + const void *result; > }; >=20=20 > /* Struct to marshall args through gdbscm_with_catch. */ > @@ -167,8 +167,8 @@ gdbscm_with_catch (void *data) > The result if NULL if no exception occurred, otherwise it is a static= ally > allocated error message (caller must *not* free). */ >=20=20 > -void * > -gdbscm_with_guile (void *(*func) (void *), void *data) > +const void * > +gdbscm_with_guile (const void *(*func) (void *), void *data) > { > struct c_data c_data; > struct with_catch_data catch_data; > @@ -369,7 +369,7 @@ struct eval_scheme_string_data > /* Wrapper to eval a C string in the Guile interpreter. > This is passed to gdbscm_with_guile. */ >=20=20 > -static void * > +static const void * > scscm_eval_scheme_string (void *datap) > { > struct eval_scheme_string_data *data > @@ -398,12 +398,12 @@ char * > gdbscm_safe_eval_string (const char *string, int display_result) > { > struct eval_scheme_string_data data =3D { string, display_result }; > - void *result; > + const void *result; >=20=20 > result =3D gdbscm_with_guile (scscm_eval_scheme_string, (void *) &data= ); >=20=20 > if (result !=3D NULL) > - return xstrdup ((char *) result); > + return xstrdup ((const char *) result); > return NULL; > } > =0C > @@ -411,7 +411,7 @@ gdbscm_safe_eval_string (const char *string, int disp= lay_result) >=20=20 > /* Helper function for gdbscm_safe_source_scheme_script. */ >=20=20 > -static void * > +static const void * > scscm_source_scheme_script (void *data) > { > const char *filename =3D (const char *) data; > @@ -439,7 +439,7 @@ gdbscm_safe_source_script (const char *filename) > by default. This function is invoked by the "source" GDB command w= hich > already has its own path search support. */ > char *abs_filename =3D NULL; > - void *result; > + const void *result; >=20=20 > if (!IS_ABSOLUTE_PATH (filename)) > { > @@ -452,7 +452,7 @@ gdbscm_safe_source_script (const char *filename) >=20=20 > xfree (abs_filename); > if (result !=3D NULL) > - return xstrdup ((char *) result); > + return xstrdup ((const char *) result); > return NULL; > } > =0C