From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70554 invoked by alias); 10 May 2018 21:10:54 -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 70537 invoked by uid 89); 10 May 2018 21:10:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 10 May 2018 21:10:51 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w4ALAjrO019385 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 10 May 2018 17:10:50 -0400 Received: by simark.ca (Postfix, from userid 112) id 610881F214; Thu, 10 May 2018 17:10:45 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 933061E56F; Thu, 10 May 2018 17:10:44 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 10 May 2018 21:27:00 -0000 From: Simon Marchi To: Tom Tromey Cc: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH RFC 4/5] Introduce scoped_mmapped_file In-Reply-To: <87y3grz0px.fsf@tromey.com> References: <1525901216-15031-1-git-send-email-simon.marchi@ericsson.com> <1525901216-15031-5-git-send-email-simon.marchi@ericsson.com> <87y3grz0px.fsf@tromey.com> Message-ID: <1601635db4edc8926dfcf2a82db65c3e@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 10 May 2018 21:10:45 +0000 X-IsSubscribed: yes X-SW-Source: 2018-05/txt/msg00270.txt.bz2 On 2018-05-10 16:59, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi writes: > > Simon> + void reset (int new_fd) > Simon> + { > Simon> + destroy (); > Simon> + > Simon> + m_fd = new_fd; > Simon> + } > > I was wondering if this should only destroy() when new_fd!=m_fd. > That way self-resetting would not cause a bug. It probably should, indeed. > Simon> + /* Map FILENAME in memory. Throw an error if anything goes > wrong. */ > Simon> + scoped_mmapped_file (const char *filename) > Simon> + { > Simon> + m_fd.reset (open (filename, 0, O_RDONLY)); > > ... however, then I thought perhaps this question could be avoided by > just initializing m_fd directly, like: > > scoped_mmapped_file (const char *filename) > : m_fd (open (filename, 0, O_RDONLY)) > > Then "reset" wouldn't be needed at all. I can do that, but I am using reset() in the following patch anyway. Though if you find a way of avoiding that usage, then we can remove the method. > Also I think that should be "open (filename, O_RDONLY)" -- no "0, ". Right, thanks. Simon