+2019-11-26 Tom Tromey <tom@tromey.com>
+
+ * value.h (add_internal_function): Add new overload. Move
+ documentation from value.h.
+ * value.c (do_add_internal_function): New function.
+ (add_internal_function): Use it. Add new overload.
+ (function_destroyer): Don't free doc.
+ * python/py-function.c (fnpy_init): Update.
+
2019-11-26 Tom Tromey <tom@tromey.com>
* python/py-cmd.c (cmdpy_destroyer): Don't free "doc".
function_destroyer (struct cmd_list_element *self, void *ignore)
{
xfree ((char *) self->name);
- xfree ((char *) self->doc);
}
-/* Add a new internal function. NAME is the name of the function; DOC
- is a documentation string describing the function. HANDLER is
- called when the function is invoked. COOKIE is an arbitrary
- pointer which is passed to HANDLER and is intended for "user
- data". */
-void
-add_internal_function (const char *name, const char *doc,
- internal_function_fn handler, void *cookie)
+/* 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;
cmd = add_cmd (xstrdup (name), no_class, function_command, (char *) doc,
&functionlist);
cmd->destroyer = function_destroyer;
+
+ return cmd;
+}
+
+/* See value.h. */
+
+void
+add_internal_function (const char *name, const char *doc,
+ internal_function_fn handler, void *cookie)
+{
+ do_add_internal_function (name, doc, handler, cookie);
+}
+
+/* See value.h. */
+
+void
+add_internal_function (const 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);
+ doc.release ();
+ cmd->doc_allocated = 1;
}
/* Update VALUE before discarding OBJFILE. COPIED_TYPES is used to
int argc,
struct value **argv);
-void add_internal_function (const char *name, const char *doc,
- internal_function_fn handler,
- void *cookie);
+/* Add a new internal function. NAME is the name of the function; DOC
+ is a documentation string describing the function. HANDLER is
+ called when the function is invoked. COOKIE is an arbitrary
+ pointer which is passed to HANDLER and is intended for "user
+ data". */
+
+extern void add_internal_function (const char *name, const char *doc,
+ internal_function_fn handler,
+ void *cookie);
+
+/* This overload takes an allocated documentation string. */
+
+extern void add_internal_function (const char *name,
+ gdb::unique_xmalloc_ptr<char> &&doc,
+ internal_function_fn handler,
+ void *cookie);
struct value *call_internal_function (struct gdbarch *gdbarch,
const struct language_defn *language,