From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mHmQIKOsDmC6fgAAWB0awg (envelope-from ) for ; Mon, 25 Jan 2021 06:33:55 -0500 Received: by simark.ca (Postfix, from userid 112) id 711A51EF80; Mon, 25 Jan 2021 06:33:55 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [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 91D691E940 for ; Mon, 25 Jan 2021 06:33:54 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D919F3840C23; Mon, 25 Jan 2021 11:33:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D919F3840C23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611574433; bh=DqelbTB8ZH81vIpWgKDIaGIno/zvhhD1KshRgPz4EQw=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lKk/8jVMsebgZn9Tg60R4To0tkJjhysy0BytV7VdEtwlTa+BL7UKERnUlbmpe5oy5 dLuCm27fBiyeqf+UuIr4cbSErWUslI1sgDjhUgJDMS5hnyjeutLjD3/qWTE6V6NqPg CNh/lJw8DYMzTY+hfsaarCje3f026E7GIEP/byp0= Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id 67D263840C22 for ; Mon, 25 Jan 2021 11:33:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 67D263840C22 Received: by mail-qk1-x72a.google.com with SMTP id n7so765159qkc.4 for ; Mon, 25 Jan 2021 03:33:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DqelbTB8ZH81vIpWgKDIaGIno/zvhhD1KshRgPz4EQw=; b=oJBnI3Aa8ClfDgFs45wRjotNYqFHykbVlt+1daGWyYfIby83B+AuhmpSJeN1Ea0FXb g/Y4FrpwIDncvJcYdtPdLXe8K5LiRsWOlL0RSdPAopnuUrJduCHEj+loN3S8N6+yVMTA sBYNqiATwjWnsnuXMH0hLVmpP5mdFgEWwjlRw+9WpE0kXIf3tfDxxZX5c/u8XO0JyQBu W+CDle2u0xqNNgBZBo5MKYgE/nzZSZPSFNtkIX+fg90DhYu26jqmw8FihrSGhfFagdZ5 OCLjpIy3lZmbheNO05I9hKl4g9/T852qulWASJBuHCd9P/N+2I43K2ZNi3GWAHrKi1sO cpWQ== X-Gm-Message-State: AOAM531WGAE919KOs1f0XRkTDHjLCpWRAz7WZuYC43vxAspZr1ytmlPH zF5u/qJE/r1PY5TKKBrMfB0ZMhlpqFi/cw== X-Google-Smtp-Source: ABdhPJwYfBtfNtKLycH7lLUL7kmPpK/iaSN2JA+ChGTgtHw88ZDGbalQNxxJrC5TbyCN6FF+pD/1yw== X-Received: by 2002:a37:bc07:: with SMTP id m7mr208784qkf.438.1611574430983; Mon, 25 Jan 2021 03:33:50 -0800 (PST) Received: from ?IPv6:2804:7f0:8284:874d:fc80:9138:c52e:e4ca? ([2804:7f0:8284:874d:fc80:9138:c52e:e4ca]) by smtp.gmail.com with ESMTPSA id 199sm1794396qkm.126.2021.01.25.03.33.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Jan 2021 03:33:50 -0800 (PST) Subject: Re: [PATCH 1/4] gdb: add lookup_cmd_exact to simplify a common pattern To: Lancelot SIX , Marco Barisione References: <20210108100706.96190-1-mbarisione@undo.io> <20210108100706.96190-2-mbarisione@undo.io> <20210110000432.GA24151@gwenhwyvar> Message-ID: <3629b1ca-3133-1358-19be-3326adc4fc87@linaro.org> Date: Mon, 25 Jan 2021 08:33:47 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit 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: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 1/17/21 4:02 PM, Lancelot SIX via Gdb-patches wrote: > 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. You should use the new style. So nullptr should be used here and throughout your patch series, 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. >