[libvirt] [PATCH 7/8] examples: Use G_N_ELEMENTS instead of ARRAY_CARDINALITY

Ján Tomko jtomko at redhat.com
Tue Oct 15 14:44:10 UTC 2019


On Tue, Oct 15, 2019 at 04:10:55PM +0200, Andrea Bolognani wrote:
>On Tue, 2019-10-15 at 14:21 +0200, Ján Tomko wrote:
>> We try to keep the example programs independent of libraries
>> other than libvirt.
>>
>> Rename the locally defined ARRAY_CARDINALITY macro to G_N_ELEMENTS
>> which GLib provides, even though we don't actually include GLib.
>
>[...]
>
>> -#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
>> +#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))
>
>In this case, and in this case only, I think we should leave the name
>alone.

This case being "the isolated event-test.c example" or "the
ARRAY_CARDINALITY macro in event-test.c"?

If it's the latter, I can add an exception to syntax-check instead.

Note that I also added a G_GNUC_UNUSED macro earlier, if the G_ prefix
is the issue. (The ATTRIBUTE_UNUSED spelling is used by multiple libs,
including libxml2)

Also, we open-code the 'verify' macro from gnulib.

>
>When we use GLib and simply provide our own implementation when using
>a version that's too old, the GLib name is obviously accurate, but in
>this specific case I think it's misleading and we should stick with
>the current one.


Alternatively, would a comment along the lines of:
/* define these macros to avoid pulling in glib */
make it less misleading?

The reason we included these macros here in the first place is that
we wanted to keep the code in sync with the rest of libvirt.

Jano

>
>-- 
>Andrea Bolognani / Red Hat / Virtualization
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20191015/763169c1/attachment-0001.sig>


More information about the libvir-list mailing list