From patchwork Tue Apr 11 15:01:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 19962 Received: (qmail 110731 invoked by alias); 11 Apr 2017 15:01:41 -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 95934 invoked by uid 89); 11 Apr 2017 15:01:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy7-pub.mail.unifiedlayer.com Received: from gproxy7-pub.mail.unifiedlayer.com (HELO gproxy7-pub.mail.unifiedlayer.com) (70.40.196.235) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Tue, 11 Apr 2017 15:01:24 +0000 Received: (qmail 22026 invoked by uid 0); 11 Apr 2017 15:01:24 -0000 Received: from unknown (HELO CMOut01) (10.0.90.82) by gproxy7.mail.unifiedlayer.com with SMTP; 11 Apr 2017 15:01:24 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 731L1v0292f2jeq0131Qkg; Tue, 11 Apr 2017 09:01:24 -0600 X-Authority-Analysis: v=2.2 cv=cpDrqxwi c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=AzvcPWV-tVgA:10 a=zstS-IiYAAAA:8 a=PPV2IAwfiLHn9L6c6h8A:9 a=0JfOGDux7INNZ-Xe:21 a=zYQc6w4cyX8zEP74:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-65-226.hlrn.qwest.net ([75.166.65.226]:50042 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1cxxIG-0007Ml-NK; Tue, 11 Apr 2017 09:01:20 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 08/17] Remove some cleanups from gnu-v3-abi.c Date: Tue, 11 Apr 2017 09:01:03 -0600 Message-Id: <20170411150112.23207-9-tom@tromey.com> In-Reply-To: <20170411150112.23207-1-tom@tromey.com> References: <20170411150112.23207-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1cxxIG-0007Ml-NK X-Source-Sender: 75-166-65-226.hlrn.qwest.net (bapiya.Home) [75.166.65.226]:50042 X-Source-Auth: tom+tromey.com X-Email-Count: 9 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This removes some cleanups from gnu-v3-abi.c, by using std::vector rather than VEC. gdb/ChangeLog 2017-04-11 Tom Tromey * gnu-v3-abi.c (value_and_voffset_p): Remove typedef. (compare_value_and_voffset): Change type. Update. (compute_vtable_size): Change type of "offset_vec". (gnuv3_print_vtable): Use std::vector. Remove cleanups. (gnuv3_get_typeid): Remove extraneous declaration. --- gdb/ChangeLog | 8 ++++++++ gdb/gnu-v3-abi.c | 54 ++++++++++++++++++------------------------------------ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6f16318..d47f796 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 2017-04-11 Tom Tromey + * gnu-v3-abi.c (value_and_voffset_p): Remove typedef. + (compare_value_and_voffset): Change type. Update. + (compute_vtable_size): Change type of "offset_vec". + (gnuv3_print_vtable): Use std::vector. Remove cleanups. + (gnuv3_get_typeid): Remove extraneous declaration. + +2017-04-11 Tom Tromey + * charset.h (wchar_iterator): Fix comment. 2017-04-11 Tom Tromey diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index 6c7f35b..0090990 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -27,6 +27,7 @@ #include "valprint.h" #include "c-lang.h" #include "typeprint.h" +#include static struct cp_abi_ops gnu_v3_abi_ops; @@ -767,9 +768,6 @@ struct value_and_voffset int max_voffset; }; -typedef struct value_and_voffset *value_and_voffset_p; -DEF_VEC_P (value_and_voffset_p); - /* Hash function for value_and_voffset. */ static hashval_t @@ -792,25 +790,18 @@ eq_value_and_voffset (const void *a, const void *b) == value_address (ovb->value) + value_embedded_offset (ovb->value)); } -/* qsort comparison function for value_and_voffset. */ +/* Comparison function for value_and_voffset. */ -static int -compare_value_and_voffset (const void *a, const void *b) +static bool +compare_value_and_voffset (const struct value_and_voffset *va, + const struct value_and_voffset *vb) { - const struct value_and_voffset * const *ova - = (const struct value_and_voffset * const *) a; - CORE_ADDR addra = (value_address ((*ova)->value) - + value_embedded_offset ((*ova)->value)); - const struct value_and_voffset * const *ovb - = (const struct value_and_voffset * const *) b; - CORE_ADDR addrb = (value_address ((*ovb)->value) - + value_embedded_offset ((*ovb)->value)); - - if (addra < addrb) - return -1; - if (addra > addrb) - return 1; - return 0; + CORE_ADDR addra = (value_address (va->value) + + value_embedded_offset (va->value)); + CORE_ADDR addrb = (value_address (vb->value) + + value_embedded_offset (vb->value)); + + return addra < addrb; } /* A helper function used when printing vtables. This determines the @@ -821,7 +812,7 @@ compare_value_and_voffset (const void *a, const void *b) static void compute_vtable_size (htab_t offset_hash, - VEC (value_and_voffset_p) **offset_vec, + std::vector *offset_vec, struct value *value) { int i; @@ -847,7 +838,7 @@ compute_vtable_size (htab_t offset_hash, current_vo->value = value; current_vo->max_voffset = -1; *slot = current_vo; - VEC_safe_push (value_and_voffset_p, *offset_vec, current_vo); + offset_vec->push_back (current_vo); } /* Update the value_and_voffset object with the highest vtable @@ -940,10 +931,7 @@ gnuv3_print_vtable (struct value *value) struct type *type; struct value *vtable; struct value_print_options opts; - struct cleanup *cleanup; - VEC (value_and_voffset_p) *result_vec = NULL; - struct value_and_voffset *iter; - int i, count; + int count; value = coerce_ref (value); type = check_typedef (value_type (value)); @@ -978,17 +966,14 @@ gnuv3_print_vtable (struct value *value) htab_up offset_hash (htab_create_alloc (1, hash_value_and_voffset, eq_value_and_voffset, xfree, xcalloc, xfree)); - cleanup = make_cleanup (VEC_cleanup (value_and_voffset_p), &result_vec); + std::vector result_vec; compute_vtable_size (offset_hash.get (), &result_vec, value); - - qsort (VEC_address (value_and_voffset_p, result_vec), - VEC_length (value_and_voffset_p, result_vec), - sizeof (value_and_voffset_p), - compare_value_and_voffset); + std::sort (result_vec.begin (), result_vec.end (), + compare_value_and_voffset); count = 0; - for (i = 0; VEC_iterate (value_and_voffset_p, result_vec, i, iter); ++i) + for (value_and_voffset *iter : result_vec) { if (iter->max_voffset >= 0) { @@ -998,8 +983,6 @@ gnuv3_print_vtable (struct value *value) ++count; } } - - do_cleanups (cleanup); } /* Return a GDB type representing `struct std::type_info', laid out @@ -1077,7 +1060,6 @@ gnuv3_get_typeid (struct value *value) struct type *typeinfo_type; struct type *type; struct gdbarch *gdbarch; - struct cleanup *cleanup; struct value *result; std::string type_name, canonical;