From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12663 invoked by alias); 9 Nov 2011 01:53:39 -0000 Received: (qmail 12649 invoked by uid 22791); 9 Nov 2011 01:53:34 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from qmta14.emeryville.ca.mail.comcast.net (HELO qmta14.emeryville.ca.mail.comcast.net) (76.96.27.212) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Nov 2011 01:53:21 +0000 Received: from omta07.emeryville.ca.mail.comcast.net ([76.96.30.59]) by qmta14.emeryville.ca.mail.comcast.net with comcast id upsr1h0051GXsucAEptEbB; Wed, 09 Nov 2011 01:53:14 +0000 Received: from [192.168.10.125] ([24.218.185.35]) by omta07.emeryville.ca.mail.comcast.net with comcast id upj31h0150mEv9C8Upj3kt; Wed, 09 Nov 2011 01:43:04 +0000 Subject: Re: [RFA] Python: raise exception on field-related gdb.Type methods if it's not struct or union Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Paul Koning In-Reply-To: Date: Wed, 09 Nov 2011 01:53:00 -0000 Cc: Eli Zaretskii , tromey@redhat.com, gdb-patches@sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <3A3AF5AE-70E8-43D0-B8CE-DCADFEEF879A@comcast.net> <560557F2-1B8B-4633-8CD6-E63705EEAF0E@comcast.net> <83wrckrcg1.fsf@gnu.org> <37B202A1-DCD5-423E-8E30-55A6F2BE21EF@comcast.net> To: Doug Evans 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-11/txt/msg00215.txt.bz2 On Nov 8, 2011, at 7:29 PM, Doug Evans wrote: > On Tue, Nov 8, 2011 at 1:40 PM, Paul Koning wrot= e: >> ... >> I found the answer to that question with a bit of searching. Attached = is a patch that raises an exception (TypeError) for len() and all the field= reference methods if the type isn't struct or union. >=20 > I wasn't sure using as_number here was kosher. "works for me" if it > does the job. Yes, the book (Python Reference) says that if __nonzero__ is defined (which= is what this does) then that is used for truth testing, otherwise __len__ = is, and if neither is defined then the thing in question is always True. >=20 >> Does this need new testcases? >=20 > Yeah, I think so. > Verify "not type" DTRT, and affected operations on scalar types flag > the right error. >=20 > One question I have is: for struct types that have an empty field list > (say an empty struct), what's the result of "not type". True or > False? I can argue either way, and I'm not sure what's the best > answer, long term. > [But then again, my python fu isn't enough to be comfortable with any > conclusion I reach.] The way I wrote it, a truth test on a gdb.Type object is always True, so th= e answer to the question is "False". It doesn't matter if the type is scal= ar, or struct, or for struct whether it has fields or not. The Python Refe= rence says that objects that define neither a nonzero nor a len operation a= re always True. That applies, for example, to the Python builtin object "t= ype", and since gdb.Type is vaguely like "type" I figured the same behavior= should apply.=20=20 >=20 > Thanks very much for doing this! >=20 > btw, a couple of nits: > 1) Please put a blank line between a function's comment and its definitio= n. > There are several occurrences of this. Oops, yes, I should have remembered that. > 2) Can you rename typy_deref? typy_get_struct works for me, I'm sure > there's a better name. > "deref" feels confusing, one can deref a pointer to anything, not > just structs/unions, and > the function doesn't necessarily do a dereference. I like the name you mentioned. Will do. paul