From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WMJpF+OMd1/aNgAAWB0awg (envelope-from ) for ; Fri, 02 Oct 2020 16:26:11 -0400 Received: by simark.ca (Postfix, from userid 112) id 5535F1EF79; Fri, 2 Oct 2020 16:26:10 -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 B97681E992 for ; Fri, 2 Oct 2020 16:26:09 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00C08393C848; Fri, 2 Oct 2020 20:26:09 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id 4451B3842433 for ; Fri, 2 Oct 2020 20:26:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4451B3842433 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0F43C11784C; Fri, 2 Oct 2020 16:26:06 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id VipQzIf2dw-C; Fri, 2 Oct 2020 16:26:06 -0400 (EDT) Received: from murgatroyd.Home (174-16-122-38.hlrn.qwest.net [174.16.122.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id BFDCA117839; Fri, 2 Oct 2020 16:26:05 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 1/2] Constify ada_encode return type Date: Fri, 2 Oct 2020 14:26:03 -0600 Message-Id: <20201002202604.1517475-2-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201002202604.1517475-1-tromey@adacore.com> References: <20201002202604.1517475-1-tromey@adacore.com> MIME-Version: 1.0 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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); for (depth = 0; depth < MAX_RENAMING_CHAIN_LENGTH; depth += 1) { int tail_index; diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 0df406bff48..2502d2847b2 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -923,7 +923,7 @@ const struct ada_opname_map ada_opname_table[] = { THROW_ERRORS, throw an error if invalid operator name is found. Otherwise, return NULL in that case. */ -static char * +static const char * ada_encode_1 (const char *decoded, bool throw_errors) { static char *encoding_buffer = NULL; @@ -978,7 +978,7 @@ ada_encode_1 (const char *decoded, bool throw_errors) /* The "encoded" form of DECODED, according to GNAT conventions. The result is valid until the next call to ada_encode. */ -char * +const char * ada_encode (const char *decoded) { return ada_encode_1 (decoded, true); diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index ae313ce700a..949d16ce3a6 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -318,7 +318,7 @@ extern struct type *ada_get_base_type (struct type *); extern struct type *ada_check_typedef (struct type *); -extern char *ada_encode (const char *); +extern const char *ada_encode (const char *); extern const char *ada_enum_name (const char *); -- 2.26.2