aboutsummaryrefslogtreecommitdiff
path: root/gdb/guile/scm-pretty-print.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-05-26 23:21:23 -0600
committerTom Tromey <tom@tromey.com>2018-07-17 13:21:47 -0600
commit15bf30027bcb167833a0ca2c619c03f177ef1ba4 (patch)
tree117580eb74accac812d65ad76bb839237f0ab4d3 /gdb/guile/scm-pretty-print.c
parent7eb1a66c26b57803bb4245f84cf15278297bb649 (diff)
downloadbinutils-15bf30027bcb167833a0ca2c619c03f177ef1ba4.zip
binutils-15bf30027bcb167833a0ca2c619c03f177ef1ba4.tar.gz
binutils-15bf30027bcb167833a0ca2c619c03f177ef1ba4.tar.bz2
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.
Diffstat (limited to 'gdb/guile/scm-pretty-print.c')
-rw-r--r--gdb/guile/scm-pretty-print.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index 5e8a2a9..eea524b 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -614,25 +614,24 @@ ppscm_print_exception_unless_memory_error (SCM exception,
{
if (gdbscm_memory_error_p (gdbscm_exception_key (exception)))
{
- char *msg = gdbscm_exception_message_to_string (exception);
- struct cleanup *cleanup = make_cleanup (xfree, msg);
+ gdb::unique_xmalloc_ptr<char> msg
+ = gdbscm_exception_message_to_string (exception);
/* This "shouldn't happen", but play it safe. */
- if (msg == NULL || *msg == '\0')
+ if (msg == NULL || msg.get ()[0] == '\0')
fprintf_filtered (stream, _("<error reading variable>"));
else
{
/* Remove the trailing newline. We could instead call a special
routine for printing memory error messages, but this is easy
enough for now. */
- size_t len = strlen (msg);
+ char *msg_text = msg.get ();
+ size_t len = strlen (msg_text);
- if (msg[len - 1] == '\n')
- msg[len - 1] = '\0';
- fprintf_filtered (stream, _("<error reading variable: %s>"), msg);
+ if (msg_text[len - 1] == '\n')
+ msg_text[len - 1] = '\0';
+ fprintf_filtered (stream, _("<error reading variable: %s>"), msg_text);
}
-
- do_cleanups (cleanup);
}
else
gdbscm_print_gdb_exception (SCM_BOOL_F, exception);