summaryrefslogtreecommitdiff
path: root/gdb/interps.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-10-19 22:07:15 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2017-10-19 22:07:15 -0400
commit4c2287b0bdfbed95d37d09222fc253f4c5086ada (patch)
tree76d43e9c56c74a6faa6b6eeda74396bcb2497751 /gdb/interps.c
parentb5f6e7409243ca9b016753966a6404cdcfd41d95 (diff)
downloadbinutils-gdb-4c2287b0bdfbed95d37d09222fc253f4c5086ada.tar.gz
Get rid of VEC(interp_factory_p)
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.
Diffstat (limited to 'gdb/interps.c')
-rw-r--r--gdb/interps.c58
1 files changed, 20 insertions, 38 deletions
diff --git a/gdb/interps.c b/gdb/interps.c
index 1e89a991ca9..b177a8969eb 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<interp_factory> 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<char> (match));
}