From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59826 invoked by alias); 19 May 2018 16:06:13 -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 59779 invoked by uid 89); 19 May 2018 16:06:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 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=sk:discard, unbounded, breakpoint_at X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.91) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 May 2018 16:06:11 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway31.websitewelcome.com (Postfix) with ESMTP id B2C501738C8 for ; Sat, 19 May 2018 11:06:09 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id K4MzfwVNolAdrK4MzfS5zd; Sat, 19 May 2018 11:06:09 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:37004 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fK4Mz-002Uoe-G6; Sat, 19 May 2018 11:06:09 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/3] Remove cleanup from ada-lang.c Date: Sat, 19 May 2018 20:37:00 -0000 Message-Id: <20180519160606.19969-2-tom@tromey.com> In-Reply-To: <20180519160606.19969-1-tom@tromey.com> References: <20180519160606.19969-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fK4Mz-002Uoe-G6 X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:37004 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-05/txt/msg00441.txt.bz2 This removes a cleanup from ada-lang.c by having ada_exception_message_1 return a unique_xmalloc_ptr. gdb/ChangeLog 2018-05-18 Tom Tromey * ada-lang.c (ada_exception_message_1, ada_exception_message): Return unique_xmalloc_ptr. (print_it_exception): Update. --- gdb/ChangeLog | 6 ++++++ gdb/ada-lang.c | 29 +++++++++-------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7cbf1ec08d..da5f75030c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12342,8 +12342,6 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex, return the message which was associated to the exception, if available. Return NULL if the message could not be retrieved. - The caller must xfree the string after use. - Note: The exception message can be associated to an exception either through the use of the Raise_Exception function, or more simply (Ada 2005 and later), via: @@ -12352,13 +12350,11 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex, */ -static char * +static gdb::unique_xmalloc_ptr ada_exception_message_1 (void) { struct value *e_msg_val; - char *e_msg = NULL; int e_msg_len; - struct cleanup *cleanups; /* For runtimes that support this feature, the exception message is passed as an unbounded string argument called "message". */ @@ -12375,22 +12371,20 @@ ada_exception_message_1 (void) if (e_msg_len <= 0) return NULL; - e_msg = (char *) xmalloc (e_msg_len + 1); - cleanups = make_cleanup (xfree, e_msg); - read_memory_string (value_address (e_msg_val), e_msg, e_msg_len + 1); - e_msg[e_msg_len] = '\0'; + gdb::unique_xmalloc_ptr e_msg ((char *) xmalloc (e_msg_len + 1)); + read_memory_string (value_address (e_msg_val), e_msg.get (), e_msg_len + 1); + e_msg.get ()[e_msg_len] = '\0'; - discard_cleanups (cleanups); return e_msg; } /* Same as ada_exception_message_1, except that all exceptions are contained here (returning NULL instead). */ -static char * +static gdb::unique_xmalloc_ptr ada_exception_message (void) { - char *e_msg = NULL; /* Avoid a spurious uninitialized warning. */ + gdb::unique_xmalloc_ptr e_msg; TRY { @@ -12398,7 +12392,7 @@ ada_exception_message (void) } CATCH (e, RETURN_MASK_ERROR) { - e_msg = NULL; + e_msg.reset (nullptr); } END_CATCH @@ -12639,7 +12633,6 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs) { struct ui_out *uiout = current_uiout; struct breakpoint *b = bs->breakpoint_at; - char *exception_message; annotate_catchpoint (b->number); @@ -12707,16 +12700,12 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs) break; } - exception_message = ada_exception_message (); + gdb::unique_xmalloc_ptr exception_message = ada_exception_message (); if (exception_message != NULL) { - struct cleanup *cleanups = make_cleanup (xfree, exception_message); - uiout->text (" ("); - uiout->field_string ("exception-message", exception_message); + uiout->field_string ("exception-message", exception_message.get ()); uiout->text (")"); - - do_cleanups (cleanups); } uiout->text (" at "); -- 2.13.6