From patchwork Wed Feb 7 22:04:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 25864 Received: (qmail 3749 invoked by alias); 7 Feb 2018 22:04:43 -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 3628 invoked by uid 89); 7 Feb 2018 22:04:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.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=Hx-languages-length:1901, our X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Feb 2018 22:04:40 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 9CE7212D07 for ; Wed, 7 Feb 2018 16:04:39 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id jXpXe78x0cGlpjXpXe7FX5; 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-DG; Wed, 07 Feb 2018 16:04:39 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 5/9] Use std::string in maybe_expand Date: Wed, 7 Feb 2018 15:04:30 -0700 Message-Id: <20180207220434.6045-6-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-DG 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: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This patch changes maybe_expand to use std::string rather than an explicit malloc and a cleanup. 2018-02-07 Tom Tromey * macroexp.c (maybe_expand): Use std::string. --- gdb/ChangeLog | 4 ++++ gdb/macroexp.c | 20 ++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 33f7e5f3d0..f33e3a6f7f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2018-02-07 Tom Tromey + * macroexp.c (maybe_expand): Use std::string. + +2018-02-07 Tom Tromey + * macroexp.c (struct macro_buffer): Add initializers for some members. (init_buffer, init_shared_buffer, free_buffer) diff --git a/gdb/macroexp.c b/gdb/macroexp.c index 02cf26ff73..1fa37d2875 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -1347,28 +1347,20 @@ maybe_expand (struct macro_buffer *dest, { /* Make a null-terminated copy of it, since that's what our lookup function expects. */ - char *id = (char *) xmalloc (src_first->len + 1); - struct cleanup *back_to = make_cleanup (xfree, id); + std::string id (src_first->text, src_first->len); - memcpy (id, src_first->text, src_first->len); - id[src_first->len] = 0; - /* If we're currently re-scanning the result of expanding this macro, don't expand it again. */ - if (! currently_rescanning (no_loop, id)) + if (! currently_rescanning (no_loop, id.c_str ())) { /* Does this identifier have a macro definition in scope? */ - struct macro_definition *def = lookup_func (id, lookup_baton); + struct macro_definition *def = lookup_func (id.c_str (), + lookup_baton); - if (def && expand (id, def, dest, src_rest, no_loop, + if (def && expand (id.c_str (), def, dest, src_rest, no_loop, lookup_func, lookup_baton)) - { - do_cleanups (back_to); - return 1; - } + return 1; } - - do_cleanups (back_to); } return 0;