From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 3yqRI8uJBGCmBgAAWB0awg (envelope-from ) for ; Sun, 17 Jan 2021 14:02:35 -0500 Received: by simark.ca (Postfix, from userid 112) id 822B31EF80; Sun, 17 Jan 2021 14:02:35 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0E60F1E590 for ; Sun, 17 Jan 2021 14:02:35 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65041386F02C; Sun, 17 Jan 2021 19:02:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65041386F02C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1610910154; bh=wu2crFYRvTz+ItZL5NyuQyCTep4tjhNoHnLxD0BVxZw=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=FhA/SHgyoe0pEbP6KOJ5Lzk26XPosxh05f67SqY7+BHKMMVPADx7zokPR7zjnzyPK T3FsPoaIOvUxKrcBwaIxINBndlSRayidO9kwRljXMhA+do50nym2torQaMxqZnSBoC UoZ6iIMjGp0GHwUw6bG0CBmnp2VvbSmgA24ZBiZo= Received: from beryx.lancelotsix.com (beryx.lancelotsix.com [IPv6:2001:41d0:401:3000::1ab3]) by sourceware.org (Postfix) with ESMTPS id DEC2B3850434 for ; Sun, 17 Jan 2021 19:02:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DEC2B3850434 Received: from Plymouth (unknown [IPv6:2a02:390:8443:0:6847:5282:9a8b:b8b7]) by beryx.lancelotsix.com (Postfix) with ESMTPSA id 617A32E071; Sun, 17 Jan 2021 20:02:30 +0100 (CET) Date: Sun, 17 Jan 2021 19:02:27 +0000 To: Marco Barisione Subject: Re: [PATCH 1/4] gdb: add lookup_cmd_exact to simplify a common pattern Message-ID: References: <20210108100706.96190-1-mbarisione@undo.io> <20210108100706.96190-2-mbarisione@undo.io> <20210110000432.GA24151@gwenhwyvar> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (beryx.lancelotsix.com [0.0.0.0]); Sun, 17 Jan 2021 20:02:30 +0100 (CET) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Le Sun, Jan 17, 2021 at 10:47:38AM +0000, Marco Barisione a écrit : > On 10 Jan 2021, at 00:06, Lancelot SIX wrote: > > > > Hi > > > > I just have a few style-related remarks above. > > > > On Fri, Jan 08, 2021 at 10:07:03AM +0000, Marco Barisione via Gdb-patches wrote: > >> +/* See command.h. */ > >> + > >> +struct cmd_list_element * > >> +lookup_cmd_exact (const char *name, > >> + struct cmd_list_element *list, > >> + bool ignore_help_classes) > >> +{ > >> + const char *tem = name; > >> + struct cmd_list_element *cmd = lookup_cmd (&tem, list, "", NULL, -1, > > > > Probably s/NULL/nullptr/ ? > > > >> + ignore_help_classes); > >> + if (cmd && strcmp (name, cmd->name) != 0) > > > > I think gdb prefers explicit comparison to check for null pointers: > > > > https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Comparison_With_NULL_And_Zero > > > > + if (cmd != nullptr && strcmp (name, cmd->name) != 0) > > I tried (but I noticed I didn’t succeed!) to use nullptr and compare > with nullptr in new code or code which already looked like that. > Otherwise, I tried to stick to the style used in nearby code. > > That is, if there's code like this: > foo *bar = NULL; > When adding a new variable on the next line, I would use NULL for > consistency. > > What is the approach used in GDB? > 1. Add new code using the current style even if inconsistent with nearby > code. > 2. Stick to the style of nearby code. > 3. Also update nearby code. > > > -- > Marco Barisione > My personal approach would be to migrate to nullptr slowly but surely, but this is quite personal. I’ll let a more experienced gdb maintainer state what is the prefered way of doing things for the project. Independently of that matter, cmd should be compared to something in this expression. I guess something like + if (cmd != NULL && strcmp (name, cmd->name) != 0) should be ok to maintain consistency. Lancelot.