From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QOxnOQoIAWTefwIAWB0awg (envelope-from ) for ; Thu, 02 Mar 2023 15:33:14 -0500 Received: by simark.ca (Postfix, from userid 112) id E90101E223; Thu, 2 Mar 2023 15:33:14 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=M5sZDaPL; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 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 9FA471E0D3 for ; Thu, 2 Mar 2023 15:33:14 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2BB7F38582BC for ; Thu, 2 Mar 2023 20:33:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BB7F38582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677789194; bh=mStLKdJ/Osh7WGj6iAk99E1xeWNU1l0+7zWvisKwick=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=M5sZDaPLdwXoWL2a4+YTk8kOd5q26E0Grve9wpYjf9MRLOx0M6SdEKJfx8F5a8J4k T90OItI4/t5WEVITSB8u0WN9bEcgGNY5B7+KFKmWeJGOKSBwmLHe4qrUjPnor/uIgA sEsVc2OHjJZgvlFAPlLOj6CQ612zYk+Dtz84foB0= Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 2AA9F3858C54 for ; Thu, 2 Mar 2023 20:32:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2AA9F3858C54 Received: from smarchi-efficios.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (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 ESMTPSA id AEB351E223; Thu, 2 Mar 2023 15:32:25 -0500 (EST) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/3] gdb: make interp::m_name an `const char *` Date: Thu, 2 Mar 2023 15:32:23 -0500 Message-Id: <20230302203224.118345-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302203224.118345-1-simon.marchi@efficios.com> References: <20230302203224.118345-1-simon.marchi@efficios.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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" From: Simon Marchi I realized that the memory for interp names does not need to be allocated. The name used to register interp factory functions is always a literal string, so has static storage duration. If we change interp_lookup to pass that name instead of the string that it receives as a parameter (which does not always have static storage duration), then interps can simply store pointers to the name. So, change interp_lookup to pass `factory.name` rather than `name`. Change interp::m_name to be a `const char *` rather than an std::string. Change-Id: I0474d1f7b3512e7d172ccd73018aea927def3188 --- gdb/interps.c | 8 +++----- gdb/interps.h | 12 ++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/gdb/interps.c b/gdb/interps.c index 9517e57540d3..5b964aebbbd6 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -79,13 +79,11 @@ static struct interp *interp_lookup_existing (struct ui *ui, const char *name); interp::interp (const char *name) - : m_name (make_unique_xstrdup (name)) + : m_name (name) { } -interp::~interp () -{ -} +interp::~interp () = default; /* An interpreter factory. Maps an interpreter name to the factory function that instantiates an interpreter by that name. */ @@ -232,7 +230,7 @@ interp_lookup (struct ui *ui, const char *name) for (const interp_factory &factory : interpreter_factories) if (strcmp (factory.name, name) == 0) { - interp = factory.func (name); + interp = factory.func (factory.name); interp_add (ui, interp); return interp; } diff --git a/gdb/interps.h b/gdb/interps.h index 01bec47550dd..62f37951ddea 100644 --- a/gdb/interps.h +++ b/gdb/interps.h @@ -32,7 +32,9 @@ typedef struct interp *(*interp_factory_func) (const char *name); /* Each interpreter kind (CLI, MI, etc.) registers itself with a call to this function, passing along its name, and a pointer to a function that creates a new instance of an interpreter with that - name. */ + name. + + The memory for NAME must have static storage duration. */ extern void interp_factory_register (const char *name, interp_factory_func func); @@ -76,13 +78,11 @@ class interp { return false; } const char *name () const - { - return m_name.get (); - } + { return m_name; } private: - /* This is the name in "-i=" and "set interpreter". */ - gdb::unique_xmalloc_ptr m_name; + /* The memory for this is static, it comes from literal strings (e.g. "cli"). */ + const char *m_name; public: /* Interpreters are stored in a linked list, this is the next -- 2.39.2