Re: [RFC v14-rc2][PATCH 24/29] c/r: Add CR_COPY() macro (v4)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> +
>> +/*
>> + * Copy @count items from @LIVE to @SAVE if op is CR_CPT (otherwise,
>> + * copy in the reverse direction)
>> + */
>> +#define CR_COPY_ARRAY(op, SAVE, LIVE, count)				\
>> +	do {								\
>> +		BUILD_BUG_ON(sizeof(*SAVE) != sizeof(*LIVE));		\
>> +		if (op == CR_CPT)					\
>> +			memcpy(SAVE, LIVE, count * sizeof(*SAVE));	\
>> +		else							\
>> +			memcpy(LIVE, SAVE, count * sizeof(*SAVE));	\
>> +	} while (__must_be_array(SAVE) && __must_be_array(LIVE) && 0)

SH> It doesn't really matter I guess, but I'd prefer to see:

SH> #define CR_COPY_ARRAY(op, SAVE, LIVE, count)				\
SH> 	do {								\
SH> 		__must_be_array(SAVE);					\
SH> 		__must_be_array(LIVE);					\
SH> 		BUILD_BUG_ON(sizeof(*SAVE) != sizeof(*LIVE));		\
SH> 		if (op == CR_CPT)					\
SH> 			memcpy(SAVE, LIVE, count * sizeof(*SAVE));	\
SH> 		else							\
SH> 			memcpy(LIVE, SAVE, count * sizeof(*SAVE));	\
SH> 	} while (0)

SH> Putting the __must_be_array()s inside the condition seems really weird.

I thought I explained this somewhere.  You'll get a compile warning if
you make __must_be_array() a statement without an lvalue.  If you try
to stuff the result into a variable that you don't use, you'll get a
warning about an unused variable.  I did what I did because it seemed
like a sane way to sidestep both of those issues.

Maybe a comment is warranted? :)

-- 
Dan Smith
IBM Linux Technology Center
email: danms@xxxxxxxxxx

_______________________________________________
Containers mailing list
Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linux-foundation.org/mailman/listinfo/containers

[Index of Archives]     [Cgroups]     [Netdev]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux