[RFC][patch 2/9] export values mechanism to Python
Daniel Jacobowitz
drow@false.org
Sat Jul 26 02:55:00 GMT 2008
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
More information about the Gdb-patches
mailing list