Change gdbscm_exception_message_to_string to return a unique_xmalloc_ptr

This changes gdbscm_exception_message_to_string to return a
unique_xmalloc_ptr, allowing for the removal of some cleanups.
unique_xmalloc_ptr was chosen because at the root of the call chains
is a function from Guile that returns a malloc'd string.

gdb/ChangeLog
2018-07-17  Tom Tromey  <tom@tromey.com>

	* guile/scm-param.c (pascm_signal_setshow_error): Update.
	* guile/guile-internal.h (gdbscm_exception_message_to_string):
	Update.
	* guile/scm-cmd.c (cmdscm_function): Update.
	* guile/scm-pretty-print.c
	(ppscm_print_exception_unless_memory_error): Update.
	* guile/scm-exception.c (gdbscm_exception_message_to_string):
	Return unique_xmalloc_ptr.
This commit is contained in:
Tom Tromey 2018-05-26 23:21:23 -06:00
parent 7eb1a66c26
commit 15bf30027b
6 changed files with 31 additions and 23 deletions

View file

@ -575,16 +575,13 @@ gdbscm_print_gdb_exception (SCM port, SCM exception)
/* Return a string description of <gdb:exception> EXCEPTION.
If EXCEPTION is a gdb:with-stack exception, unwrap it, a backtrace
is never returned as part of the result.
is never returned as part of the result. */
Space for the result is malloc'd, the caller must free. */
char *
gdb::unique_xmalloc_ptr<char>
gdbscm_exception_message_to_string (SCM exception)
{
SCM port = scm_open_output_string ();
SCM key, args;
char *result;
gdb_assert (gdbscm_is_exception (exception));
@ -601,9 +598,9 @@ gdbscm_exception_message_to_string (SCM exception)
}
gdbscm_print_exception_message (port, SCM_BOOL_F, key, args);
result = gdbscm_scm_to_c_string (scm_get_output_string (port));
gdb::unique_xmalloc_ptr<char> result
(gdbscm_scm_to_c_string (scm_get_output_string (port)));
scm_close_port (port);
return result;
}