Re: [PATCH RFC 4/5] Introduce scoped_mmapped_file

Tom Tromey
2018-05-10T20:59:11Z

>>>>> "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.

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.

Also I think that should be "open (filename, O_RDONLY)" -- no "0, ".

Tom