From patchwork Wed Apr 4 04:40:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26593 Received: (qmail 86154 invoked by alias); 4 Apr 2018 04:41:00 -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 85797 invoked by uid 89); 4 Apr 2018 04:40:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.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_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.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Apr 2018 04:40:55 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway24.websitewelcome.com (Postfix) with ESMTP id D7F7D19B19 for ; Tue, 3 Apr 2018 23:40:53 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 3aE9fLGef7Ovo3aE9feVHS; Tue, 03 Apr 2018 23:40:53 -0500 Received: from 75-166-37-45.hlrn.qwest.net ([75.166.37.45]:43166 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f3aE9-000hxu-Kx; Tue, 03 Apr 2018 23:40:53 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 09/10] Remove typep and VEC(typep) from linespec.c Date: Tue, 3 Apr 2018 22:40:48 -0600 Message-Id: <20180404044049.31481-10-tom@tromey.com> In-Reply-To: <20180404044049.31481-1-tom@tromey.com> References: <20180404044049.31481-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f3aE9-000hxu-Kx X-Source-Sender: 75-166-37-45.hlrn.qwest.net (bapiya.Home) [75.166.37.45]:43166 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes VEC(typep) from linespec.c in favor of std::vector. It also removes the "typep" typedef. This change allowed the removal of some cleanups. I believe the previous cleanup code in find_superclass_methods could result in a memory leak, so this patch is an improvement in that way as well. gdb/ChangeLog 2018-04-03 Tom Tromey * linespec.c (typep): Remove typedef. (find_methods, find_superclass_methods): Take a std::vector. (find_method): Use std::vector. --- gdb/ChangeLog | 6 ++++++ gdb/linespec.c | 35 ++++++++++------------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index b52e0061da..7ef8012ab5 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -80,9 +80,6 @@ enum class linespec_complete_what typedef struct symbol *symbolp; DEF_VEC_P (symbolp); -typedef struct type *typep; -DEF_VEC_P (typep); - /* An address entry is used to ensure that any given location is only added to the result a single time. It holds an address and the program space from which the address came. */ @@ -1211,7 +1208,7 @@ iterate_over_file_blocks static void find_methods (struct type *t, enum language t_lang, const char *name, std::vector *result_names, - VEC (typep) **superclasses) + std::vector *superclasses) { int ibase; const char *class_name = type_name_no_tag (t); @@ -1272,7 +1269,7 @@ find_methods (struct type *t, enum language t_lang, const char *name, } for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) - VEC_safe_push (typep, *superclasses, TYPE_BASECLASS (t, ibase)); + superclasses->push_back (TYPE_BASECLASS (t, ibase)); } /* Find an instance of the character C in the string S that is outside @@ -3645,32 +3642,24 @@ add_all_symbol_names_from_pspace (struct collect_info *info, } static void -find_superclass_methods (VEC (typep) *superclasses, +find_superclass_methods (std::vector &&superclasses, const char *name, enum language name_lang, std::vector *result_names) { size_t old_len = result_names->size (); - VEC (typep) *iter_classes; - struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); - iter_classes = superclasses; while (1) { - VEC (typep) *new_supers = NULL; - int ix; - struct type *t; + std::vector new_supers; - make_cleanup (VEC_cleanup (typep), &new_supers); - for (ix = 0; VEC_iterate (typep, iter_classes, ix, t); ++ix) + for (struct type *t : superclasses) find_methods (t, name_lang, name, result_names, &new_supers); - if (result_names->size () != old_len || VEC_empty (typep, new_supers)) + if (result_names->size () != old_len || new_supers.empty ()) break; - iter_classes = new_supers; + superclasses = std::move (new_supers); } - - do_cleanups (cleanup); } /* This finds the method METHOD_NAME in the class CLASS_NAME whose type is @@ -3684,10 +3673,9 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs, VEC (bound_minimal_symbol_d) **minsyms) { struct symbol *sym; - struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); int ix; size_t last_result_len; - VEC (typep) *superclass_vec; + std::vector superclass_vec; std::vector result_names; struct collect_info info; @@ -3712,8 +3700,6 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs, those names. This loop is written in a somewhat funny way because we collect data across the program space before deciding what to do. */ - superclass_vec = NULL; - make_cleanup (VEC_cleanup (typep), &superclass_vec); last_result_len = 0; for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix) { @@ -3739,7 +3725,7 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs, /* If we did not find a direct implementation anywhere in this program space, consider superclasses. */ if (result_names.size () == last_result_len) - find_superclass_methods (superclass_vec, method_name, + find_superclass_methods (std::move (superclass_vec), method_name, SYMBOL_LANGUAGE (sym), &result_names); /* We have a list of candidate symbol names, so now we @@ -3748,7 +3734,7 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs, add_all_symbol_names_from_pspace (&info, pspace, result_names, FUNCTIONS_DOMAIN); - VEC_truncate (typep, superclass_vec, 0); + superclass_vec.clear (); last_result_len = result_names.size (); } } @@ -3758,7 +3744,6 @@ find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs, { *symbols = info.result.symbols; *minsyms = info.result.minimal_symbols; - do_cleanups (cleanup); return; }