From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2678 invoked by alias); 11 Jan 2013 18:02:28 -0000 Received: (qmail 2648 invoked by uid 22791); 11 Jan 2013 18:02:25 -0000 X-SWARE-Spam-Status: No, hits=-7.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_BJ 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; Fri, 11 Jan 2013 18:02:16 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0BI1lEx030232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 11 Jan 2013 13:01:55 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0BI1j28012508; Fri, 11 Jan 2013 13:01:46 -0500 Message-ID: <50F05388.2090408@redhat.com> Date: Fri, 11 Jan 2013 18:02:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Joel Brobecker CC: Yao Qi , gdb-patches@sourceware.org Subject: Re: [PATCH] Don't check PST is NULL in read_symtab References: <1357869440-23451-1-git-send-email-yao@codesourcery.com> <20130111045233.GK6143@adacore.com> <50F025B5.2060203@codesourcery.com> <20130111150537.GM6143@adacore.com> In-Reply-To: <20130111150537.GM6143@adacore.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 2013-01/txt/msg00238.txt.bz2 On 01/11/2013 03:05 PM, Joel Brobecker wrote: >> IMO, we don't need an assertion to check PST, because the function is >> used in this way, >> >> (*pst->read_symtab) (objfile, pst); > > I am fine without the assertion as well. But if we followed your > argument, we would never need an assertion. For me, assertions > achieve two goals: > 1. Clearly document an expectation; > 2. Cause a semi-friendly abortion, rather than a mysterious behavior > or crash. > As of today, the way this function is called indeed guarantees that > PST is never NULL. But someone adding a call at a later date might > introduce a bug and cause it to be called with PST == NULL... FWIW, I agree with both of you. I agree with assertion's roles. But I also agree with Yao that for functions that implement a class-like interface and take a "this" pointer, there's no need to sprinkle the codebase with "gdb_assert (self != NULL)" checks. BUT (!), when reading one of those functions, it's a bit more obvious and self-describing that the function takes a "this"-style pointer when the parameter is actually called "self", and / or at least is the first parameter in the function's signature. Like: static void dbx_psymtab_to_symtab_1 (struct objfile *objfile, struct partial_symtab *pst) { static void dbx_psymtab_to_symtab_1 (struct partial_symtab *pst, struct objfile *objfile) { static void dbx_psymtab_to_symtab_1 (struct partial_symtab *self, struct objfile *objfile) { (It'd be even better for grepability/readability if the implementations and hook name agreed, like: - result->read_symtab = dbx_psymtab_to_symtab; + result->read_symtab = dbx_read_symtab; or - result->read_symtab = dbx_psymtab_to_symtab; + result->psymtab_to_symtab = dbx_psymtab_to_symtab; ... ) -- Pedro Alves