From patchwork Fri Oct 20 02:09:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 23719 Received: (qmail 29448 invoked by alias); 20 Oct 2017 02:09:26 -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 29401 invoked by uid 89); 20 Oct 2017 02:09:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=factories, tracker X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Oct 2017 02:09:24 +0000 X-ASG-Debug-ID: 1508465349-0c856e65d437d4a60001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id s9pSJGCsYridAnR3 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 19 Oct 2017 22:09:09 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-192.222.251.162.electronicbox.net [192.222.251.162]) by smtp.electronicbox.net (Postfix) with ESMTP id AA65E441B21; Thu, 19 Oct 2017 22:09:09 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-192.222.251.162.electronicbox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [pushed] Get rid of VEC(interp_factory_p) Date: Thu, 19 Oct 2017 22:09:08 -0400 X-ASG-Orig-Subj: [pushed] Get rid of VEC(interp_factory_p) Message-Id: <20171020020908.22432-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1508465349 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 5073 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 1.50 X-Barracuda-Spam-Status: No, SCORE=1.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_SC0_MV0713, BSF_SC0_MV0713_2 X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.44045 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_SC0_MV0713 Custom rule MV0713 1.00 BSF_SC0_MV0713_2 BSF_SC0_MV0713_2 X-IsSubscribed: yes From: Simon Marchi Replace it with an std::vector. gdb/ChangeLog: * interps.c (struct interp_factory): Add constructor. (interp_factory_p): Remove typedef. (DEF_VEC_P(interp_factory_p)): Remove. (interpreter_factories): Change type to std::vector. (interp_factory_register): Adjust. (interp_lookup): Adjust. (interpreter_completer): Adjust. --- gdb/ChangeLog | 10 ++++++++++ gdb/interps.c | 58 ++++++++++++++++++++-------------------------------------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 70725eec9a..fe95d0a614 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2017-10-19 Simon Marchi + + * interps.c (struct interp_factory): Add constructor. + (interp_factory_p): Remove typedef. + (DEF_VEC_P(interp_factory_p)): Remove. + (interpreter_factories): Change type to std::vector. + (interp_factory_register): Adjust. + (interp_lookup): Adjust. + (interpreter_completer): Adjust. + 2017-10-19 Tom Tromey * break-catch-syscall.c (catch_syscall_completer): Use diff --git a/gdb/interps.c b/gdb/interps.c index 1e89a991ca..b177a8969e 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -91,6 +91,10 @@ interp::~interp () struct interp_factory { + interp_factory (const char *name_, interp_factory_func func_) + : name (name_), func (func_) + {} + /* This is the name in "-i=INTERP" and "interpreter-exec INTERP". */ const char *name; @@ -98,35 +102,24 @@ struct interp_factory interp_factory_func func; }; -typedef struct interp_factory *interp_factory_p; -DEF_VEC_P(interp_factory_p); - /* The registered interpreter factories. */ -static VEC(interp_factory_p) *interpreter_factories = NULL; +static std::vector interpreter_factories; /* See interps.h. */ void interp_factory_register (const char *name, interp_factory_func func) { - struct interp_factory *f; - int ix; - /* Assert that no factory for NAME is already registered. */ - for (ix = 0; - VEC_iterate (interp_factory_p, interpreter_factories, ix, f); - ++ix) - if (strcmp (f->name, name) == 0) + for (const interp_factory &f : interpreter_factories) + if (strcmp (f.name, name) == 0) { internal_error (__FILE__, __LINE__, _("interpreter factory already registered: \"%s\"\n"), name); } - f = XNEW (struct interp_factory); - f->name = name; - f->func = func; - VEC_safe_push (interp_factory_p, interpreter_factories, f); + interpreter_factories.emplace_back (name, func); } /* Add interpreter INTERP to the gdb interpreter list. The @@ -225,24 +218,18 @@ interp_lookup_existing (struct ui *ui, const char *name) struct interp * interp_lookup (struct ui *ui, const char *name) { - struct interp_factory *factory; - struct interp *interp; - int ix; - if (name == NULL || strlen (name) == 0) return NULL; /* Only create each interpreter once per top level. */ - interp = interp_lookup_existing (ui, name); + struct interp *interp = interp_lookup_existing (ui, name); if (interp != NULL) return interp; - for (ix = 0; - VEC_iterate (interp_factory_p, interpreter_factories, ix, factory); - ++ix) - if (strcmp (factory->name, name) == 0) + for (const interp_factory &factory : interpreter_factories) + if (strcmp (factory.name, name) == 0) { - interp = factory->func (name); + interp = factory.func (name); interp_add (ui, interp); return interp; } @@ -446,33 +433,28 @@ interpreter_completer (struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word) { - struct interp_factory *interp; - int textlen; - int ix; - - textlen = strlen (text); - for (ix = 0; - VEC_iterate (interp_factory_p, interpreter_factories, ix, interp); - ++ix) + int textlen = strlen (text); + + for (const interp_factory &interp : interpreter_factories) { - if (strncmp (interp->name, text, textlen) == 0) + if (strncmp (interp.name, text, textlen) == 0) { char *match; - match = (char *) xmalloc (strlen (word) + strlen (interp->name) + 1); + match = (char *) xmalloc (strlen (word) + strlen (interp.name) + 1); if (word == text) - strcpy (match, interp->name); + strcpy (match, interp.name); else if (word > text) { /* Return some portion of interp->name. */ - strcpy (match, interp->name + (word - text)); + strcpy (match, interp.name + (word - text)); } else { /* Return some of text plus interp->name. */ strncpy (match, word, text - word); match[text - word] = '\0'; - strcat (match, interp->name); + strcat (match, interp.name); } tracker.add_completion (gdb::unique_xmalloc_ptr (match)); }