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

Re: [libvirt] [PATCH 6/6] Implement VNC password change in QEMU



On Mon, Mar 22, 2010 at 03:21:06PM -0600, Eric Blake wrote:
> 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 don't think the multiple evaluation matters - none of the uses of
these macros pass in complex expressions where multiple evaluation
would cause problems. THe args are always just constant strings, or
char * pointers.

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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