From patchwork Wed Sep 6 05:13:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22666 Received: (qmail 116105 invoked by alias); 6 Sep 2017 05:17:14 -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 106781 invoked by uid 89); 6 Sep 2017 05:15:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=11226, baby X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Sep 2017 05:13:14 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy10.mail.unifiedlayer.com (Postfix) with ESMTP id 239CC140509 for ; Tue, 5 Sep 2017 23:13:13 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id 65DA1w00i2f2jeq015DDpM; Tue, 05 Sep 2017 23:13:13 -0600 X-Authority-Analysis: v=2.2 cv=G8xsK5s5 c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=Db13g2I3ADWtWaLDZkcA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:51406 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dpSeD-003XHD-Vr; Tue, 05 Sep 2017 23:13:10 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/4] Change funcall_chain to be a std::vector Date: Tue, 5 Sep 2017 23:13:06 -0600 Message-Id: <20170906051306.6092-5-tom@tromey.com> In-Reply-To: <20170906051306.6092-1-tom@tromey.com> References: <20170906051306.6092-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dpSeD-003XHD-Vr X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:51406 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This simplifies the handling of funcall_chain, by changing it to be a std::vector and then fixing the users. This allows the removal of a cleanup. It would be even cleaner to replace this with better logic in the parsers; but a baby step seemed ok. Apparently the old code was leaking funcall_chain here. This is repaired now. ChangeLog 2017-09-05 Tom Tromey * parse.c (funcall_chain): Now a std::vector. (start_arglist, end_arglist): Simplify. (free_funcalls): Remove. (parse_exp_in_context_1): Remove cleanup. --- gdb/ChangeLog | 7 +++++++ gdb/parse.c | 46 +++++++--------------------------------------- 2 files changed, 14 insertions(+), 39 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cd7664b..4995887 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2017-09-05 Tom Tromey + * parse.c (funcall_chain): Now a std::vector. + (start_arglist, end_arglist): Simplify. + (free_funcalls): Remove. + (parse_exp_in_context_1): Remove cleanup. + +2017-09-05 Tom Tromey + * go-exp.y (go_parse): Don't create a cleanup. 2017-09-05 Tom Tromey diff --git a/gdb/parse.c b/gdb/parse.c index 7971f6c..ae2c4d6 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -111,8 +111,6 @@ show_parserdebug (struct ui_file *file, int from_tty, } -static void free_funcalls (void *ignore); - static int prefixify_subexp (struct expression *, struct expression *, int, int); @@ -128,13 +126,7 @@ void _initialize_parse (void); /* Data structure for saving values of arglist_len for function calls whose arguments contain other function calls. */ -struct funcall - { - struct funcall *next; - int arglist_len; - }; - -static struct funcall *funcall_chain; +static std::vector *funcall_chain; /* Begin counting arguments for a function call, saving the data about any containing call. */ @@ -142,13 +134,8 @@ static struct funcall *funcall_chain; void start_arglist (void) { - struct funcall *newobj; - - newobj = XNEW (struct funcall); - newobj->next = funcall_chain; - newobj->arglist_len = arglist_len; + funcall_chain->push_back (arglist_len); arglist_len = 0; - funcall_chain = newobj; } /* Return the number of arguments in a function call just terminated, @@ -158,28 +145,11 @@ int end_arglist (void) { int val = arglist_len; - struct funcall *call = funcall_chain; - - funcall_chain = call->next; - arglist_len = call->arglist_len; - xfree (call); + arglist_len = funcall_chain->back (); + funcall_chain->pop_back (); return val; } -/* Free everything in the funcall chain. - Used when there is an error inside parsing. */ - -static void -free_funcalls (void *ignore) -{ - struct funcall *call, *next; - - for (call = funcall_chain; call; call = next) - { - next = call->next; - xfree (call); - } -} /* See definition in parser-defs.h. */ @@ -1152,7 +1122,6 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc, const struct block *block, int comma, int void_context_p, int *out_subexp) { - struct cleanup *old_chain; const struct language_defn *lang = NULL; struct parser_state ps; int subexp; @@ -1172,8 +1141,9 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc, if (lexptr == 0 || *lexptr == 0) error_no_arg (_("expression to compute")); - old_chain = make_cleanup (free_funcalls, 0 /*ignore*/); - funcall_chain = 0; + std::vector funcalls; + scoped_restore save_funcall_chain = make_scoped_restore (&funcall_chain, + &funcalls); expression_context_block = block; @@ -1267,8 +1237,6 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc, if (expressiondebug) dump_prefix_expression (ps.expout, gdb_stdlog); - discard_cleanups (old_chain); - *stringptr = lexptr; return expression_up (ps.expout); }