From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5875 invoked by alias); 10 Apr 2012 22:01:08 -0000 Received: (qmail 5848 invoked by uid 22791); 10 Apr 2012 22:01:06 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Apr 2012 22:00:50 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3AM0lmr019393 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 Apr 2012 18:00:47 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3AM0jc3005151 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 10 Apr 2012 18:00:46 -0400 From: Tom Tromey To: Siva Chandra Cc: Eli Zaretskii , gdb-patches@sourceware.org Subject: Re: [RFC - Python Scripting] New method gdb.Symtab.blocks_iterator - docs included References: <87mx6k4b9t.fsf@fleche.redhat.com> Date: Tue, 10 Apr 2012 22:21:00 -0000 In-Reply-To: (Siva Chandra's message of "Tue, 10 Apr 2012 13:14:28 +0530") Message-ID: <87398b4582.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.95 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-04/txt/msg00197.txt.bz2 >>>>> "Siva" =3D=3D Siva Chandra writes: Siva> I have picked Symtab.blocks. I personally don't like making Symtab Siva> iterable as blocks are just one of them. Doug's note made me start wondering why iterating over all the blocks made sense here -- and now I tend to think it doesn't. I think it would be a bit more future-proof to just let the user access the symtab's global and static blocks, then rely on iteration over symbols within a block. This would mean also adding a way to fetch a block's subblocks. The reason I see this as more future-proof is that I think the block structure, including global and static blocks, is a feature of the underlying problem. So, it is much less likely to change if we need to refactor symtabs or blocks. (And, in fact, my lazy block-reading code would have mild problems with your iterator, but no troubles at all in this approach.) Sorry about this change of mind... Siva> + =C2=A0 block_object =3D block_to_block_object (block, symtab->objfi= le); Siva> + =C2=A0 if (! block_object) Siva> + =C2=A0 =C2=A0 { Siva> + =C2=A0 =C2=A0 =C2=A0 PyErr_SetString (PyExc_RuntimeError, Siva> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0_("Unable to get the next gdb.Block object.")); Tom> If block_to_block_object fails, then the error will already be set. Tom> I think it is generally better to propagate the original exception in Tom> cases like this. =C2=A0Otherwise, the new exception may obscure some m= ore Tom> fundamental error. Siva> block_to_block_object just returns NULL on failure. Am I missing Siva> something? If it returns NULL then it has already set the Python exception. This is a Python coding convention that we follow in many places. E.g., in block_to_block_object, the NULL return can only happen if PyObject_New fails; but if that fails and returns NULL, then it is guaranteed to have set the exception; and therefore the same is true for block_to_block_object. Siva> + =C2=A0 (iter->iter_index)++; Tom> Also I'm curious if an error should invalidate the iterator in some wa= y. Siva> Since the iterator exists only in Python environment, my opinion is Siva> that if the iterator gets invalidated, the execution should never Siva> reach this place. Do you see something else? Can't the caller ignore the error and call iter.next again? But I think it probably doesn't matter. The best thing would be to see if there is some Python standard here; if so, follow it; if not, do whatever is convenient. Tom