From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130231 invoked by alias); 19 Jul 2017 22:52:24 -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 130221 invoked by uid 89); 19 Jul 2017 22:52:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS autolearn=ham version=3.3.2 spammy=hoc X-HELO: gproxy8.mail.unifiedlayer.com Received: from gproxy8-pub.mail.unifiedlayer.com (HELO gproxy8.mail.unifiedlayer.com) (67.222.33.93) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Jul 2017 22:52:23 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy8.mail.unifiedlayer.com (Postfix) with ESMTP id 466BF1ABE94 for ; Wed, 19 Jul 2017 16:27:29 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id mmTS1v0012f2jeq01mTVbw; Wed, 19 Jul 2017 16:27:29 -0600 X-Authority-Analysis: v=2.2 cv=UM2tJGXy c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=G3gG6ho9WtcA:10 a=20KFwNOVAAAA:8 a=0RPAVo9aO0dl-Rd5okIA:9 Received: from 174-16-124-214.hlrn.qwest.net ([174.16.124.214]:42558 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dXxRF-0018C2-Qo; Wed, 19 Jul 2017 16:27:25 -0600 From: Tom Tromey To: Pedro Alves Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFA 09/23] Remove close cleanup References: <20170503224626.2818-1-tom@tromey.com> <20170503224626.2818-10-tom@tromey.com> Date: Wed, 19 Jul 2017 22:52:00 -0000 In-Reply-To: (Pedro Alves's message of "Fri, 2 Jun 2017 19:08:55 +0100") Message-ID: <87iniom59v.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BWhitelist: no X-Exim-ID: 1dXxRF-0018C2-Qo X-Source-Sender: 174-16-124-214.hlrn.qwest.net (bapiya) [174.16.124.214]:42558 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2017-07/txt/msg00296.txt.bz2 >>>>> "Pedro" == Pedro Alves writes: Pedro> Patch looks good. Pedro> The bit below made me stop for a second: [...] Pedro> Would the following be too clever? Pedro> /* Restore errno on exit to the value saved by the Pedro> last save() call. Ctor saves. */ Pedro> struct scoped_errno_restore [...] Pedro> /* Save errno and return MNSH_FS_ERROR. */ Pedro> auto fs_err = [&] () Pedro> { Pedro> restore_errno.save (); Pedro> return MNSH_FS_ERROR; Pedro> }; [...] Pedro> [It gets rid of both the scope, and the gotos.] How about making fd_closer a template, like: template class fd_closer ... ~fd_closer () { if (m_fd != -1) CLOSER (m_fd); } Then in linux-namespaces.c: /* A function like "close" that saves and restores errno. */ static int close_saving_fd (int fd) { scoped_restore save_errno = make_scoped_restore (&errno); return close (fd); } ... gdb::fd_closer close_fd (fd); This also removes the scope and the gotos. The main plus is that it's simpler. The main minus is that it's ad hoc. Tom