From patchwork Wed Feb 7 22:04:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 25866 Received: (qmail 3855 invoked by alias); 7 Feb 2018 22:04:44 -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 3734 invoked by uid 89); 7 Feb 2018 22:04:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 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=Hx-languages-length:2813 X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.48.71) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 22:04:41 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 028EB104FA for ; Wed, 7 Feb 2018 16:04:40 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id jXpXe1EuiuMnyjXpXehkOp; Wed, 07 Feb 2018 16:04:39 -0600 Received: from 174-29-33-254.hlrn.qwest.net ([174.29.33.254]:59168 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1ejXpX-002nlZ-P1; Wed, 07 Feb 2018 16:04:39 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 6/9] Remove cleanups from macro_define_command Date: Wed, 7 Feb 2018 15:04:31 -0700 Message-Id: <20180207220434.6045-7-tom@tromey.com> In-Reply-To: <20180207220434.6045-1-tom@tromey.com> References: <20180207220434.6045-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1ejXpX-002nlZ-P1 X-Source-Sender: 174-29-33-254.hlrn.qwest.net (pokyo.Home) [174.29.33.254]:59168 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes cleanups from macro_define_command, by introducing a new struct temporary_macro_definition that cleans up after itself. 2018-02-07 Tom Tromey * macrocmd.c (struct temporary_macro_definition): New. (macro_define_command): Use temporary_macro_definition. Remove cleanups. (free_macro_definition_ptr): Remove. --- gdb/ChangeLog | 7 +++++++ gdb/macrocmd.c | 42 +++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f33e3a6f7f..f0ec664d23 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2018-02-07 Tom Tromey + * macrocmd.c (struct temporary_macro_definition): New. + (macro_define_command): Use temporary_macro_definition. Remove + cleanups. + (free_macro_definition_ptr): Remove. + +2018-02-07 Tom Tromey + * macroexp.c (maybe_expand): Use std::string. 2018-02-07 Tom Tromey diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c index 13fd95d7da..e6cf921a1b 100644 --- a/gdb/macrocmd.c +++ b/gdb/macrocmd.c @@ -324,35 +324,37 @@ extract_identifier (const char **expp, int is_parameter) return result; } -/* Helper function to clean up a temporarily-constructed macro object. - This assumes that the contents were all allocated with xmalloc. */ -static void -free_macro_definition_ptr (void *ptr) +struct temporary_macro_definition : public macro_definition { - int i; - struct macro_definition *loc = (struct macro_definition *) ptr; - - for (i = 0; i < loc->argc; ++i) - xfree ((char *) loc->argv[i]); - xfree ((char *) loc->argv); - /* Note that the 'replacement' field is not allocated. */ -} + temporary_macro_definition () + { + table = nullptr; + kind = macro_object_like; + argc = 0; + argv = nullptr; + replacement = nullptr; + } + + ~temporary_macro_definition () + { + int i; + + for (i = 0; i < argc; ++i) + xfree ((char *) argv[i]); + xfree ((char *) argv); + /* Note that the 'replacement' field is not allocated. */ + } +}; static void macro_define_command (const char *exp, int from_tty) { - struct macro_definition new_macro; + temporary_macro_definition new_macro; char *name = NULL; - struct cleanup *cleanup_chain; if (!exp) error (_("usage: macro define NAME[(ARGUMENT-LIST)] [REPLACEMENT-LIST]")); - cleanup_chain = make_cleanup (free_macro_definition_ptr, &new_macro); - make_cleanup (free_current_contents, &name); - - memset (&new_macro, 0, sizeof (struct macro_definition)); - skip_ws (&exp); name = extract_identifier (&exp, 0); if (! name) @@ -415,8 +417,6 @@ macro_define_command (const char *exp, int from_tty) skip_ws (&exp); macro_define_object (macro_main (macro_user_macros), -1, name, exp); } - - do_cleanups (cleanup_chain); }