aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-param.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-05-26 23:34:02 -0600
committerTom Tromey <tom@tromey.com>2018-07-17 13:21:48 -0600
commitc6c6149af440c3032eb7d02c2852907c61aac470 (patch)
treec2f5e25dc0448ab794d148ccea81afd71fb0d248 /gdb/guile/scm-param.c
parenta1a31cb8dce7d1bfa7878dc08c28af330ef2ed69 (diff)
downloadgdb-c6c6149af440c3032eb7d02c2852907c61aac470.zip
gdb-c6c6149af440c3032eb7d02c2852907c61aac470.tar.gz
gdb-c6c6149af440c3032eb7d02c2852907c61aac470.tar.bz2
Return unique_xmalloc_ptr from gdbscm_scm_to_string
This changes gdbscm_scm_to_string to return a unique_xmalloc_ptr and then fixes all the callers. This allows for the removal of some cleanups. gdb/ChangeLog 2018-07-17 Tom Tromey <tom@tromey.com> * guile/scm-param.c (pascm_set_func, pascm_show_func) (compute_enum_list, pascm_set_param_value_x) (gdbscm_parameter_value): Update. * guile/guile-internal.h (gdbscm_scm_to_string): Update. (gdbscm_scm_to_host_string): Update. * guile/scm-math.c (vlscm_convert_typed_value_from_scheme): Update. * guile/scm-cmd.c (cmdscm_add_completion): Update. * guile/scm-pretty-print.c (ppscm_print_string_repr): Update. * guile/scm-string.c (gdbscm_scm_to_string): Return unique_xmalloc_ptr. (gdbscm_scm_to_host_string): Likewise.
Diffstat (limited to 'gdb/guile/scm-param.c')
-rw-r--r--gdb/guile/scm-param.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c
index 7ff4af9..29ebf0e 100644
--- a/gdb/guile/scm-param.c
+++ b/gdb/guile/scm-param.c
@@ -273,8 +273,6 @@ pascm_set_func (const char *args, int from_tty, struct cmd_list_element *c)
{
param_smob *p_smob = (param_smob *) get_cmd_context (c);
SCM self, result, exception;
- char *msg;
- struct cleanup *cleanups;
gdb_assert (gdbscm_is_procedure (p_smob->set_func));
@@ -291,18 +289,17 @@ pascm_set_func (const char *args, int from_tty, struct cmd_list_element *c)
if (!scm_is_string (result))
error (_("Result of %s set-func is not a string."), p_smob->name);
- msg = gdbscm_scm_to_host_string (result, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> msg = gdbscm_scm_to_host_string (result, NULL,
+ &exception);
if (msg == NULL)
{
gdbscm_print_gdb_exception (SCM_BOOL_F, exception);
error (_("Error converting show text to host string."));
}
- cleanups = make_cleanup (xfree, msg);
/* GDB is usually silent when a parameter is set. */
- if (*msg != '\0')
- fprintf_filtered (gdb_stdout, "%s\n", msg);
- do_cleanups (cleanups);
+ if (*msg.get () != '\0')
+ fprintf_filtered (gdb_stdout, "%s\n", msg.get ());
}
/* A callback function that is registered against the respective
@@ -316,8 +313,6 @@ pascm_show_func (struct ui_file *file, int from_tty,
{
param_smob *p_smob = (param_smob *) get_cmd_context (c);
SCM value_scm, self, result, exception;
- char *msg;
- struct cleanup *cleanups;
gdb_assert (gdbscm_is_procedure (p_smob->show_func));
@@ -338,16 +333,15 @@ pascm_show_func (struct ui_file *file, int from_tty,
_("Error occurred showing parameter."));
}
- msg = gdbscm_scm_to_host_string (result, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> msg = gdbscm_scm_to_host_string (result, NULL,
+ &exception);
if (msg == NULL)
{
gdbscm_print_gdb_exception (SCM_BOOL_F, exception);
error (_("Error converting show text to host string."));
}
- cleanups = make_cleanup (xfree, msg);
- fprintf_filtered (file, "%s\n", msg);
- do_cleanups (cleanups);
+ fprintf_filtered (file, "%s\n", msg.get ());
}
/* A helper function that dispatches to the appropriate add_setshow
@@ -516,7 +510,8 @@ compute_enum_list (SCM enum_values_scm, int arg_pos, const char *func_name)
freeargv (enum_values);
SCM_ASSERT_TYPE (0, value, arg_pos, func_name, _("string"));
}
- enum_values[i] = gdbscm_scm_to_host_string (value, NULL, &exception);
+ enum_values[i] = gdbscm_scm_to_host_string (value, NULL,
+ &exception).release ();
if (enum_values[i] == NULL)
{
freeargv (enum_values);
@@ -683,34 +678,33 @@ pascm_set_param_value_x (enum var_types type, union pascm_variable *var,
}
else
{
- char *string;
SCM exception;
- string = gdbscm_scm_to_host_string (value, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> string
+ = gdbscm_scm_to_host_string (value, NULL, &exception);
if (string == NULL)
gdbscm_throw (exception);
xfree (var->stringval);
- var->stringval = string;
+ var->stringval = string.release ();
}
break;
case var_enum:
{
int i;
- char *str;
SCM exception;
SCM_ASSERT_TYPE (scm_is_string (value), value, arg_pos, func_name,
_("string"));
- str = gdbscm_scm_to_host_string (value, NULL, &exception);
+ gdb::unique_xmalloc_ptr<char> str
+ = gdbscm_scm_to_host_string (value, NULL, &exception);
if (str == NULL)
gdbscm_throw (exception);
for (i = 0; enumeration[i]; ++i)
{
- if (strcmp (enumeration[i], str) == 0)
+ if (strcmp (enumeration[i], str.get ()) == 0)
break;
}
- xfree (str);
if (enumeration[i] == NULL)
{
gdbscm_out_of_range_error (func_name, arg_pos, value,
@@ -1059,17 +1053,17 @@ gdbscm_parameter_value (SCM self)
}
else
{
- char *name;
SCM except_scm;
struct cmd_list_element *alias, *prefix, *cmd;
char *newarg;
int found = -1;
struct gdb_exception except = exception_none;
- name = gdbscm_scm_to_host_string (self, NULL, &except_scm);
+ gdb::unique_xmalloc_ptr<char> name
+ = gdbscm_scm_to_host_string (self, NULL, &except_scm);
if (name == NULL)
gdbscm_throw (except_scm);
- newarg = concat ("show ", name, (char *) NULL);
+ newarg = concat ("show ", name.get (), (char *) NULL);
TRY
{
found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
@@ -1080,7 +1074,6 @@ gdbscm_parameter_value (SCM self)
}
END_CATCH
- xfree (name);
xfree (newarg);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
if (!found)