From patchwork Thu Nov 30 03:01:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24616 Received: (qmail 102372 invoked by alias); 30 Nov 2017 03:01:48 -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 102332 invoked by uid 89); 30 Nov 2017 03:01:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.51.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 Nov 2017 03:01:44 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 7678122AD8 for ; Wed, 29 Nov 2017 21:01:43 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id KF6dei3axpOTvKF6deMa1b; Wed, 29 Nov 2017 21:01:43 -0600 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:57898 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eKF6d-002PmB-89; Wed, 29 Nov 2017 21:01:43 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/6] Remove cleanup from old_renaming_is_invisible Date: Wed, 29 Nov 2017 20:01:35 -0700 Message-Id: <20171130030140.14830-2-tom@tromey.com> In-Reply-To: <20171130030140.14830-1-tom@tromey.com> References: <20171130030140.14830-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eKF6d-002PmB-89 X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.Home) [71.218.90.63]:57898 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes a cleanup from ada-lang.c by changing xget_renaming_scope to return a std::string. ChangeLog 2017-11-29 Tom Tromey * ada-lang.c (xget_renaming_scope): Return std::string. (old_renaming_is_invisible): Update. --- gdb/ChangeLog | 5 +++++ gdb/ada-lang.c | 35 +++++++---------------------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 3265c211fb..d5dfa07b78 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5180,9 +5180,9 @@ remove_extra_symbols (struct block_symbol *syms, int nsyms) /* Given a type that corresponds to a renaming entity, use the type name to extract the scope (package name or function name, fully qualified, and following the GNAT encoding convention) where this renaming has been - defined. The string returned needs to be deallocated after use. */ + defined. */ -static char * +static std::string xget_renaming_scope (struct type *renaming_type) { /* The renaming types adhere to the following convention: @@ -5193,8 +5193,6 @@ xget_renaming_scope (struct type *renaming_type) const char *name = type_name_no_tag (renaming_type); const char *suffix = strstr (name, "___XR"); const char *last; - int scope_len; - char *scope; /* Now, backtrack a bit until we find the first "__". Start looking at suffix - 3, as the part is at least one character long. */ @@ -5204,14 +5202,7 @@ xget_renaming_scope (struct type *renaming_type) break; /* Make a copy of scope and return it. */ - - scope_len = last - name; - scope = (char *) xmalloc ((scope_len + 1) * sizeof (char)); - - strncpy (scope, name, scope_len); - scope[scope_len] = '\0'; - - return scope; + return std::string (name, last); } /* Return nonzero if NAME corresponds to a package name. */ @@ -5251,21 +5242,14 @@ is_package_name (const char *name) static int old_renaming_is_invisible (const struct symbol *sym, const char *function_name) { - char *scope; - struct cleanup *old_chain; - if (SYMBOL_CLASS (sym) != LOC_TYPEDEF) return 0; - scope = xget_renaming_scope (SYMBOL_TYPE (sym)); - old_chain = make_cleanup (xfree, scope); + std::string scope = xget_renaming_scope (SYMBOL_TYPE (sym)); /* If the rename has been defined in a package, then it is visible. */ - if (is_package_name (scope)) - { - do_cleanups (old_chain); - return 0; - } + if (is_package_name (scope.c_str ())) + return 0; /* Check that the rename is in the current function scope by checking that its name starts with SCOPE. */ @@ -5277,12 +5261,7 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name) if (startswith (function_name, "_ada_")) function_name += 5; - { - int is_invisible = !startswith (function_name, scope); - - do_cleanups (old_chain); - return is_invisible; - } + return !startswith (function_name, scope.c_str ()); } /* Remove entries from SYMS that corresponds to a renaming entity that