[libvirt] [dbus RFC 01/11] util: introduce VIRT_ARRAY_CARDINALITY macro

Pavel Hrdina posted 11 patches 7 years, 3 months ago
[libvirt] [dbus RFC 01/11] util: introduce VIRT_ARRAY_CARDINALITY macro
Posted by Pavel Hrdina 7 years, 3 months ago
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util.h b/src/util.h
index 0c9f3d7..6d99841 100644
--- a/src/util.h
+++ b/src/util.h
@@ -8,6 +8,8 @@
 #define _cleanup_(_x) __attribute__((__cleanup__(_x)))
 #define VIR_ATTR_UNUSED __attribute__((__unused__))
 
+#define VIRT_ARRAY_CARDINALITY(array) (sizeof(array) / sizeof(*(array)))
+
 
 int
 virtDBusUtilMessageAppendTypedParameters(sd_bus_message *message,
-- 
2.14.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus RFC 01/11] util: introduce VIRT_ARRAY_CARDINALITY macro
Posted by Daniel P. Berrange 7 years, 3 months ago
On Mon, Jan 22, 2018 at 06:15:59PM +0100, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/util.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/util.h b/src/util.h
> index 0c9f3d7..6d99841 100644
> --- a/src/util.h
> +++ b/src/util.h
> @@ -8,6 +8,8 @@
>  #define _cleanup_(_x) __attribute__((__cleanup__(_x)))
>  #define VIR_ATTR_UNUSED __attribute__((__unused__))
>  
> +#define VIRT_ARRAY_CARDINALITY(array) (sizeof(array) / sizeof(*(array)))
> +
>  
>  int
>  virtDBusUtilMessageAppendTypedParameters(sd_bus_message *message,

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>

Though if I was naming this again in libvirt I would follow glib and call
it VIR_N_ELEMENTS as it way shorter & easier to spell than the word
CARDINALITY :-)  Your call !

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus RFC 01/11] util: introduce VIRT_ARRAY_CARDINALITY macro
Posted by Pavel Hrdina 7 years, 3 months ago
On Tue, Jan 23, 2018 at 09:48:51AM +0000, Daniel P. Berrange wrote:
> On Mon, Jan 22, 2018 at 06:15:59PM +0100, Pavel Hrdina wrote:
> > Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> > ---
> >  src/util.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/src/util.h b/src/util.h
> > index 0c9f3d7..6d99841 100644
> > --- a/src/util.h
> > +++ b/src/util.h
> > @@ -8,6 +8,8 @@
> >  #define _cleanup_(_x) __attribute__((__cleanup__(_x)))
> >  #define VIR_ATTR_UNUSED __attribute__((__unused__))
> >  
> > +#define VIRT_ARRAY_CARDINALITY(array) (sizeof(array) / sizeof(*(array)))
> > +
> >  
> >  int
> >  virtDBusUtilMessageAppendTypedParameters(sd_bus_message *message,
> 
> Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
> 
> Though if I was naming this again in libvirt I would follow glib and call
> it VIR_N_ELEMENTS as it way shorter & easier to spell than the word
> CARDINALITY :-)  Your call !

That's definitely better name, I'll use that one, thanks.

Pavel
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list