From patchwork Sun Sep 10 21:50:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22808 Received: (qmail 42101 invoked by alias); 10 Sep 2017 21:50:50 -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 41842 invoked by uid 89); 10 Sep 2017 21:50:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=3127 X-HELO: gproxy9-pub.mail.unifiedlayer.com Received: from gproxy9-pub.mail.unifiedlayer.com (HELO gproxy9-pub.mail.unifiedlayer.com) (69.89.20.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Sep 2017 21:50:47 +0000 Received: from cmgw2 (unknown [10.0.90.83]) by gproxy9.mail.unifiedlayer.com (Postfix) with ESMTP id C32A11E06FF for ; Sun, 10 Sep 2017 15:50:45 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id 7xqi1w00V2f2jeq01xql5r; Sun, 10 Sep 2017 15:50:45 -0600 X-Authority-Analysis: v=2.2 cv=dZfw5Tfe c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=GBX72N0cULy4WzQcg_4A:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:39396 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1drA7m-0020eg-Kb; Sun, 10 Sep 2017 15:50:42 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 7/8] Use std::string in d-namespace.c Date: Sun, 10 Sep 2017 15:50:36 -0600 Message-Id: <20170910215037.24329-8-tom@tromey.com> In-Reply-To: <20170910215037.24329-1-tom@tromey.com> References: <20170910215037.24329-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1drA7m-0020eg-Kb X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:39396 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes some cleanups from d-namespace.c by replacing manual string management with std::string. ChangeLog 2017-09-10 Tom Tromey * d-namespace.c (d_lookup_symbol): Use std::string. (find_symbol_in_baseclass): Likewise. --- gdb/ChangeLog | 5 +++++ gdb/d-namespace.c | 45 ++++++++++++--------------------------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 735de68..f757ab5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-09-10 Tom Tromey + * d-namespace.c (d_lookup_symbol): Use std::string. + (find_symbol_in_baseclass): Likewise. + +2017-09-10 Tom Tromey + * ctf.c (ctf_start): Use std::string. 2017-09-10 Tom Tromey diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c index ae2e7e3..bc791f7 100644 --- a/gdb/d-namespace.c +++ b/gdb/d-namespace.c @@ -108,16 +108,13 @@ d_lookup_symbol (const struct language_defn *langdef, if (search) { - char *classname, *nested; + std::string classname, nested; unsigned int prefix_len; - struct cleanup *cleanup; struct block_symbol class_sym; /* A simple lookup failed. Check if the symbol was defined in a base class. */ - cleanup = make_cleanup (null_cleanup, NULL); - /* Find the name of the class and the name of the method, variable, etc. */ prefix_len = d_entire_prefix_len (name); @@ -130,42 +127,31 @@ d_lookup_symbol (const struct language_defn *langdef, lang_this = lookup_language_this (language_def (language_d), block); if (lang_this.symbol == NULL) - { - do_cleanups (cleanup); - return null_block_symbol; - } + return null_block_symbol; type = check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (lang_this.symbol))); - classname = xstrdup (TYPE_NAME (type)); - nested = xstrdup (name); + classname = TYPE_NAME (type); + nested = name; } else { /* The class name is everything up to and including PREFIX_LEN. */ - classname = savestring (name, prefix_len); + classname = std::string (name, prefix_len); /* The rest of the name is everything else past the initial scope operator. */ - nested = xstrdup (name + prefix_len + 1); + nested = std::string (name + prefix_len + 1); } - /* Add cleanups to free memory for these strings. */ - make_cleanup (xfree, classname); - make_cleanup (xfree, nested); - /* Lookup a class named CLASSNAME. If none is found, there is nothing more that can be done. */ - class_sym = lookup_global_symbol (classname, block, domain); + class_sym = lookup_global_symbol (classname.c_str (), block, domain); if (class_sym.symbol == NULL) - { - do_cleanups (cleanup); - return null_block_symbol; - } + return null_block_symbol; /* Look for a symbol named NESTED in this class. */ sym = d_lookup_nested_symbol (SYMBOL_TYPE (class_sym.symbol), - nested, block); - do_cleanups (cleanup); + nested.c_str (), block); } return sym; @@ -260,18 +246,14 @@ static struct block_symbol find_symbol_in_baseclass (struct type *parent_type, const char *name, const struct block *block) { - char *concatenated_name = NULL; struct block_symbol sym; - struct cleanup *cleanup; int i; sym.symbol = NULL; sym.block = NULL; - cleanup = make_cleanup (free_current_contents, &concatenated_name); for (i = 0; i < TYPE_N_BASECLASSES (parent_type); ++i) { - size_t len; struct type *base_type = TYPE_BASECLASS (parent_type, i); const char *base_name = TYPE_BASECLASS_NAME (parent_type, i); @@ -287,10 +269,8 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, /* Now search all static file-level symbols. We have to do this for things like typedefs in the class. First search in this symtab, what we want is possibly there. */ - len = strlen (base_name) + strlen (name) + 2; - concatenated_name = (char *) xrealloc (concatenated_name, len); - xsnprintf (concatenated_name, len, "%s.%s", base_name, name); - sym = lookup_symbol_in_static_block (concatenated_name, block, + std::string concatenated_name = std::string (base_name) + "." + name; + sym = lookup_symbol_in_static_block (concatenated_name.c_str (), block, VAR_DOMAIN); if (sym.symbol != NULL) break; @@ -298,7 +278,7 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, /* Nope. We now have to search all static blocks in all objfiles, even if block != NULL, because there's no guarantees as to which symtab the symbol we want is in. */ - sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN); + sym = lookup_static_symbol (concatenated_name.c_str (), VAR_DOMAIN); if (sym.symbol != NULL) break; @@ -312,7 +292,6 @@ find_symbol_in_baseclass (struct type *parent_type, const char *name, } } - do_cleanups (cleanup); return sym; }