* Python: should gdb.Value array indexing check bounds? @ 2011-09-20 16:05 Paul_Koning 2011-09-20 16:12 ` Matt Rice 0 siblings, 1 reply; 4+ messages in thread From: Paul_Koning @ 2011-09-20 16:05 UTC (permalink / raw) To: gdb 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. paul ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Python: should gdb.Value array indexing check bounds? 2011-09-20 16:05 Python: should gdb.Value array indexing check bounds? Paul_Koning @ 2011-09-20 16:12 ` Matt Rice [not found] ` <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM> 0 siblings, 1 reply; 4+ messages in thread From: Matt Rice @ 2011-09-20 16:12 UTC (permalink / raw) To: Paul_Koning; +Cc: gdb 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). ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM>]
* Re: Python: should gdb.Value array indexing check bounds? [not found] ` <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM> @ 2011-09-20 16:19 ` Paul Koning 2011-10-05 18:08 ` Tom Tromey 0 siblings, 1 reply; 4+ messages in thread From: Paul Koning @ 2011-09-20 16:19 UTC (permalink / raw) To: ratmice; +Cc: gdb > 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Python: should gdb.Value array indexing check bounds? 2011-09-20 16:19 ` Paul Koning @ 2011-10-05 18:08 ` Tom Tromey 0 siblings, 0 replies; 4+ messages in thread From: Tom Tromey @ 2011-10-05 18:08 UTC (permalink / raw) To: Paul Koning; +Cc: ratmice, gdb >>>>> "Paul" == Paul Koning <paulkoning@comcast.net> writes: Paul> Currently, if a gdb.Value object corresponds to an array, array Paul> indexing is done C-style: no bounds checking, just pointer Paul> arithmetic. That's somewhat unnatural to Python. Should it do a Paul> range check instead, and raise IndexError for out of range index Paul> values? I think it would be good if the bad cases could somehow be avoided. Matt> I'd think no because of things like: Matt> http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Zero-Length.html Matt> (which is possible with non-zero length arrays also). Paul> I suppose that could be handled by making the check not apply in that Paul> case. I think there are other bad cases -- e.g., the classic C struct hack uses an array with 1 element. Paul> Or the bounds could be made writable? Right now the bounds go Paul> with the type, not the value; for them to be writable they would have Paul> to go with the value. This sounds like Jan's VLA patchset. I'm not sure how rewriting the bounds would work in practice. I guess you could just cast the array to a pointer today. Tom ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-10-05 18:08 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-09-20 16:05 Python: should gdb.Value array indexing check bounds? Paul_Koning 2011-09-20 16:12 ` Matt Rice [not found] ` <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM> 2011-09-20 16:19 ` Paul Koning 2011-10-05 18:08 ` Tom Tromey
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).