From patchwork Fri May 25 18:41:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27508 Received: (qmail 8328 invoked by alias); 25 May 2018 18:41:46 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 8312 invoked by uid 89); 25 May 2018 18:41:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 25 May 2018 18:41:43 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 40A28AC9D5F for ; Fri, 25 May 2018 13:41:42 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MHeofvDOBSjJAMHeofXIcA; Fri, 25 May 2018 13:41:42 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:40032 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fMHen-000yNM-Vz; Fri, 25 May 2018 13:41:42 -0500 From: Tom Tromey To: Pedro Alves Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA 4/4] Remove interp_name References: <20180430051207.19979-1-tom@tromey.com> <20180430051207.19979-5-tom@tromey.com> <0b5df1d7-ea68-8bb0-bbdf-6a370b35042c@redhat.com> Date: Fri, 25 May 2018 12:41:40 -0600 In-Reply-To: <0b5df1d7-ea68-8bb0-bbdf-6a370b35042c@redhat.com> (Pedro Alves's message of "Fri, 25 May 2018 19:12:06 +0100") Message-ID: <874liv1st7.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fMHen-000yNM-Vz X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya) [174.29.44.154]:40032 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes >>>>> "Pedro" == Pedro Alves writes: Pedro> Not sure. The name is supposedly read-only, which would Pedro> suggest renaming the field to m_name and adding a name() Pedro> getter. WDYT? How about the appended as a follow-up patch to this series? Tom commit d525a99be1b02dda6c69007e31dd06f276378aea Author: Tom Tromey Date: Fri May 25 12:39:51 2018 -0600 Add "name" method to class interp In a review Pedro pointed out that interp::name is intended to be read-only, and so an accessor would be a better fit. This patch renames the field and adds a "name" method that is used instead. ChangeLog 2018-05-25 Tom Tromey * tui/tui.c (tui_enable): Update. * mi/mi-interp.c (mi_interp::init): Update. * interps.h (class interp) : New method. : Rename from name. (~scoped_restore_interp): Update. * interps.c (interp::interp): Update. (interp_add, interp_set, interp_lookup_existing) (current_interp_named_p): Update. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0bf350c255..a01f60c3b0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,14 @@ +2018-05-25 Tom Tromey + + * tui/tui.c (tui_enable): Update. + * mi/mi-interp.c (mi_interp::init): Update. + * interps.h (class interp) : New method. + : Rename from name. + (~scoped_restore_interp): Update. + * interps.c (interp::interp): Update. + (interp_add, interp_set, interp_lookup_existing) + (current_interp_named_p): Update. + 2018-05-25 Tom Tromey * interps.c (interp_name): Remove. diff --git a/gdb/interps.c b/gdb/interps.c index 8ec9744fdf..789ae86946 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -78,8 +78,8 @@ static struct interp *interp_lookup_existing (struct ui *ui, const char *name); interp::interp (const char *name) + : m_name (xstrdup (name)) { - this->name = xstrdup (name); this->inited = false; } @@ -129,7 +129,7 @@ interp_add (struct ui *ui, struct interp *interp) { struct ui_interp_info *ui_interp = get_interp_info (ui); - gdb_assert (interp_lookup_existing (ui, interp->name) == NULL); + gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL); interp->next = ui_interp->interp_list; ui_interp->interp_list = interp; @@ -170,11 +170,11 @@ interp_set (struct interp *interp, bool top_level) /* We use interpreter_p for the "set interpreter" variable, so we need to make sure we have a malloc'ed copy for the set command to free. */ if (interpreter_p != NULL - && strcmp (interp->name, interpreter_p) != 0) + && strcmp (interp->name (), interpreter_p) != 0) { xfree (interpreter_p); - interpreter_p = xstrdup (interp->name); + interpreter_p = xstrdup (interp->name ()); } /* Run the init proc. */ @@ -206,7 +206,7 @@ interp_lookup_existing (struct ui *ui, const char *name) interp != NULL; interp = interp->next) { - if (strcmp (interp->name, name) == 0) + if (strcmp (interp->name (), name) == 0) return interp; } @@ -282,7 +282,7 @@ current_interp_named_p (const char *interp_name) struct interp *interp = ui_interp->current_interpreter; if (interp != NULL) - return (strcmp (interp->name, interp_name) == 0); + return (strcmp (interp->name (), interp_name) == 0); return 0; } diff --git a/gdb/interps.h b/gdb/interps.h index a689be5625..74c9a80918 100644 --- a/gdb/interps.h +++ b/gdb/interps.h @@ -74,8 +74,13 @@ public: virtual bool supports_command_editing () { return false; } + const char *name () const + { + return m_name; + } + /* This is the name in "-i=" and "set interpreter". */ - const char *name; + const char *m_name; /* Interpreters are stored in a linked list, this is the next one... */ @@ -111,7 +116,7 @@ public: ~scoped_restore_interp () { - set_interp (m_interp->name); + set_interp (m_interp->name ()); } scoped_restore_interp (const scoped_restore_interp &) = delete; diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index e52d797973..ebc899f631 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -130,13 +130,13 @@ mi_interp::init (bool top_level) /* INTERP_MI selects the most recent released version. "mi2" was released as part of GDB 6.0. */ - if (strcmp (name, INTERP_MI) == 0) + if (strcmp (name (), INTERP_MI) == 0) mi_version = 2; - else if (strcmp (name, INTERP_MI1) == 0) + else if (strcmp (name (), INTERP_MI1) == 0) mi_version = 1; - else if (strcmp (name, INTERP_MI2) == 0) + else if (strcmp (name (), INTERP_MI2) == 0) mi_version = 2; - else if (strcmp (name, INTERP_MI3) == 0) + else if (strcmp (name (), INTERP_MI3) == 0) mi_version = 3; else gdb_assert_not_reached ("unhandled MI version"); diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 9e2520b4fc..75a9ced619 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -415,7 +415,7 @@ tui_enable (void) /* If the top level interpreter is not the console/tui (e.g., MI), enabling curses will certainly lose. */ - interp = top_level_interpreter ()->name; + interp = top_level_interpreter ()->name (); if (strcmp (interp, INTERP_TUI) != 0) error (_("Cannot enable the TUI when the interpreter is '%s'"), interp);