svn commit: r263740 - in head/sys: cam/ctl dev/iscsi

Bruce Evans brde at optusnet.com.au
Wed Mar 26 03:20:35 UTC 2014


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


More information about the svn-src-head mailing list