Re: [RFC 1/2] Unified UUID/GUID definition
From: Huang Ying
Date: Fri Oct 16 2009 - 05:20:46 EST
On Fri, 2009-10-16 at 17:03 +0800, Laurent Pinchart wrote:
[...]
> > +#define UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
> > +((uuid_le) \
> > +{{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff,
> > \ + (b) & 0xff, ((b) >> 8) & 0xff, \
> > + (c) & 0xff, ((c) >> 8) & 0xff, \
> > + (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
> > +
> > +#define UUID_BE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
> > +((uuid_be) \
> > +{{ ((a) >> 24) & 0xff, ((a) >> 16) & 0xff, ((a) >> 8) & 0xff, (a) & 0xff,
> > \ + ((b) >> 8) & 0xff, (b) & 0xff, \
> > + ((c) >> 8) & 0xff, (c) & 0xff, \
> > + (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }})
> > +
> > +#define NULL_UUID_LE \
> > + UUID_LE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00)
> > +
> > +#define NULL_UUID_BE \
> > + UUID_BE(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
> > + 0x00, 0x00, 0x00, 0x00)
> > +
> > +static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2)
> > +{
> > + return memcmp(&u1, &u2, sizeof(uuid_le));
> > +}
> > +
> > +static inline int uuid_be_cmp(const uuid_be u1, const uuid_be u2)
> > +{
> > + return memcmp(&u1, &u2, sizeof(uuid_be));
> > +}
>
> Shouldn't you pass pointers to those functions instead ?
This is intended for a typical usage model (in fact copied from efi.h).
#define MY_UUID_LE UUID_LE(...)
if (uuid_le_cmp(uuid, MY_UUID_LE)) {
...
}
You need not define another variable for comparing with a UUID constant.
> It would also be nice to have a single uuid_cmp function. Would it be possible
> to use typeof(), __builtin_types_compatible_p() and BUILD_BUG_ON_ZERO magic to
> make sure both arguments are of the same type and one of uuid_be and uuid_le ?
> It might no work with the Intel compiler though.
It seems a little tricky and complex. This is just a very simple
function.
Best Regards,
Huang Ying
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/