From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90910 invoked by alias); 1 Oct 2016 05:22:25 -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 90897 invoked by uid 89); 1 Oct 2016 05:22:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL,BAYES_40,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=cleanups, U*simon.marchi, simonmarchipolymtlca, Marchi X-HELO: gproxy6-pub.mail.unifiedlayer.com Received: from gproxy6-pub.mail.unifiedlayer.com (HELO gproxy6-pub.mail.unifiedlayer.com) (67.222.39.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Sat, 01 Oct 2016 05:22:15 +0000 Received: (qmail 15552 invoked by uid 0); 1 Oct 2016 05:22:13 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy6.mail.unifiedlayer.com with SMTP; 1 Oct 2016 05:22:13 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id q5NA1t00M2f2jeq015NDQ6; Fri, 30 Sep 2016 23:22:13 -0600 X-Authority-Analysis: v=2.1 cv=X7zBdgje c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=GW1xBdLrtEIA:10 a=vDFG-EyRSTMJ-6-N3DwA:9 Received: from 71-218-192-86.hlrn.qwest.net ([71.218.192.86]:39844 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1bqCkU-0005kA-Ax; Fri, 30 Sep 2016 23:22:10 -0600 From: Tom Tromey To: Simon Marchi Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA 03/22] Use scoped_restore for ui_file References: <1474949330-4307-1-git-send-email-tom@tromey.com> <1474949330-4307-4-git-send-email-tom@tromey.com> <7417a71f254c7f42026408c5e143b374@simark.ca> Date: Sat, 01 Oct 2016 05:22:00 -0000 In-Reply-To: <7417a71f254c7f42026408c5e143b374@simark.ca> (Simon Marchi's message of "Sat, 01 Oct 2016 00:28:10 -0400") Message-ID: <87bmz4fxtt.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BWhitelist: no X-Exim-ID: 1bqCkU-0005kA-Ax X-Source-Sender: 71-218-192-86.hlrn.qwest.net (bapiya) [71.218.192.86]:39844 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2016-10/txt/msg00006.txt.bz2 >>>>> "Simon" == Simon Marchi writes: Simon> shared_ptr< scoped_restore > save_file; Why shared_ptr and not unique_ptr? Simon> We can't use std::shared_ptr, since it's only in c++11, but I think Simon> it's just a matter of time before we define our own version of it. ... Pedro's branch has unique_ptr :) Simon> An alternative would be to have a default constructor for Simon> scoped_restore, that creates an inactive scoped_restore, and then Simon> assign it a variable to restore later with acquire(T* var)/acquire(T* Simon> var, T value) methods or something. I am not sure which one is Simon> better. FWIW Mozilla uses an Option class for this kind of thing. It works like: Option< scoped_restore > save_file; if (mumble) { save_file.emplace (make_scoped_restore (&var)); } The main advantage of this over *_ptr is that Option contains the object, so no heap allocations are required. Simon> To support some use cases where discard_cleanups is used, we might Simon> need a way to "release" the scoped_restore, which would essentially Simon> cancel it. So if we have a "release" method, maybe having the Simon> symmetrical "acquire" would make sense. Simon> What do you think? It seems sensible to me. One idea to consider is whether it's better to have a separate "discardable" variant of scoped_restore (or whatever else); the idea being that then the type name serves as a signal to look more closely at the logic. I think most spots don't need discardable cleanups. Tom