This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 4/6] Constify some parameters in the varobj code
- From: Pedro Alves <palves at redhat dot com>
- To: Simon Marchi <simon dot marchi at ericsson dot com>, gdb-patches at sourceware dot org
- Date: Tue, 03 Feb 2015 17:55:41 +0100
- Subject: Re: [PATCH 4/6] Constify some parameters in the varobj code
- Authentication-results: sourceware.org; auth=none
- References: <1422559716-5480-1-git-send-email-simon dot marchi at ericsson dot com> <1422559716-5480-4-git-send-email-simon dot marchi at ericsson dot com>
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