Let commands free "name"
This adds a "name_allocated" field to cmd_list_element, so that commands can own their "name" when necessary. Then, this changes a few spots in gdb that currently free the name by hand to instead use this facility. gdb/ChangeLog 2019-11-26 Tom Tromey <tom@tromey.com> * python/py-function.c (fnpy_init): Update. * value.h (add_internal_function): Adjust declaration. * value.c (function_destroyer): Remove. (do_add_internal_function): Don't set destroyer or copy name. (add_internal_function): Take unique_xmalloc_ptr<char> for name. Set name_allocated. * python/py-cmd.c (cmdpy_destroyer): Don't free "name". (cmdpy_init): Set name_allocated. * cli/cli-decode.h (struct cmd_list_element) <name_allocated>: New member. (~cmd_list_element): Free "name" if needed. Change-Id: Ie1435cea5bbf4bd92056125f112917c607cbb761
This commit is contained in:
parent
1a6d41c643
commit
3ea16160a6
6 changed files with 32 additions and 20 deletions
|
@ -98,8 +98,7 @@ cmdpy_destroyer (struct cmd_list_element *self, void *context)
|
|||
gdbpy_ref<cmdpy_object> cmd ((cmdpy_object *) context);
|
||||
cmd->command = NULL;
|
||||
|
||||
/* We allocated the name and perhaps the prefix name. */
|
||||
xfree ((char *) self->name);
|
||||
/* We may have allocated the prefix name. */
|
||||
xfree ((char *) self->prefixname);
|
||||
}
|
||||
|
||||
|
@ -562,6 +561,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
|
|||
cmd->func = cmdpy_function;
|
||||
cmd->destroyer = cmdpy_destroyer;
|
||||
cmd->doc_allocated = 1;
|
||||
cmd->name_allocated = 1;
|
||||
|
||||
obj->command = cmd;
|
||||
set_cmd_context (cmd, self_ref.release ());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue