Allocate cmd_list_element with new

This adds a constructor and destructor to cmd_list_element and changes
it to be allocated with new.  This will be useful in a subsequent
patch.

ChangeLog
2018-05-04  Tom Tromey  <tom@tromey.com>

	* cli/cli-decode.h (cmd_list_element): New constructor.
	(~cmd_list_element): New destructor.
	(struct cmd_list_element): Add initializers.
	* cli/cli-decode.c (do_add_cmd): Use "new".
	(delete_cmd): Use "delete".
This commit is contained in:
Tom Tromey 2018-04-16 21:09:48 -06:00
parent a3b60e4588
commit e2fc72e2c5
3 changed files with 62 additions and 55 deletions

View file

@ -193,7 +193,8 @@ static struct cmd_list_element *
do_add_cmd (const char *name, enum command_class theclass,
const char *doc, struct cmd_list_element **list)
{
struct cmd_list_element *c = XNEW (struct cmd_list_element);
struct cmd_list_element *c = new struct cmd_list_element (name, theclass,
doc);
struct cmd_list_element *p, *iter;
/* Turn each alias of the old command into an alias of the new
@ -227,34 +228,6 @@ do_add_cmd (const char *name, enum command_class theclass,
p->next = c;
}
c->name = name;
c->theclass = theclass;
set_cmd_context (c, NULL);
c->doc = doc;
c->cmd_deprecated = 0;
c->deprecated_warn_user = 0;
c->malloced_replacement = 0;
c->doc_allocated = 0;
c->replacement = NULL;
c->pre_show_hook = NULL;
c->hook_in = 0;
c->prefixlist = NULL;
c->prefixname = NULL;
c->allow_unknown = 0;
c->prefix = NULL;
c->abbrev_flag = 0;
set_cmd_completer (c, symbol_completer);
c->completer_handle_brkchars = NULL;
c->destroyer = NULL;
c->type = not_set_cmd;
c->var = NULL;
c->var_type = var_boolean;
c->enums = NULL;
c->user_commands = NULL;
c->cmd_pointer = NULL;
c->alias_chain = NULL;
c->suppress_notification = NULL;
return c;
}
@ -841,8 +814,6 @@ delete_cmd (const char *name, struct cmd_list_element **list,
*prehookee = iter->hookee_pre;
if (iter->hookee_post)
iter->hookee_post->hook_post = 0;
if (iter->doc && iter->doc_allocated)
xfree ((char *) iter->doc);
*posthook = iter->hook_post;
*posthookee = iter->hookee_post;
@ -866,7 +837,7 @@ delete_cmd (const char *name, struct cmd_list_element **list,
*prevp = iter->alias_chain;
}
xfree (iter);
delete iter;
/* We won't see another command with the same name. */
break;