From patchwork Fri Sep 23 19:53:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 15959 Received: (qmail 47021 invoked by alias); 23 Sep 2016 19:53:20 -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 47000 invoked by uid 89); 23 Sep 2016 19:53:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*r:4.86_1, 11827, 1182, 7, XNEWVEC X-HELO: gproxy6-pub.mail.unifiedlayer.com Received: from gproxy6-pub.mail.unifiedlayer.com (HELO gproxy6-pub.mail.unifiedlayer.com) (67.222.39.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Fri, 23 Sep 2016 19:53:11 +0000 Received: (qmail 21988 invoked by uid 0); 23 Sep 2016 19:53:10 -0000 Received: from unknown (HELO cmgw2) (10.0.90.83) by gproxy6.mail.unifiedlayer.com with SMTP; 23 Sep 2016 19:53:10 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw2 with id n7t41t00U2f2jeq017t72U; Fri, 23 Sep 2016 13:53:08 -0600 X-Authority-Analysis: v=2.1 cv=F4vEKMRN c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=GW1xBdLrtEIA:10 a=zstS-IiYAAAA:8 a=Or-wRp7S3U4J3-Pha0QA:9 a=18Em21sbz6HYOAsI:21 a=dDjkywq44nkaCxWo:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-16-151-161.hlrn.qwest.net ([174.16.151.161]:55642 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bnWWv-0005Ed-Ri; Fri, 23 Sep 2016 13:53:05 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI v2 3/5] Use std::string, std::vector in rust-lang.c Date: Fri, 23 Sep 2016 13:53:00 -0600 Message-Id: <1474660382-14294-4-git-send-email-tom@tromey.com> In-Reply-To: <1474660382-14294-1-git-send-email-tom@tromey.com> References: <1474660382-14294-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1bnWWv-0005Ed-Ri X-Source-Sender: 174-16-151-161.hlrn.qwest.net (bapiya.Home) [174.16.151.161]:55642 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This patch changes some spots in rust-lang.c to use std::string or std::vector, removing some cleanups. 2016-09-23 Tom Tromey * rust-lang.c: Include and . (rust_evaluate_funcall): Use std::vector, std::string. (rust_evaluate_subexp): Use std::string. (rust_lookup_symbol_nonlocal): Use std::string. --- gdb/ChangeLog | 7 +++++++ gdb/rust-lang.c | 35 +++++++++++++---------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 410c386..ab90503 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2016-09-23 Tom Tromey + * rust-lang.c: Include and . + (rust_evaluate_funcall): Use std::vector, std::string. + (rust_evaluate_subexp): Use std::string. + (rust_lookup_symbol_nonlocal): Use std::string. + +2016-09-23 Tom Tromey + * cp-namespace.c: Include . (cp_search_static_and_baseclasses) (cp_lookup_symbol_imports_or_template, find_symbol_in_baseclass): diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 77f7428..82cd3f9 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -32,6 +32,8 @@ #include "rust-lang.h" #include "valprint.h" #include "varobj.h" +#include +#include extern initialize_file_ftype _initialize_rust_language; @@ -1154,10 +1156,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside) int i; int num_args = exp->elts[*pos + 1].longconst; const char *method; - char *name; struct value *function, *result, *arg0; - struct value **args; - struct cleanup *cleanup; struct type *type, *fn_type; const struct block *block; struct block_symbol sym; @@ -1183,8 +1182,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside) return arg0; } - args = XNEWVEC (struct value *, num_args + 1); - cleanup = make_cleanup (xfree, args); + std::vector args (num_args + 1); args[0] = arg0; /* We don't yet implement real Deref semantics. */ @@ -1200,17 +1198,16 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside) if (TYPE_TAG_NAME (type) == NULL) error (_("Method call on nameless type")); - name = concat (TYPE_TAG_NAME (type), "::", method, (char *) NULL); - make_cleanup (xfree, name); + std::string name = std::string (TYPE_TAG_NAME (type)) + "::" + method; block = get_selected_block (0); - sym = lookup_symbol (name, block, VAR_DOMAIN, NULL); + sym = lookup_symbol (name.c_str (), block, VAR_DOMAIN, NULL); if (sym.symbol == NULL) - error (_("Could not find function named '%s'"), name); + error (_("Could not find function named '%s'"), name.c_str ()); fn_type = SYMBOL_TYPE (sym.symbol); if (TYPE_NFIELDS (fn_type) == 0) - error (_("Function '%s' takes no arguments"), name); + error (_("Function '%s' takes no arguments"), name.c_str ()); if (TYPE_CODE (TYPE_FIELD_TYPE (fn_type, 0)) == TYPE_CODE_PTR) args[0] = value_addr (args[0]); @@ -1223,8 +1220,7 @@ rust_evaluate_funcall (struct expression *exp, int *pos, enum noside noside) if (noside == EVAL_AVOID_SIDE_EFFECTS) result = value_zero (TYPE_TARGET_TYPE (fn_type), not_lval); else - result = call_function_by_hand (function, num_args + 1, args); - do_cleanups (cleanup); + result = call_function_by_hand (function, num_args + 1, args.data ()); return result; } @@ -1601,14 +1597,11 @@ rust_evaluate_subexp (struct type *expect_type, struct expression *exp, { CORE_ADDR addr; int i; - struct value **eltvec = XNEWVEC (struct value *, copies); - struct cleanup *cleanup = make_cleanup (xfree, eltvec); + std::vector eltvec (copies); for (i = 0; i < copies; ++i) eltvec[i] = elt; - result = value_array (0, copies - 1, eltvec); - - do_cleanups (cleanup); + result = value_array (0, copies - 1, eltvec.data ()); } else { @@ -2036,14 +2029,12 @@ rust_lookup_symbol_nonlocal (const struct language_defn *langdef, if (scope[0] != '\0') { - char *scopedname = concat (scope, "::", name, (char *) NULL); - struct cleanup *cleanup = make_cleanup (xfree, scopedname); + std::string scopedname = std::string (scope) + "::" + name; - result = lookup_symbol_in_static_block (scopedname, block, + result = lookup_symbol_in_static_block (scopedname.c_str (), block, domain); if (result.symbol == NULL) - result = lookup_global_symbol (scopedname, block, domain); - do_cleanups (cleanup); + result = lookup_global_symbol (scopedname.c_str (), block, domain); } } return result;