This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA 09/23] Remove close cleanup
- From: Tom Tromey <tom at tromey dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: Tom Tromey <tom at tromey dot com>, gdb-patches at sourceware dot org
- Date: Wed, 19 Jul 2017 16:27:24 -0600
- Subject: Re: [RFA 09/23] Remove close cleanup
- Authentication-results: sourceware.org; auth=none
- References: <20170503224626.2818-1-tom@tromey.com> <20170503224626.2818-10-tom@tromey.com> <ca2efb7d-21f7-f935-fbe3-86d09916d0f0@redhat.com>
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> 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<int (*CLOSER) (int) = close>
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_saving_errno> 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