From patchwork Thu Nov 30 03:01:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24619 Received: (qmail 102528 invoked by alias); 30 Nov 2017 03:01:48 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 102351 invoked by uid 89); 30 Nov 2017 03:01:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 30 Nov 2017 03:01:45 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 64FFC6F7510 for ; Wed, 29 Nov 2017 21:01:44 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id KF6eeB7XiRtUXKF6eeIGDV; Wed, 29 Nov 2017 21:01:44 -0600 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:57898 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eKF6e-002PmB-65; Wed, 29 Nov 2017 21:01:44 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 4/6] Remove some more cleanups from ada-lang.c Date: Wed, 29 Nov 2017 20:01:38 -0700 Message-Id: <20171130030140.14830-5-tom@tromey.com> In-Reply-To: <20171130030140.14830-1-tom@tromey.com> References: <20171130030140.14830-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eKF6e-002PmB-65 X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.Home) [71.218.90.63]:57898 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes a few more cleanups from ada-lang.c by using unique_xmalloc_ptr in a couple of spots. ChangeLog 2017-11-29 Tom Tromey * ada-lang.c (ada_exception_message_1): Return unique_xmalloc_ptr. (ada_exception_message_1): Update. (ada_exception_message): Return unique_xmalloc_ptr. (print_it_exception): Update. --- gdb/ChangeLog | 8 ++++++++ gdb/ada-lang.c | 31 +++++++++---------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 0248663ba8..8d0ac60575 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12088,8 +12088,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: @@ -12098,13 +12096,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". */ @@ -12121,34 +12117,30 @@ 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); + gdb::unique_xmalloc_ptr result ((char *) xmalloc (e_msg_len + 1)); + char *e_msg = result.get (); read_memory_string (value_address (e_msg_val), e_msg, e_msg_len + 1); e_msg[e_msg_len] = '\0'; - discard_cleanups (cleanups); - return e_msg; + return result; } /* 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. */ - TRY { - e_msg = ada_exception_message_1 (); + return ada_exception_message_1 (); } CATCH (e, RETURN_MASK_ERROR) { - e_msg = NULL; } END_CATCH - return e_msg; + return nullptr; } /* Same as ada_exception_name_addr_1, except that it intercepts and contains @@ -12383,7 +12375,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); @@ -12450,16 +12441,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 ");