From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id B67B53851C07 for ; Fri, 2 Oct 2020 21:51:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B67B53851C07 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) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 3D5391E590; Fri, 2 Oct 2020 17:51:14 -0400 (EDT) Subject: Re: [PATCH 1/2] Constify ada_encode return type To: Tom Tromey , gdb-patches@sourceware.org References: <20201002202604.1517475-1-tromey@adacore.com> <20201002202604.1517475-2-tromey@adacore.com> From: Simon Marchi Message-ID: <6864fd19-d99f-7066-1eef-7dbbf6f2d84f@simark.ca> Date: Fri, 2 Oct 2020 17:51:13 -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-2-tromey@adacore.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Fri, 02 Oct 2020 21:51:15 -0000 On 2020-10-02 4:26 p.m., Tom Tromey wrote: > Callers of ada_encode don't ever modify the result, and also don't own > it -- it is owned by a static buffer in ada_encode_1. This patch > changes ada_encode to return a const char *, which I feel is somewhat > clearer. > > gdb/ChangeLog > 2020-10-02 Tom Tromey > > * ada-lang.h (ada_encode): Constify result. > * ada-lang.c (ada_encode): Constify result. > (ada_encode_1): Constify result. > --- > gdb/ChangeLog | 6 ++++++ > gdb/ada-exp.y | 6 +++--- > gdb/ada-lang.c | 4 ++-- > gdb/ada-lang.h | 2 +- > 4 files changed, 12 insertions(+), 6 deletions(-) > > diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y > index 57d89b01fec..61d8df9df48 100644 > --- a/gdb/ada-exp.y > +++ b/gdb/ada-exp.y > @@ -1201,9 +1201,9 @@ write_var_or_type (struct parser_state *par_state, > if (block == NULL) > block = par_state->expression_context_block; > > - encoded_name = ada_encode (name0.ptr); > - name_len = strlen (encoded_name); > - encoded_name = obstack_strndup (&temp_parse_space, encoded_name, name_len); > + const char *temp_name = ada_encode (name0.ptr); > + name_len = strlen (temp_name); > + encoded_name = obstack_strndup (&temp_parse_space, temp_name, name_len); Could this be further simplified to: encoded_name = obstack_strdup (&temp_parse_space, ada_encode (name0.ptr)); ? In any case, this LGTM. Simon