From patchwork Fri Aug 15 20:34:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 2402 Received: (qmail 14295 invoked by alias); 15 Aug 2014 20:34:46 -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 14255 invoked by uid 89); 15 Aug 2014 20:34:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: usevmg20.ericsson.net Received: from usevmg20.ericsson.net (HELO usevmg20.ericsson.net) (198.24.6.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 15 Aug 2014 20:34:43 +0000 Received: from EUSAAHC003.ericsson.se (Unknown_Domain [147.117.188.81]) by usevmg20.ericsson.net (Symantec Mail Security) with SMTP id 4A.73.05330.6BA1EE35; Fri, 15 Aug 2014 16:35:35 +0200 (CEST) Received: from simark-hp.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.81) with Microsoft SMTP Server (TLS) id 14.3.174.1; Fri, 15 Aug 2014 16:34:40 -0400 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH] Convert target_structs vector to VEC Date: Fri, 15 Aug 2014 16:34:34 -0400 Message-ID: <1408134874-15078-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-IsSubscribed: yes I thought that this home made implementation of a vector could be replaced by the more standard VEC. The implementation seems to predate the introduction of vec.h, so that would explain why it exists. Ran make check before and after, no new failures. gdb/ChangeLog: 2014-08-15 Simon Marchi * target.c (target_struct_size): Remove. (target_struct_allocsize): Remove. (DEFAULT_ALLOCSIZE): Remove. (target_ops_p): New typedef. (DEF_VEC_P (target_ops_p)): New vector type. (target_structs): Change type to VEC (target_ops_p). (add_target_with_completer): Replace "push" code by VEC_safe_push. (find_default_run_target): Rewrite for loop following changes to target_structs. --- gdb/target.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index ba244bc..8bf6031 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -117,13 +117,10 @@ static void init_dummy_target (void); static void update_current_target (void); -/* Pointer to array of target architecture structures; the size of the - array; the current index into the array; the allocated size of the - array. */ -struct target_ops **target_structs; -unsigned target_struct_size; -unsigned target_struct_allocsize; -#define DEFAULT_ALLOCSIZE 10 +/* Vector of existing target structures. */ +typedef struct target_ops *target_ops_p; +DEF_VEC_P (target_ops_p); +static VEC (target_ops_p) *target_structs; /* The initial current target, so that there is always a semi-valid current target. */ @@ -379,20 +376,7 @@ add_target_with_completer (struct target_ops *t, complete_target_initialization (t); - if (!target_structs) - { - target_struct_allocsize = DEFAULT_ALLOCSIZE; - target_structs = (struct target_ops **) xmalloc - (target_struct_allocsize * sizeof (*target_structs)); - } - if (target_struct_size >= target_struct_allocsize) - { - target_struct_allocsize *= 2; - target_structs = (struct target_ops **) - xrealloc ((char *) target_structs, - target_struct_allocsize * sizeof (*target_structs)); - } - target_structs[target_struct_size++] = t; + VEC_safe_push (target_ops_p, target_structs, t); if (targetlist == NULL) add_prefix_cmd ("target", class_run, target_command, _("\ @@ -2363,15 +2347,15 @@ find_default_run_target (char *do_mesg) if (auto_connect_native_target) { - struct target_ops **t; + struct target_ops *t; int count = 0; + int i; - for (t = target_structs; t < target_structs + target_struct_size; - ++t) + for (i = 0; VEC_iterate (target_ops_p, target_structs, i, t); ++i) { - if ((*t)->to_can_run != delegate_can_run && target_can_run (*t)) + if (t->to_can_run != delegate_can_run && target_can_run (t)) { - runable = *t; + runable = t; ++count; } }