+2018-07-19 Pedro Alves <palves@redhat.com>
+
+ * guile/guile-internal.h (gdbscm_scm_to_c_string): Now returns a
+ gdb::unique_xmalloc_ptr.
+ * guile/scm-breakpoint.c (gdbscm_set_breakpoint_condition_x):
+ Adjust to use dbscm_wrap and gdb::unique_xmalloc_ptr.
+ * guile/scm-exception.c (gdbscm_exception_message_to_string): Use
+ copy-initialization.
+ * guile/scm-pretty-print.c (ppscm_print_children): Use
+ gdb::unique_xmalloc_ptr instead of cleanups.
+ (gdbscm_apply_val_pretty_printer): Remove cleanups.
+ * guile/scm-string.c (gdbscm_scm_to_c_string): Now returns a
+ gdb::unique_xmalloc_ptr.
+ * guile/scm-type.c (gdbscm_type_field, gdbscm_type_has_field_p):
+ Adjust to use gdb::unique_xmalloc_ptr.
+ * guile/scm-utils.c (extract_arg): Adjust.
+ * guile/scm-value.c (gdbscm_value_field): Adjust to use
+ gdb::unique_xmalloc_ptr instead of a cleanup.
+
2018-07-19 Tom Tromey <tom@tromey.com>
* utils.c (do_value_free_to_mark)
extern int gdbscm_scm_string_to_int (SCM string);
-extern char *gdbscm_scm_to_c_string (SCM string);
+extern gdb::unique_xmalloc_ptr<char> gdbscm_scm_to_c_string (SCM string);
extern SCM gdbscm_scm_from_c_string (const char *string);
{
breakpoint_smob *bp_smob
= bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
- char *exp;
- struct gdb_exception except = exception_none;
SCM_ASSERT_TYPE (scm_is_string (newvalue) || gdbscm_is_false (newvalue),
newvalue, SCM_ARG2, FUNC_NAME,
_("string or #f"));
- if (gdbscm_is_false (newvalue))
- exp = NULL;
- else
- exp = gdbscm_scm_to_c_string (newvalue);
-
- TRY
- {
- set_breakpoint_condition (bp_smob->bp, exp ? exp : "", 0);
- }
- CATCH (ex, RETURN_MASK_ALL)
+ return gdbscm_wrap ([=]
{
- except = ex;
- }
- END_CATCH
+ gdb::unique_xmalloc_ptr<char> exp
+ = (gdbscm_is_false (newvalue)
+ ? nullptr
+ : gdbscm_scm_to_c_string (newvalue));
- xfree (exp);
- GDBSCM_HANDLE_GDB_EXCEPTION (except);
+ set_breakpoint_condition (bp_smob->bp, exp ? exp.get () : "", 0);
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
+ });
}
/* (breakpoint-stop <gdb:breakpoint>) -> procedure or #f */
gdbscm_print_exception_message (port, SCM_BOOL_F, key, args);
gdb::unique_xmalloc_ptr<char> result
- (gdbscm_scm_to_c_string (scm_get_output_string (port)));
+ = gdbscm_scm_to_c_string (scm_get_output_string (port));
scm_close_port (port);
return result;
}
unsigned int i;
SCM children;
SCM iter = SCM_BOOL_F; /* -Wall */
- struct cleanup *cleanups;
if (gdbscm_is_false (w_smob->children))
return;
return;
}
- cleanups = make_cleanup (null_cleanup, NULL);
-
/* If we are printing a map or an array, we want special formatting. */
is_map = hint == HINT_MAP;
is_array = hint == HINT_ARRAY;
for (i = 0; i < options->print_max; ++i)
{
SCM scm_name, v_scm;
- char *name;
SCM item = itscm_safe_call_next_x (iter, gdbscm_memory_error_p);
- struct cleanup *inner_cleanup = make_cleanup (null_cleanup, NULL);
if (gdbscm_is_exception (item))
{
" a string"), item);
continue;
}
- name = gdbscm_scm_to_c_string (scm_name);
- make_cleanup (xfree, name);
+ gdb::unique_xmalloc_ptr<char> name
+ = gdbscm_scm_to_c_string (scm_name);
/* Print initial "{". For other elements, there are three cases:
1. Maps. Print a "," after each value element.
}
else if (! is_map)
{
- fputs_filtered (name, stream);
+ fputs_filtered (name.get (), stream);
fputs_filtered (" = ", stream);
}
}
else if (scm_is_string (v_scm))
{
- char *output = gdbscm_scm_to_c_string (v_scm);
-
- fputs_filtered (output, stream);
- xfree (output);
+ gdb::unique_xmalloc_ptr<char> output
+ = gdbscm_scm_to_c_string (v_scm);
+ fputs_filtered (output.get (), stream);
}
else
{
if (is_map && i % 2 == 0)
fputs_filtered ("] = ", stream);
-
- do_cleanups (inner_cleanup);
}
if (i)
}
done:
- do_cleanups (cleanups);
-
/* Play it safe, make sure ITER doesn't get GC'd. */
scm_remember_upto_here_1 (iter);
}
SCM val_obj = SCM_BOOL_F;
struct value *value;
enum display_hint hint;
- struct cleanup *cleanups;
enum ext_lang_rc result = EXT_LANG_RC_NOP;
enum string_repr_result print_result;
const gdb_byte *valaddr = value_contents_for_printing (val);
if (!gdb_scheme_initialized)
return EXT_LANG_RC_NOP;
- cleanups = make_cleanup (null_cleanup, NULL);
-
/* Instantiate the printer. */
value = value_from_component (val, type, embedded_offset);
done:
if (gdbscm_is_exception (exception))
ppscm_print_exception_unless_memory_error (exception, stream);
- do_cleanups (cleanups);
return result;
}
\f
/* Convert an SCM string to a C (latin1) string.
"latin1" is chosen because Guile won't throw an exception.
- 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_c_string (SCM string)
{
- return scm_to_latin1_string (string);
+ return gdb::unique_xmalloc_ptr<char> (scm_to_latin1_string (string));
}
/* Use printf to construct a Scheme string. */
type_smob *t_smob
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- char *field;
- int i;
SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
_("string"));
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
_(not_composite_error));
- field = gdbscm_scm_to_c_string (field_scm);
-
- for (i = 0; i < TYPE_NFIELDS (type); i++)
- {
- const char *t_field_name = TYPE_FIELD_NAME (type, i);
+ {
+ gdb::unique_xmalloc_ptr<char> field = gdbscm_scm_to_c_string (field_scm);
- if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
- {
- xfree (field);
- return tyscm_make_field_smob (self, i);
- }
- }
+ for (int i = 0; i < TYPE_NFIELDS (type); i++)
+ {
+ const char *t_field_name = TYPE_FIELD_NAME (type, i);
- xfree (field);
+ if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
+ {
+ field.reset (nullptr);
+ return tyscm_make_field_smob (self, i);
+ }
+ }
+ }
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, field_scm,
_("Unknown field"));
type_smob *t_smob
= tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
struct type *type = t_smob->type;
- char *field;
- int i;
SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
_("string"));
gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
_(not_composite_error));
- field = gdbscm_scm_to_c_string (field_scm);
+ {
+ gdb::unique_xmalloc_ptr<char> field
+ = gdbscm_scm_to_c_string (field_scm);
- for (i = 0; i < TYPE_NFIELDS (type); i++)
- {
- const char *t_field_name = TYPE_FIELD_NAME (type, i);
+ for (int i = 0; i < TYPE_NFIELDS (type); i++)
+ {
+ const char *t_field_name = TYPE_FIELD_NAME (type, i);
- if (t_field_name && (strcmp_iw (t_field_name, field) == 0))
- {
- xfree (field);
+ if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
return SCM_BOOL_T;
- }
- }
-
- xfree (field);
+ }
+ }
return SCM_BOOL_F;
}
CHECK_TYPE (gdbscm_is_true (scm_string_p (arg)), arg, position,
func_name, _("string"));
- *arg_ptr = gdbscm_scm_to_c_string (arg);
+ *arg_ptr = gdbscm_scm_to_c_string (arg).release ();
break;
}
case 't':
{
scoped_value_mark free_values;
- char *field = gdbscm_scm_to_c_string (field_scm);
-
- struct cleanup *cleanups = make_cleanup (xfree, field);
+ gdb::unique_xmalloc_ptr<char> field = gdbscm_scm_to_c_string (field_scm);
struct value *tmp = v_smob->value;
- struct value *res_val = value_struct_elt (&tmp, NULL, field, NULL,
+ struct value *res_val = value_struct_elt (&tmp, NULL, field.get (), NULL,
"struct/class/union");
- SCM result = vlscm_scm_from_value (res_val);
-
- do_cleanups (cleanups);
-
- return result;
+ return vlscm_scm_from_value (res_val);
});
}