public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: wangshuo_1994@foxmail.com
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] hurd fcntl: remove duplicate do...while in LOCKED macro
Date: Wed, 4 Jan 2023 12:56:50 +0100	[thread overview]
Message-ID: <20230104115650.7rqlrdmxb25jpik2@begin> (raw)
In-Reply-To: <tencent_6AE67FD99D9CE0D5E6F93FFF6CE49CED1E09@qq.com>

wangshuo_1994@foxmail.com, le mer. 04 janv. 2023 18:30:57 +0800, a ecrit:
> From: abushwang <wangshuo_1994@foxmail.com>
> 
> commit e1a467d introduces do...while for LOCKED macro. However, there is
> already while(0) in LOCKED macro according to HURD_CRITICAL_END in hurd/hurd/signal.h:
> 
>     #define HURD_CRITICAL_BEGIN \
>       { void *__hurd_critical__ = _hurd_critical_section_lock ()
>     #define HURD_CRITICAL_END \
>           _hurd_critical_section_unlock (__hurd_critical__); } while (0)
> 
> It is robust enough.

That's true, but that's a bit hidden, and might someday go away.

The original purpose of my change was to avoid exposing a double ';' to
static analyzers who then frown upon it.

The do { } while(0) shouldn't be harmful anyway, so I prefer to keep it.

Samuel

> Signed-off-by: abushwang <wangshuo_1994@foxmail.com>
> ---
>  sysdeps/mach/hurd/fcntl.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c
> index 48608493a1..ea35e9b977 100644
> --- a/sysdeps/mach/hurd/fcntl.c
> +++ b/sysdeps/mach/hurd/fcntl.c
> @@ -109,7 +109,7 @@ __libc_fcntl (int fd, int cmd, ...)
>  
>        /* Set RESULT by evaluating EXPR with the descriptor locked.
>  	 Check for an empty descriptor and return EBADF.  */
> -#define LOCKED(expr) do {						      \
> +#define LOCKED(expr)							      \
>        HURD_CRITICAL_BEGIN;						      \
>        __spin_lock (&d->port.lock);					      \
>        if (d->port.port == MACH_PORT_NULL)				      \
> @@ -117,8 +117,7 @@ __libc_fcntl (int fd, int cmd, ...)
>        else								      \
>  	result = (expr);						      \
>        __spin_unlock (&d->port.lock);					      \
> -      HURD_CRITICAL_END;						      \
> -} while(0)
> +      HURD_CRITICAL_END;
>  
>      case F_GETFD:		/* Get descriptor flags.  */
>        LOCKED (d->flags);
> -- 
> 2.37.3

      reply	other threads:[~2023-01-04 11:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04 10:30 wangshuo_1994
2023-01-04 11:56 ` Samuel Thibault [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230104115650.7rqlrdmxb25jpik2@begin \
    --to=samuel.thibault@ens-lyon.org \
    --cc=libc-alpha@sourceware.org \
    --cc=wangshuo_1994@foxmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).