Re: [PATCH RFC 4/5] Introduce scoped_mmapped_file

Simon Marchi
2018-05-10T21:10:54Z

On 2018-05-10 16:59, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> 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