aboutsummaryrefslogtreecommitdiff
path: root/gdb/value.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-11-15 16:56:20 -0700
committerTom Tromey <tom@tromey.com>2019-11-26 14:20:30 -0700
commit3ea16160a66e0e3bc59842e27e41890411729a86 (patch)
treeff0b73e9b147676969cefb85ba6fe24c88374473 /gdb/value.c
parent1a6d41c6433a0980f302c480b1d1db71234b49e4 (diff)
downloadgdb-3ea16160a66e0e3bc59842e27e41890411729a86.zip
gdb-3ea16160a66e0e3bc59842e27e41890411729a86.tar.gz
gdb-3ea16160a66e0e3bc59842e27e41890411729a86.tar.bz2
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
Diffstat (limited to 'gdb/value.c')
-rw-r--r--gdb/value.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/gdb/value.c b/gdb/value.c
index 8e22ac7..57e62b9 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2421,31 +2421,19 @@ function_command (const char *command, int from_tty)
/* Do nothing. */
}
-/* Clean up if an internal function's command is destroyed. */
-static void
-function_destroyer (struct cmd_list_element *self, void *ignore)
-{
- xfree ((char *) self->name);
-}
-
/* Helper function that does the work for add_internal_function. */
static struct cmd_list_element *
do_add_internal_function (const char *name, const char *doc,
internal_function_fn handler, void *cookie)
{
- struct cmd_list_element *cmd;
struct internal_function *ifn;
struct internalvar *var = lookup_internalvar (name);
ifn = create_internal_function (name, handler, cookie);
set_internalvar_function (var, ifn);
- cmd = add_cmd (xstrdup (name), no_class, function_command, (char *) doc,
- &functionlist);
- cmd->destroyer = function_destroyer;
-
- return cmd;
+ return add_cmd (name, no_class, function_command, doc, &functionlist);
}
/* See value.h. */
@@ -2460,13 +2448,16 @@ add_internal_function (const char *name, const char *doc,
/* See value.h. */
void
-add_internal_function (const char *name, gdb::unique_xmalloc_ptr<char> &&doc,
+add_internal_function (gdb::unique_xmalloc_ptr<char> &&name,
+ gdb::unique_xmalloc_ptr<char> &&doc,
internal_function_fn handler, void *cookie)
{
struct cmd_list_element *cmd
- = do_add_internal_function (name, doc.get (), handler, cookie);
+ = do_add_internal_function (name.get (), doc.get (), handler, cookie);
doc.release ();
cmd->doc_allocated = 1;
+ name.release ();
+ cmd->name_allocated = 1;
}
/* Update VALUE before discarding OBJFILE. COPIED_TYPES is used to