Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Mar 2014 13:58:57 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        John-Mark Gurney <jmg@funkthat.com>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Edward Tomasz Napierala <trasz@freebsd.org>
Subject:   Re: svn commit: r263740 - in head/sys: cam/ctl dev/iscsi
Message-ID:  <20140326134456.V1525@besplex.bde.org>
In-Reply-To: <20140325205523.GA60889@funkthat.com>
References:  <201403251830.s2PIUvIu029793@svn.freebsd.org> <20140325205523.GA60889@funkthat.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 25 Mar 2014, John-Mark Gurney wrote:

> Edward Tomasz Napierala wrote this message on Tue, Mar 25, 2014 at 18:30 +0000:
>> Author: trasz
>> Date: Tue Mar 25 18:30:57 2014
>> New Revision: 263740
>> URL: http://svnweb.freebsd.org/changeset/base/263740
>>
>> Log:
>>   Use a less unusual syntax in debug printfs.
>
> Just for reference, this is partly a bug fix...
>
> if { xxx } while (0)
>
> is two statements, and if you tried to use the macros as such:
> if (something)
> 	MACRO(param)
> else
> 	somethingelse;

It seems to be entirely this bug fix, except for massive churning of the
indentation.

>> @@ -98,29 +98,38 @@ SYSCTL_INT(_kern_cam_ctl_iscsi, OID_AUTO
>>      &maxcmdsn_delta, 256, "Number of commands the initiator can send "
>>      "without confirmation");
>>
>> -#define	CFISCSI_DEBUG(X, ...)					\
>> -	if (debug > 1) {					\
>> -		printf("%s: " X "\n", __func__, ## __VA_ARGS__);\
>> +#define	CFISCSI_DEBUG(X, ...)						\
>> +	do {								\
>> +		if (debug > 1) {					\
>> +			printf("%s: " X "\n",				\
>> +			    __func__, ## __VA_ARGS__);			\
>> +		}							\
>>  	} while (0)
>>

Normal style is as in sys/queue.h.  It doesn't make the code less
readable by pushing the non-do-while parts of it to the right, and
didn't churn the indentation when adding do-while.

Normal style is also used for the more directly related KASSERT()...

BTW, KASSERT() is still dumbed down to work K&R compilers that don't
support __VA_ARGS__.  This is hard to fix since its collateral bad
syntax is used in thousands of callers.  Automatic printing of the
function names was intentionally left out of KASSERT(), so that
callers could omit it if they wanted, but this has resulted in lots
of ugly syntax and source code bloat in callers.  Here the ugly
syntax is hidden in the macro, and the bloat is mostly at runtime.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140326134456.V1525>