This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH c++ 05/12] guile: Constify gdbscm_with_guile return value


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]