This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH c++ 05/12] guile: Constify gdbscm_with_guile return value
- From: Simon Marchi <simon dot marchi at polymtl dot ca>
- To: Doug Evans <xdje42 at gmail dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 26 Oct 2015 11:09:08 -0400
- Subject: Re: [PATCH c++ 05/12] guile: Constify gdbscm_with_guile return value
- Authentication-results: sourceware.org; auth=none
- References: <1445831204-16588-1-git-send-email-simon dot marchi at polymtl dot ca> <1445831204-16588-5-git-send-email-simon dot marchi at polymtl dot ca> <m3k2qab3v4 dot fsf at sspiff dot org>
On 26 October 2015 at 01:22, Doug Evans <xdje42@gmail.com> wrote:
> 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 != NULL)
Hmmm, looking more at the issue, I see that we happen to call
gdbscm_with_guile only with functions that return const char *. But
it doesn't mean we should make gdbscm_with_guile return const char *
ncecessarily. It (and scm_with_guile) takes a void* and returns a
void* in order to be generic, just like in the pthread_create/join
API. The caller is responsible to cast the void* to the right type.
In C++, we could always get fancy and make it a templated function to
get type-safety.
So in retrospect, I think we should leave the original return type
(non-const void*) and just add the appropriate casts.
Does that make sense?