From d744f0f9652ee8de839c09e4517b18c9b88aecb7 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 8 Sep 2020 17:34:41 +0100 Subject: gdb::handle_eintr, remove need to specify return type This eliminates the need to specify the return type when using handle_eintr. We let the compiler deduce it for us. Also, use lowercase for function parameter names. Uppercase should only be used on template parameters. gdb/ChangeLog: * nat/linux-waitpid.c: Include "gdbsupport/eintr.h". (my_waitpid): Use gdb::handle_eintr. gdbserver/ChangeLog: * netbsd-low.cc (netbsd_waitpid, netbsd_process_target::kill) (netbsd_qxfer_libraries_svr4): Use gdb::handle_eintr without explicit type. gdbsupport/ChangeLog: * eintr.h (handle_eintr): Replace Ret template parameter with ErrorValType. Use it as type of the failure value. Deduce the function's return type using decltype. Use lowercase for function parameter names. --- gdbsupport/ChangeLog | 7 +++++++ gdbsupport/eintr.h | 26 +++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'gdbsupport') diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index 759eea1..2b01a0b 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,10 @@ +2020-10-26 Pedro Alves + + * eintr.h (handle_eintr): Replace Ret template parameter with + ErrorValType. Use it as type of the failure value. Deduce the + function's return type using decltype. Use lowercase for function + parameter names. + 2020-10-25 Simon Marchi * Makefile.in: Re-generate. diff --git a/gdbsupport/eintr.h b/gdbsupport/eintr.h index 64ff594..e097047 100644 --- a/gdbsupport/eintr.h +++ b/gdbsupport/eintr.h @@ -43,25 +43,29 @@ namespace gdb You could wrap it by writing the wrapped form: - ssize_t ret = gdb::handle_eintr (-1, ::write, pipe[1], "+", 1); + ssize_t ret = gdb::handle_eintr (-1, ::write, pipe[1], "+", 1); - The RET typename specifies the return type of the wrapped system call, which - is typically int or ssize_t. The R argument specifies the failure value - indicating the interrupted syscall when calling the F function with - the A... arguments. */ + ERRVAL specifies the failure value indicating that the call to the + F function with ARGS... arguments was possibly interrupted with a + signal. */ -template -inline Ret handle_eintr (const Ret &R, const Fun &F, const Args &... A) +template +inline auto +handle_eintr (ErrorValType errval, const Fun &f, const Args &... args) + -> decltype (f (args...)) { - Ret ret; + decltype (f (args...)) ret; + do { errno = 0; - ret = F (A...); + ret = f (args...); } - while (ret == R && errno == EINTR); + while (ret == errval && errno == EINTR); + return ret; } -} + +} /* namespace gdb */ #endif /* GDBSUPPORT_EINTR_H */ -- cgit v1.1