From patchwork Wed Oct 19 01:11:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 16633 Received: (qmail 123399 invoked by alias); 19 Oct 2016 01:12:30 -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 123239 invoked by uid 89); 19 Oct 2016 01:12:29 -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=22, 8, *length, 1176 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:27 +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 5CFC485540 for ; Wed, 19 Oct 2016 01:12:26 +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 u9J1CJjb019701 for ; Tue, 18 Oct 2016 21:12:25 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 06/31] Introduce ui_file_as_string Date: Wed, 19 Oct 2016 02:11:54 +0100 Message-Id: <1476839539-8374-7-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> ui_file_as_string is a variant of ui_file_xstrdup that returns a std::string instead of a xmalloc'ed char *. The idea is using the new function to eliminate "make_cleanup (xfree, ...)" cleanups throughout. Following patches will make use of this. gdb/ChangeLog: yyyy-mm-yy Pedro Alves * ui-file.c (do_ui_file_as_string, ui_file_as_string): New functions. * ui-file.h: Include . (ui_file_as_string): New declaration. --- gdb/ui-file.c | 22 ++++++++++++++++++++++ gdb/ui-file.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/gdb/ui-file.c b/gdb/ui-file.c index a977f89..31228a3 100644 --- a/gdb/ui-file.c +++ b/gdb/ui-file.c @@ -356,6 +356,28 @@ ui_file_xstrdup (struct ui_file *file, long *length) return acc.buffer; } +/* ui_file utility function for converting a ``struct ui_file'' into a + std:string. */ + +static void +do_ui_file_as_string (void *context, const char *buffer, long length) +{ + std::string *str = (std::string *) context; + + *str = std::string (buffer, length); +} + +/* See ui-file.h. */ + +std::string +ui_file_as_string (struct ui_file *file) +{ + std::string str; + + ui_file_put (file, do_ui_file_as_string, &str); + return str; +} + static void do_ui_file_obsavestring (void *context, const char *buffer, long length) { diff --git a/gdb/ui-file.h b/gdb/ui-file.h index f6df572..2ed11de 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -22,6 +22,8 @@ struct obstack; struct ui_file; +#include + /* Create a generic ui_file object with null methods. */ extern struct ui_file *ui_file_new (void); @@ -117,6 +119,10 @@ extern void ui_file_put (struct ui_file *src, minus that appended NUL. */ extern char *ui_file_xstrdup (struct ui_file *file, long *length); +/* Returns a std::string containing the entire contents of FILE (as + determined by ui_file_put()). */ +extern std::string ui_file_as_string (struct ui_file *file); + /* Similar to ui_file_xstrdup, but return a new string allocated on OBSTACK. */ extern char *ui_file_obsavestring (struct ui_file *file,