This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC][patch 2/9] export values mechanism to Python
- From: Daniel Jacobowitz <drow at false dot org>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: Thiago Jung Bauermann <bauerman at br dot ibm dot com>, gdb-patches at sourceware dot org
- Date: Fri, 25 Jul 2008 22:54:25 -0400
- Subject: Re: [RFC][patch 2/9] export values mechanism to Python
- References: <20080429155212.444237503@br.ibm.com> <20080429155304.466637516@br.ibm.com> <20080528212451.GB2969@caradoc.them.org> <m3k5h78j64.fsf@fleche.redhat.com> <1215410598.1795.58.camel@localhost.localdomain> <m3lk0d9s4o.fsf@fleche.redhat.com>
On Mon, Jul 07, 2008 at 05:44:23PM -0600, Tom Tromey wrote:
> Thiago> In the case of valpy_get_element (which is used to access an element in
> Thiago> a value representing a struct or class), using __getitem__ means that in
> Thiago> Python one would use a_struct["element"] to access a_struct.element.
> Thiago> This looks a bit strange at least.
>
> I don't mind this, my reasoning is:
>
> * I suspect it will be more common to use a string-valued expression
> here than it will be to use a string constant.
I don't know about that... If we have a foo and want to
determine what sort of foo it is, we'll want foo.type and foo.subtype;
in other words I expect pretty-printers to use lots of fixed-name
members.
> * This approach also works nicely for arrays.
> * This approach does not mix the Value namespace with the
> debuggee's field names.
I thought about making both approaches work. It is tecnically easy;
if we use __getattr__, then foo.field will work - unless field is
ambiguous with a value method, which will take priority. foo["field"]
will always work. But if we provide this then script writers will use
it which will be a problem if we ever added methods.
So, it only makes sense if we plan to have no instance methods for
values. You'd know better than I do whether instance methods are
likely to be useful here.
--
Daniel Jacobowitz
CodeSourcery