[PATCH] Convert 'name' of 'struct varobj' to 'const char *'.

Tom Tromey tromey@redhat.com
Fri Aug 30 16:20:00 GMT 2013


>>>>> "Yao" == Yao Qi <yao@codesourcery.com> writes:

Yao> This patch is to change the type of field 'name' of 'struct varobj'
Yao> from 'char *' to 'const char *'.

It's tempting to do this but I think the new casts tell us that
something fishy is going on.

Yao>  struct varobj *
Yao> -varobj_create (char *objname,
Yao> -	       char *expression, CORE_ADDR frame, enum varobj_type type)
Yao> +varobj_create (char *objname, const char *expression, CORE_ADDR frame,
Yao> +	       enum varobj_type type)

Here we're claiming that this takes a const char *.

Yao> -  xfree (var->name);
Yao> +  xfree ((void *) var->name);

But here we cast away const to free the object.

I think this means the object wasn't "really const".  It's an
abstraction violation.

A different approach might be to change varobj_create to accept a const,
and then xstrdup it there.  But then the field still could not really be
const.

Tom



More information about the Gdb-patches mailing list