From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10177 invoked by alias); 11 Sep 2018 09:58:26 -0000 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 Received: (qmail 10168 invoked by uid 89); 11 Sep 2018 09:58:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=resize, day X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Sep 2018 09:58:25 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w8B9wI1b021667 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 11 Sep 2018 05:58:23 -0400 Received: by simark.ca (Postfix, from userid 112) id 6A34E1E5A4; Tue, 11 Sep 2018 05:58:18 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 8E0731E16B; Tue, 11 Sep 2018 05:58:17 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 11 Sep 2018 09:58:00 -0000 From: Simon Marchi To: Joel Brobecker Cc: gdb-patches@sourceware.org, Jerome Guitton Subject: Re: [RFA v2] arm-pikeos: software single step In-Reply-To: <20180911085612.GA3379@adacore.com> References: <20180910174345.GD3234@adacore.com> <1536604744-3814-1-git-send-email-y> <20180911085612.GA3379@adacore.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00315.txt.bz2 On 2018-09-11 09:56, Joel Brobecker wrote: >> > + symbol_table = (asymbol **) xmalloc (storage_needed); >> > + make_cleanup (xfree, symbol_table); >> >> It would make Tom really happy if you could avoid introducing a >> cleanup :). >> I would suggest using an std::vector. If you'd rather not >> do it >> it's not a big deal, we can change it after. > > Attached is the patch I am testing. I am wondering if this is the best > way, though. What do you think? It looks good to me. You could use a range-for, because it's cool: for (asymbol *sym : symbol_table) but what you have is also fine. > One question I asked myself is whether we needed the std::vector at > all, as the building of the vector is a bit clunky in this situation. > As I understand it, this is mostly to automate the destruction of > the array. I was wondering whether we could do without the std::vector > entirely, and just handle the array without a cleanup, since the code > is simple enough that we can make sure it doesn't throw (I was hoping > that eg marking the function noexcept would help guaranty that). But > at the end of the day, although it's manageable in this case, I felt > it was better to go with the safer approach. Well, it would be fine to not use a vector, but in any case I would recommend the use of an object that ensures the memory is de-allocated in any case, whether it is an std::vector, an std::unique_ptr or a gdb::unique_xmalloc_ptr. I don't see any advantage of doing a manual free over using one of those. An alternative would be to use a VLA: asymbol *symbol_table[max_number_of_symbols]; which I think ends up being like an alloca. But in this case there could be a huge number of symbols I suppose, so I would avoid that. > Same remark with resizing the array: In practice, we don't need to do > it since we know the bounds and iterate over the elements without > accessing the them from the vector; but it's clearer and safer this > way. Right, with the range-for you would need the resize though. Simon