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.
+
+2018-07-17 Tom Tromey <tom@tromey.com>
+
* guile/guile.c (gdbscm_eval_from_control_command): Update.
* guile/guile-internal.h (gdbscm_safe_eval_string): Update.
* guile/scm-objfile.c (gdbscm_execute_objfile_script): Update.
extern SCM gdbscm_scm_from_printf (const char *format, ...)
ATTRIBUTE_PRINTF (1, 2);
-extern char *gdbscm_scm_to_string (SCM string, size_t *lenp,
- const char *charset,
- int strict, SCM *except_scmp);
+extern gdb::unique_xmalloc_ptr<char> gdbscm_scm_to_string
+ (SCM string, size_t *lenp, const char *charset, int strict, SCM *except_scmp);
extern SCM gdbscm_scm_from_string (const char *string, size_t len,
const char *charset, int strict);
-extern char *gdbscm_scm_to_host_string (SCM string, size_t *lenp, SCM *except);
+extern gdb::unique_xmalloc_ptr<char> gdbscm_scm_to_host_string
+ (SCM string, size_t *lenp, SCM *except);
extern SCM gdbscm_scm_from_host_string (const char *string, size_t len);
}
gdb::unique_xmalloc_ptr<char> item
- (gdbscm_scm_to_string (completion, NULL, host_charset (), 1,
- &except_scm));
+ = gdbscm_scm_to_string (completion, NULL, host_charset (), 1,
+ &except_scm);
if (item == NULL)
{
/* Inform the user, but otherwise ignore the entire result. */
}
else if (scm_is_string (obj))
{
- char *s;
size_t len;
struct cleanup *cleanup;
else
{
/* TODO: Provide option to specify conversion strategy. */
- s = gdbscm_scm_to_string (obj, &len,
+ gdb::unique_xmalloc_ptr<char> s
+ = gdbscm_scm_to_string (obj, &len,
target_charset (gdbarch),
0 /*non-strict*/,
&except_scm);
if (s != NULL)
- {
- cleanup = make_cleanup (xfree, s);
- value
- = value_cstring (s, len,
- language_string_char_type (language,
- gdbarch));
- do_cleanups (cleanup);
- }
+ value = value_cstring (s.get (), len,
+ language_string_char_type (language,
+ gdbarch));
else
value = NULL;
}
{
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));
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
{
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));
_("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
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);
}
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,
}
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);
}
END_CATCH
- xfree (name);
xfree (newarg);
GDBSCM_HANDLE_GDB_EXCEPTION (except);
if (!found)
}
else if (scm_is_string (str_scm))
{
- struct cleanup *cleanup;
size_t length;
- char *string
+ gdb::unique_xmalloc_ptr<char> string
= gdbscm_scm_to_string (str_scm, &length,
target_charset (gdbarch), 0 /*!strict*/, NULL);
- cleanup = make_cleanup (xfree, string);
if (hint == HINT_STRING)
{
struct type *type = builtin_type (gdbarch)->builtin_char;
- LA_PRINT_STRING (stream, type, (gdb_byte *) string,
+ LA_PRINT_STRING (stream, type, (gdb_byte *) string.get (),
length, NULL, 0, options);
}
else
for (i = 0; i < length; ++i)
{
- if (string[i] == '\0')
+ if (string.get ()[i] == '\0')
fputs_filtered ("\\000", stream);
else
- fputc_filtered (string[i], stream);
+ fputc_filtered (string.get ()[i], stream);
}
}
result = STRING_REPR_OK;
- do_cleanups (cleanup);
}
else if (lsscm_is_lazy_string (str_scm))
{
If STRICT is zero, then escape sequences are used for characters that
can't be converted, and EXCEPT_SCMP may be passed as NULL.
- Space for the result is allocated with malloc, caller must free.
It is an error to call this if STRING is not a string. */
-char *
+gdb::unique_xmalloc_ptr<char>
gdbscm_scm_to_string (SCM string, size_t *lenp,
const char *charset, int strict, SCM *except_scmp)
{
if (gdbscm_is_false (scm_result))
{
gdb_assert (data.result != NULL);
- return data.result;
+ return gdb::unique_xmalloc_ptr<char> (data.result);
}
gdb_assert (gdbscm_is_exception (scm_result));
*except_scmp = scm_result;
Returns NULL if there is a conversion error, with the exception object
stored in *EXCEPT_SCMP.
- Space for the result is allocated with malloc, caller must free.
It is an error to call this if STRING is not a string. */
-char *
+gdb::unique_xmalloc_ptr<char>
gdbscm_scm_to_host_string (SCM string, size_t *lenp, SCM *except_scmp)
{
return gdbscm_scm_to_string (string, lenp, host_charset (), 1, except_scmp);