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: Doug Evans <xdje42 at gmail dot com>
- To: Simon Marchi <simon dot marchi at polymtl dot ca>
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 26 Oct 2015 09:21:07 -0700
- 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> <CAFXXi0kxpDNB7EwPK-ot4qFBetPxgENbknD8861EB3mvF_vZTw at mail dot gmail dot com>
Simon Marchi <simon.marchi@polymtl.ca> writes:
> 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?
The function comment for gdbscm_with_guile says:
/* A wrapper around scm_with_guile that prints backtraces and exceptions
according to "set guile print-stack".
The result if NULL if no exception occurred, otherwise it is a statically
allocated error message (caller must *not* free). */
If we're going to return an error message,
why make it a void * and not a char * (const as appropriate)?
The lower level guile API uses a void * because it doesn't specify what
the result is. But in this use of it we do specify what the result is.