public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Paul Koning <paulkoning@comcast.net>
To: ratmice@gmail.com
Cc: gdb@sourceware.org
Subject: Re: Python: should gdb.Value array indexing check bounds?
Date: Tue, 20 Sep 2011 16:19:00 -0000	[thread overview]
Message-ID: <7A2DB38D-692D-4E15-BBCE-EFFD115F47DA@comcast.net> (raw)
In-Reply-To: <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM>

> 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

  parent reply	other threads:[~2011-09-20 16:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20 16:05 Paul_Koning
2011-09-20 16:12 ` Matt Rice
     [not found]   ` <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM>
2011-09-20 16:19     ` Paul Koning [this message]
2011-10-05 18:08       ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7A2DB38D-692D-4E15-BBCE-EFFD115F47DA@comcast.net \
    --to=paulkoning@comcast.net \
    --cc=gdb@sourceware.org \
    --cc=ratmice@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).