From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26657 invoked by alias); 16 Sep 2011 14:55:21 -0000 Received: (qmail 26647 invoked by uid 22791); 16 Sep 2011 14:55:21 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from qmta07.westchester.pa.mail.comcast.net (HELO qmta07.westchester.pa.mail.comcast.net) (76.96.62.64) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Sep 2011 14:55:02 +0000 Received: from omta06.westchester.pa.mail.comcast.net ([76.96.62.51]) by qmta07.westchester.pa.mail.comcast.net with comcast id ZStW1h00816LCl057Sv3a3; Fri, 16 Sep 2011 14:55:03 +0000 Received: from [10.127.238.91] ([65.206.2.68]) by omta06.westchester.pa.mail.comcast.net with comcast id ZSus1h0021U2a2h3SSuu8M; Fri, 16 Sep 2011 14:55:00 +0000 Subject: Re: Python: add field access by name and standard python mapping methods to gdb.Type Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Paul Koning In-Reply-To: Date: Fri, 16 Sep 2011 14:57:00 -0000 Cc: gdb-patches@sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: <0A6582A5-22D0-4284-AE41-DE92F544B650@comcast.net> References: To: pmuldoon@redhat.com 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: 2011-09/txt/msg00306.txt.bz2 On Sep 16, 2011, at 6:45 AM, Phil Muldoon wrote: > Paul Koning writes: >=20 >> ... >=20 >> +typy_getitem (PyObject *self, PyObject *key) >> +{ >> + struct type *type =3D ((type_object *) self)->type; >> + char *field; >> + int i; >> +=20=20 >> + field =3D python_string_to_host_string (key); >> + if (field =3D=3D NULL) >> + return NULL; >> + >> + /* We want just fields of this type, not of base types, so instead of= =20 >> + using lookup_struct_elt_type, portions of that function are >> + copied here. */ >> + >> + for (;;) >> + { >> + CHECK_TYPEDEF (type); >> + if (TYPE_CODE (type) !=3D TYPE_CODE_PTR >> + && TYPE_CODE (type) !=3D TYPE_CODE_REF) >> + break; >> + type =3D TYPE_TARGET_TYPE (type); >> + } >=20 > This gives me pause, not because it is wrong, but because I wonder if > there is a possibility that this loop will never exit. I presume it > will eventually find the base_type, just by continually walking the > TARGET_TYPE until it reaches bottom.=20=20 >=20 > Can you check how this is done in other parts of GDB (this must happen > quite often?). This code was directly lifted from lookup_struct_elt_type in gdbtypes.c Th= e same sort of thing occurs in a number of other places, as you expected. = For example, in c_value_of_variable in varobj.c, a similar loop shows up bu= t that one just strips TYPE_CODE_REF, it does not look for TYPE_CODE_PTR. I can certainly make this a standard function, perhaps in gdbtypes.c. Then= I can also change other occurrences of this code pattern to call that, but= I would not want to go use it for things that are similar but not identica= l (like the one in varobj.c I mentioned). Should that be a separate patch?= It seems better that way. paul