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] Convert 'name' of 'struct varobj' to 'const char *'.


>>>>> "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


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