From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59611 invoked by alias); 27 May 2018 15:20:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 59479 invoked by uid 89); 27 May 2018 15:20:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Space, 25110 X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.31) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 27 May 2018 15:20:14 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 4E356F795 for ; Sun, 27 May 2018 10:20:13 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MxSvfzmxLBcCXMxSvft6YP; Sun, 27 May 2018 10:20:13 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:51012 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fMxSv-004Ahx-0h; Sun, 27 May 2018 10:20:13 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/4] Change gdbscm_exception_message_to_string to return a unique_xmalloc_ptr Date: Sun, 27 May 2018 15:40:00 -0000 Message-Id: <20180527152009.4228-3-tom@tromey.com> In-Reply-To: <20180527152009.4228-1-tom@tromey.com> References: <20180527152009.4228-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fMxSv-004Ahx-0h X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:51012 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-05/txt/msg00717.txt.bz2 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. ChangeLog 2018-05-26 Tom Tromey * 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. --- gdb/ChangeLog | 11 +++++++++++ gdb/guile/guile-internal.h | 3 ++- gdb/guile/scm-cmd.c | 6 +++--- gdb/guile/scm-exception.c | 11 ++++------- gdb/guile/scm-param.c | 6 +++--- gdb/guile/scm-pretty-print.c | 17 ++++++++--------- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h index 6bce58e150..20e2c70e16 100644 --- a/gdb/guile/guile-internal.h +++ b/gdb/guile/guile-internal.h @@ -362,7 +362,8 @@ extern void gdbscm_print_exception_with_stack (SCM port, SCM stack, extern void gdbscm_print_gdb_exception (SCM port, SCM exception); -extern char *gdbscm_exception_message_to_string (SCM exception); +extern gdb::unique_xmalloc_ptr gdbscm_exception_message_to_string + (SCM exception); extern excp_matcher_func gdbscm_memory_error_p; diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c index 64243d1ba2..8bb46622a9 100644 --- a/gdb/guile/scm-cmd.c +++ b/gdb/guile/scm-cmd.c @@ -316,10 +316,10 @@ cmdscm_function (struct cmd_list_element *command, itself. */ if (gdbscm_user_error_p (gdbscm_exception_key (result))) { - char *msg = gdbscm_exception_message_to_string (result); + gdb::unique_xmalloc_ptr msg + = gdbscm_exception_message_to_string (result); - make_cleanup (xfree, msg); - error ("%s", msg); + error ("%s", msg.get ()); } else { diff --git a/gdb/guile/scm-exception.c b/gdb/guile/scm-exception.c index e4b81a1fd1..f0bcdcd49e 100644 --- a/gdb/guile/scm-exception.c +++ b/gdb/guile/scm-exception.c @@ -575,16 +575,13 @@ gdbscm_print_gdb_exception (SCM port, SCM exception) /* Return a string description of 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 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 result + (gdbscm_scm_to_c_string (scm_get_output_string (port))); scm_close_port (port); - return result; } diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c index d48f14e55c..7ff4af9501 100644 --- a/gdb/guile/scm-param.c +++ b/gdb/guile/scm-param.c @@ -251,10 +251,10 @@ pascm_signal_setshow_error (SCM exception, const char *msg) itself. */ if (gdbscm_user_error_p (gdbscm_exception_key (exception))) { - char *excp_text = gdbscm_exception_message_to_string (exception); + gdb::unique_xmalloc_ptr excp_text + = gdbscm_exception_message_to_string (exception); - make_cleanup (xfree, excp_text); - error ("%s", excp_text); + error ("%s", excp_text.get ()); } else { diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c index 5e8a2a998d..eea524b104 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 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, _("")); 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, _(""), msg); + if (msg_text[len - 1] == '\n') + msg_text[len - 1] = '\0'; + fprintf_filtered (stream, _(""), msg_text); } - - do_cleanups (cleanup); } else gdbscm_print_gdb_exception (SCM_BOOL_F, exception); -- 2.13.6