Re: Python: should gdb.Value array indexing check bounds?

Paul Koning
2011-09-20T16:19:21Z

> From: Matt Rice [mailto:ratmice@gmail.com]
>
> On Tue, Sep 20, 2011 at 9:04 AM, <Paul_Koning@dell.com> wrote:
>> Currently, if a gdb.Value object corresponds to an array, array indexing is done C-style: no bounds checking, just pointer arithmetic. That's somewhat unnatural to Python. Should it do a range check instead, and raise IndexError for out of range index values?
>>
>> That wouldn't affect indexing of pointers, since those don't have a range so the only possible approach is the C one.
>
> I'd think no because of things like:
> http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Zero-Length.html
> (which is possible with non-zero length arrays also).

I suppose that could be handled by making the check not apply in that case. Or the bounds could be made writable? Right now the bounds go with the type, not the value; for them to be writable they would have to go with the value.

Part of my reason for asking is that I'm looking at how to do iterators. In Python you can iterate over a list (array), and I'd like to be able to do that for a gdb.Value which is an array. And come to think of it, that can certainly be done even if the indexing operation itself doesn't honor bounds, but it would be more Pythonically consistent if the range of indexes over which the iterator iterates matches the range of indexes that indexing allows.

paul