svn commit: r257298 - head/lib/libproc

Mark Johnston markj at freebsd.org
Tue Oct 29 15:29:22 UTC 2013


On Wed, Oct 30, 2013 at 12:21:28AM +1100, Bruce Evans wrote:
> On Tue, 29 Oct 2013, Mark Johnston wrote:
> 
> > Log:
> >  Revert r257248 and fix the problem in a way that doesn't violate style(9).
> 
> Why did gcc complain about the original version?

It looks like this is because of the use of -W, which is apparently an
alias for -Wextra; according to the gcc man page, this will trigger a
warning when "an empty body occurs in an if or else statement."

> 
> > Modified: head/lib/libproc/_libproc.h
> > ==============================================================================
> > --- head/lib/libproc/_libproc.h	Tue Oct 29 02:25:18 2013	(r257297)
> > +++ head/lib/libproc/_libproc.h	Tue Oct 29 03:12:31 2013	(r257298)
> > @@ -52,6 +52,6 @@ struct proc_handle {
> > #define	DPRINTF(...) 	warn(__VA_ARGS__)
> > #define	DPRINTFX(...)	warnx(__VA_ARGS__)
> > #else
> > -#define	DPRINTF(...)
> > -#define	DPRINTFX(...)
> > +#define	DPRINTF(...)    do { } while (0)
> > +#define	DPRINTFX(...)   do { } while (0)
> > #endif
> >
> > Modified: head/lib/libproc/proc_util.c
> > ==============================================================================
> > --- head/lib/libproc/proc_util.c	Tue Oct 29 02:25:18 2013	(r257297)
> > +++ head/lib/libproc/proc_util.c	Tue Oct 29 03:12:31 2013	(r257298)
> > @@ -145,9 +145,8 @@ proc_wstatus(struct proc_handle *phdl)
> > 	if (phdl == NULL)
> > 		return (-1);
> > 	if (waitpid(phdl->pid, &status, WUNTRACED) < 0) {
> > -		if (errno != EINTR) {
> > +		if (errno != EINTR)
> > 			DPRINTF("waitpid");
> > -		}
> > 		return (-1);
> > 	}
> > 	if (WIFSTOPPED(status))
> 
> Unlike some buggy macros, the null macro expanded to syntactically correct
> code:
> 
>  		if (errno != EINTR)
>  			;
> 
> so it doesn't need the do-while hack.  Empty statements are common in some
> contexts, so compilers shouldn't warn about them.  In all versions, the
> macro isn't completely function-like and the if statement is dead code,
> so if compilers warn about too many things then the do-while hack wouldn't
> work here or in most places that it is used.
> 
> Nearby style bugs:
> - the error check is for "< 0" instead of for "== -1"
> - the error message is not as loud as old ones.  All old ones begin with
>    "ERROR: ".  The new style is better.  "ERROR" is not even redundant.
>    It is wrong, since the errors are just warnings.
> 
> Bruce


More information about the svn-src-all mailing list