From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 5uQnNXuhd1/nOAAAWB0awg (envelope-from ) for ; Fri, 02 Oct 2020 17:54:03 -0400 Received: by simark.ca (Postfix, from userid 112) id CCF0A1EF44; Fri, 2 Oct 2020 17:54:03 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=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 3F7EA1E590 for ; Fri, 2 Oct 2020 17:54:03 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 06977388187D; Fri, 2 Oct 2020 21:54:03 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 707FE3851C07 for ; Fri, 2 Oct 2020 21:54:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 707FE3851C07 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [172.16.0.95] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 274821E590; Fri, 2 Oct 2020 17:54:01 -0400 (EDT) Subject: Re: [PATCH 2/2] Use obstack in ada_encode_1 To: Tom Tromey , gdb-patches@sourceware.org References: <20201002202604.1517475-1-tromey@adacore.com> <20201002202604.1517475-3-tromey@adacore.com> From: Simon Marchi Message-ID: <2d52a731-17e4-4a8f-0916-9a2203b0c94d@simark.ca> Date: Fri, 2 Oct 2020 17:54:00 -0400 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: <20201002202604.1517475-3-tromey@adacore.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2020-10-02 4:26 p.m., Tom Tromey wrote: > I'd eventually like to get rid of the GROW_VECT macro; and since I had > already touched ada_encode_1 I decided to start here. This patch > removes the use of the macro in favor of using an obstack in this > function. > > 2020-10-02 Tom Tromey > > * ada-lang.c (ada_encode_1): Use an obstack. > --- > gdb/ChangeLog | 4 ++++ > gdb/ada-lang.c | 26 +++++++------------------- > 2 files changed, 11 insertions(+), 19 deletions(-) > > diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c > index 2502d2847b2..dfe9d44959f 100644 > --- a/gdb/ada-lang.c > +++ b/gdb/ada-lang.c > @@ -926,25 +926,17 @@ const struct ada_opname_map ada_opname_table[] = { > static const char * > ada_encode_1 (const char *decoded, bool throw_errors) > { > - static char *encoding_buffer = NULL; > - static size_t encoding_buffer_size = 0; > + static auto_obstack encoding_buffer; > const char *p; > - int k; > > if (decoded == NULL) > return NULL; > > - GROW_VECT (encoding_buffer, encoding_buffer_size, > - 2 * strlen (decoded) + 10); > - > - k = 0; > + encoding_buffer.clear (); > for (p = decoded; *p != '\0'; p += 1) > { > if (*p == '.') > - { > - encoding_buffer[k] = encoding_buffer[k + 1] = '_'; > - k += 2; > - } > + obstack_grow_str (&encoding_buffer, "__"); > else if (*p == '"') > { > const struct ada_opname_map *mapping; > @@ -960,19 +952,15 @@ ada_encode_1 (const char *decoded, bool throw_errors) > else > return NULL; > } > - strcpy (encoding_buffer + k, mapping->encoded); > - k += strlen (mapping->encoded); > + obstack_grow_str (&encoding_buffer, mapping->encoded); > break; > } > else > - { > - encoding_buffer[k] = *p; > - k += 1; > - } > + obstack_1grow (&encoding_buffer, *p); > } > > - encoding_buffer[k] = '\0'; > - return encoding_buffer; > + obstack_1grow (&encoding_buffer, '\0'); > + return (const char *) obstack_finish (&encoding_buffer); > } > > /* The "encoded" form of DECODED, according to GNAT conventions. > -- > 2.26.2 > I think the same could be achieved using a static std::string instead of an obstack, and it would be a bit more C++-y, but either way is fine with me. Simon