From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36585 invoked by alias); 2 Jun 2017 19:22:46 -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 36452 invoked by uid 89); 2 Jun 2017 19:22:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00,KAM_STOCKGEN,RP_MATCHES_RCVD,SPF_HELO_PASS,T_FILL_THIS_FORM_SHORT autolearn=no version=3.3.2 spammy=pains X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Jun 2017 19:22:44 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61B77334584; Fri, 2 Jun 2017 19:22:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 61B77334584 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 61B77334584 Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB55460A99; Fri, 2 Jun 2017 19:22:46 +0000 (UTC) Subject: Re: [RFA 15/23] Use std::vector to avoid cleanups To: Tom Tromey , gdb-patches@sourceware.org References: <20170503224626.2818-1-tom@tromey.com> <20170503224626.2818-16-tom@tromey.com> From: Pedro Alves Message-ID: <51da6cfd-42c9-536b-17b0-dbd9998e0ff4@redhat.com> Date: Fri, 02 Jun 2017 19:22:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170503224626.2818-16-tom@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-06/txt/msg00067.txt.bz2 On 05/03/2017 11:46 PM, Tom Tromey wrote: > This patch introduces std::vector in several spots in gdb that were > using xmalloc and a cleanup. > > The simple_search_memory change warrants a bit of extra attention. It > was previously using malloc to try to handle memory allocation > failures. I don't know whether this was actually important. ( It still pains me a little to see std::vector used when we're going to fill in the data anyway, because std::vector value/zero-initializes, which is pointless in these cases. :-) I think I'll need to accept that people dislike the idea of unique_ptr, so I'll stop mentioning that, though at some point I think I may propose an allocator that default-initializes, and then I'll nag people to use _that_, like: typedef std::vector gdb_byte_vec; gdb_byte_vec buf (size); ) > @@ -601,24 +599,18 @@ elf_rel_plt_read (minimal_symbol_reader &reader, > OBJFILE the symbol is undefined and the objfile having NAME defined > may not yet have been loaded. */ > > - if (string_buffer_size < name_len + got_suffix_len + 1) > - { > - string_buffer_size = 2 * (name_len + got_suffix_len); > - string_buffer = (char *) xrealloc (string_buffer, string_buffer_size); > - } > - memcpy (string_buffer, name, name_len); > - memcpy (&string_buffer[name_len], SYMBOL_GOT_PLT_SUFFIX, > - got_suffix_len + 1); > + string_buffer.clear (); > + string_buffer.insert (string_buffer.end (), name, name + name_len); > + string_buffer.insert (string_buffer.end (), got_suffix, > + got_suffix + got_suffix_len + 1); So the patch all looks good to me, but it seems to me that in this particular case, making this buffer be a std::string would clarify the code: string_buffer.assign (name, name_len); string_buffer.append (got_suffix, got_suffix_len); > > - msym = record_minimal_symbol (reader, string_buffer, > + msym = record_minimal_symbol (reader, string_buffer.data (), > name_len + got_suffix_len, and here maybe use string_buffer.size () (std::string is guaranteed to be null terminated.) > true, address, mst_slot_got_plt, got_plt, > objfile); Thanks, Pedro Alves