forked from Imagelibrary/binutils-gdb
gdb: change set_internalvar_function to take a unique pointer
This makes the transfer of ownership a bit clearer, even though the internal_function is still held with a raw pointer inside internalval. Change-Id: Ie8d13270b64737b92291532acfbfcbc992b482b5 Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
This commit is contained in:
14
gdb/value.c
14
gdb/value.c
@@ -74,6 +74,8 @@ struct internal_function
|
|||||||
void *cookie;
|
void *cookie;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using internal_function_up = std::unique_ptr<internal_function>;
|
||||||
|
|
||||||
/* Returns true if the ranges defined by [offset1, offset1+len1) and
|
/* Returns true if the ranges defined by [offset1, offset1+len1) and
|
||||||
[offset2, offset2+len2) overlap. */
|
[offset2, offset2+len2) overlap. */
|
||||||
|
|
||||||
@@ -2297,13 +2299,13 @@ set_internalvar_string (struct internalvar *var, const char *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_internalvar_function (struct internalvar *var, struct internal_function *f)
|
set_internalvar_function (internalvar *var, internal_function_up f)
|
||||||
{
|
{
|
||||||
/* Clean up old contents. */
|
/* Clean up old contents. */
|
||||||
clear_internalvar (var);
|
clear_internalvar (var);
|
||||||
|
|
||||||
var->kind = INTERNALVAR_FUNCTION;
|
var->kind = INTERNALVAR_FUNCTION;
|
||||||
var->u.fn.function = f;
|
var->u.fn.function = f.release ();
|
||||||
var->u.fn.canonical = 1;
|
var->u.fn.canonical = 1;
|
||||||
/* Variables installed here are always the canonical version. */
|
/* Variables installed here are always the canonical version. */
|
||||||
}
|
}
|
||||||
@@ -2385,11 +2387,9 @@ static struct cmd_list_element *
|
|||||||
do_add_internal_function (const char *name, const char *doc,
|
do_add_internal_function (const char *name, const char *doc,
|
||||||
internal_function_fn_noside handler, void *cookie)
|
internal_function_fn_noside handler, void *cookie)
|
||||||
{
|
{
|
||||||
struct internal_function *ifn;
|
set_internalvar_function (lookup_internalvar (name),
|
||||||
struct internalvar *var = lookup_internalvar (name);
|
std::make_unique<internal_function> (name, handler,
|
||||||
|
cookie));
|
||||||
ifn = new internal_function (name, handler, cookie);
|
|
||||||
set_internalvar_function (var, ifn);
|
|
||||||
|
|
||||||
return add_cmd (name, no_class, function_command, doc, &functionlist);
|
return add_cmd (name, no_class, function_command, doc, &functionlist);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user