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 4/6] Constify some parameters in the varobj code



On 15-02-03 11:55 AM, Pedro Alves wrote:
> On 01/29/2015 08:28 PM, Simon Marchi wrote:
>> To make it clear that some functions should not modify the variable
>> object, this patch adds the const qualifier where it makes sense to some
>> struct varobj * parameters. Most getters should take a const pointer to
>> guarantee they don't modify the object.
>>
>> Unfortunately, I couldn't add it to some callbacks (such as name_of_child).
>> In the C implementation, they call c_describe_child, which calls
>> varobj_get_path_expr. varobj_get_path_expr needs to modify the object in
>> order to cache the computed value. It therefore can't take a const
>> pointer, and it affects the whole call chain. I suppose that's where you
>> would use a "mutable" in C++.
> 
> FYI, in these cases it's totally fine to have the function take a const pointer,
> and then cast away the const inside the function.  We do exactly that in
> a few places.  E.g.:
> 
> /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
>    in the language-specific part of GSYMBOL, if it has not been
>    previously computed.  Tries to save the decoded name in the same
>    obstack as GSYMBOL, if possible, and otherwise on the heap (so that,
>    in any case, the decoded symbol has a lifetime at least that of
>    GSYMBOL).
>    The GSYMBOL parameter is "mutable" in the C++ sense: logically
>    const, but nevertheless modified to a semantically equivalent form
>    when a decoded name is cached in it.  */
> 
> const char *
> ada_decode_symbol (const struct general_symbol_info *arg)
> {
>   struct general_symbol_info *gsymbol = (struct general_symbol_info *) arg;
> ...
> 
> Thanks,
> Pedro Alves

Thanks for the tip! I'll do it soon.


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