On 03/22/2010 01:05 PM, Daniel P. Berrange wrote: > Use the new virDomainUpdateDeviceFlags API to allow the VNC password > to be changed on the fly > > * src/internal.h: Define STREQ_NULLABLE() which is like STREQ() > but does not crash if either argument is NULL, and treats two > NULLs as equal. ... > +++ b/src/internal.h > @@ -58,6 +58,12 @@ > # define STRCASENEQLEN(a,b,n) (strncasecmp(a,b,n) != 0) > # define STRPREFIX(a,b) (strncmp(a,b,strlen(b)) == 0) > > +# define STREQ_NULLABLE(a, b) \ > + ((!a && !b) || (a && b && STREQ(a, b))) > +# define STRNEQ_NULLABLE(a, b) \ > + ((!a && b) || (a && !b) || (a && b && STRNEQ(a, b))) This seems like an independently useful change, and one worth documenting in docs/hacking.html.in next to the existing documentation on STREQ. It also has a bug - it is under-parenthesized. And you can use ^ for compactness: # define STREQ_NULLABLE(a, b) \ ((!(a) && !(b)) || ((a) && (b) && STREQ(a, b))) # define STRNEQ_NULLABLE(a, b) \ ((!(a) ^ !(b)) || ((a) && (b) && STRNEQ(a, b))) Hmmm. The existing STREQ and STRNEQ only evaluate arguments once, but this evaluates arguments multiple times. Then again, so does the existing STRPREFIX. Are any of these three worth making static inline functions, rather than macros, to avoid side-effects of multiple evaluation? I did not closely review the rest of the patch. -- Eric Blake eblake@xxxxxxxxxx +1-801-349-2682 Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list