From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1029 invoked by alias); 20 Sep 2011 16:19:21 -0000 Received: (qmail 1017 invoked by uid 22791); 20 Sep 2011 16:19:17 -0000 X-SWARE-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,FREEMAIL_REPLY,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from qmta02.emeryville.ca.mail.comcast.net (HELO qmta02.emeryville.ca.mail.comcast.net) (76.96.30.24) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Sep 2011 16:19:03 +0000 Received: from omta23.emeryville.ca.mail.comcast.net ([76.96.30.90]) by qmta02.emeryville.ca.mail.comcast.net with comcast id b47R1h0061wfjNsA24JxZ3; Tue, 20 Sep 2011 16:18:57 +0000 Received: from [10.127.238.91] ([65.206.2.68]) by omta23.emeryville.ca.mail.comcast.net with comcast id b4E01h01l1U2a2h8j4E3Dz; Tue, 20 Sep 2011 16:14:09 +0000 Subject: Re: Python: should gdb.Value array indexing check bounds? Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Paul Koning In-Reply-To: <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM> Date: Tue, 20 Sep 2011 16:19:00 -0000 Cc: gdb@sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: <7A2DB38D-692D-4E15-BBCE-EFFD115F47DA@comcast.net> References: <09787EF419216C41A903FD14EE5506DD03094C6D5D@AUSX7MCPC103.AMER.DELL.COM> <09787EF419216C41A903FD14EE5506DD03094C6D7D@AUSX7MCPC103.AMER.DELL.COM> To: ratmice@gmail.com Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-09/txt/msg00071.txt.bz2 > From: Matt Rice [mailto:ratmice@gmail.com]=20 >=20 > On Tue, Sep 20, 2011 at 9:04 AM, 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 some= what unnatural to Python. Should it do a range check instead, and raise In= dexError for out of range index values? >>=20 >> That wouldn't affect indexing of pointers, since those don't have a rang= e so the only possible approach is the C one. >=20 > 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 t= ype, 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. I= n 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 boun= ds, but it would be more Pythonically consistent if the range of indexes ov= er which the iterator iterates matches the range of indexes that indexing a= llows. paul