From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125439 invoked by alias); 19 Oct 2016 01:12:48 -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 125077 invoked by uid 89); 19 Oct 2016 01:12:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Oct 2016 01:12:43 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20680201FB for ; Wed, 19 Oct 2016 01:12:42 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9J1CJjt019701 for ; Tue, 18 Oct 2016 21:12:41 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 24/31] Use ui_file_as_string in gdb/ada-lang.c Date: Wed, 19 Oct 2016 01:12:00 -0000 Message-Id: <1476839539-8374-25-git-send-email-palves@redhat.com> In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com> References: <1476839539-8374-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-10/txt/msg00529.txt.bz2 gdb/ChangeLog: yyyy-mm-yy Pedro Alves * ada-lang.c (type_as_string): Use ui_file_as_string and return std::string. (type_as_string_and_cleanup): Delete. (ada_lookup_struct_elt_type): Use type_as_string. --- gdb/ada-lang.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d1a39bc..3c04554 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -7608,39 +7608,24 @@ ada_value_struct_elt (struct value *arg, char *name, int no_err) "a value that is not a record.")); } -/* Return a string representation of type TYPE. Caller must free - result. */ +/* Return a string representation of type TYPE. */ -static char * +static std::string type_as_string (struct type *type) { struct ui_file *tmp_stream = mem_fileopen (); struct cleanup *old_chain; - char *str; tmp_stream = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (tmp_stream); type_print (type, "", tmp_stream, -1); - str = ui_file_xstrdup (tmp_stream, NULL); + std::string str = ui_file_as_string (tmp_stream); do_cleanups (old_chain); return str; } -/* Return a string representation of type TYPE, and install a cleanup - that releases it. */ - -static char * -type_as_string_and_cleanup (struct type *type) -{ - char *str; - - str = type_as_string (type); - make_cleanup (xfree, str); - return str; -} - /* Given a type TYPE, look up the type of the component of type named NAME. If DISPP is non-null, add its byte displacement from the beginning of a structure (pointed to by a value) of type TYPE to *DISPP (does not @@ -7681,15 +7666,11 @@ ada_lookup_struct_elt_type (struct type *type, char *name, int refok, || (TYPE_CODE (type) != TYPE_CODE_STRUCT && TYPE_CODE (type) != TYPE_CODE_UNION)) { - const char *type_str; - if (noerr) return NULL; - type_str = (type != NULL - ? type_as_string_and_cleanup (type) - : _("(null)")); - error (_("Type %s is not a structure or union type"), type_str); + error (_("Type %s is not a structure or union type"), + type != NULL ? type_as_string (type).c_str () : _("(null)")); } type = to_static_fixed_type (type); @@ -7762,7 +7743,7 @@ BadName: const char *name_str = name != NULL ? name : _(""); error (_("Type %s has no component named %s"), - type_as_string_and_cleanup (type), name_str); + type_as_string (type).c_str (), name_str); } return NULL; -- 2.5.5