From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 49641 invoked by alias); 16 Jan 2017 17:58:01 -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 48971 invoked by uid 89); 16 Jan 2017 17:58:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ui_out, ui_file_delete, palves, scoped_restore 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; Mon, 16 Jan 2017 17:57:59 +0000 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEC7581222; Mon, 16 Jan 2017 17:57:59 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19A8E1BE86E; Mon, 16 Jan 2017 17:57:58 +0000 (UTC) Subject: Re: [RFA 2/5] Introduce ui_file_up and use it to remove cleanups To: Tom Tromey , gdb-patches@sourceware.org References: <20170115134253.24018-1-tom@tromey.com> <20170115134253.24018-3-tom@tromey.com> From: Pedro Alves Message-ID: <8396005b-762c-7fb6-5151-3d0b11a1f642@redhat.com> Date: Mon, 16 Jan 2017 17:58:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170115134253.24018-3-tom@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-01/txt/msg00303.txt.bz2 On 01/15/2017 01:42 PM, Tom Tromey wrote: > This introduces a new ui_file_up typedef, which is a specialization of > unique_ptr that calls ui_file_delete. This patch also changes > mem_fileopen to return a ui_file_up, and fixes the users. It also > updates a few other spots in the Python code to use this rather than > cleanups. > > If at some point ui_file_delete is removed in favor of a destructor, I > think the typedef could be changed and the default deletion policy > used instead. Urgh, guess you forgot/missed my palves/cxx-eliminate-cleanups branch ... :-( The top commit does: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Eliminate make_cleanup_ui_file_delete And now that ui_file_as_string is in, let's eliminate it. :-) Makes ui_file a real C++ hierarchy. mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows almost 1k loc dropped.) string_file has a string() method that gives you a direct reference to the internal std::string. This is what replaces old (well, new) ui_file_as_string, which used to alway return a new copy of the same data the stream had inside.. With direct access via a writable reference, we can instead move the string out of the string_stream. Note I needed a tweak on scoped_restore. That one should probably be split out to a separate patch. This exposed the need to make use of gnulib namespace support. Otherwise, making use of read/write/printf/puts/etc symbol names will clash on systems where gnulib replaces those functions, due to '#define foo rpl_foo'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I've been working on fixing that gnulib namespace issue since, thinking that I'd fix it before posting that patch, but looks like that was the wrong decision... :-/ Simon's ui_out series also had the same problem, but since common-defs.h includes the system headers that might cause the problem before any other header, it ends up not being such a bad problem in practice... Thanks, Pedro Alves