[Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS

Marc-André Lureau posted 41 patches 6 years, 11 months ago
[Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
Posted by Marc-André Lureau 6 years, 11 months ago
Do not require QEMU macro.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 slirp/ncsi.c | 2 +-
 slirp/tftp.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/slirp/ncsi.c b/slirp/ncsi.c
index 10decfb5ef..8594382270 100644
--- a/slirp/ncsi.c
+++ b/slirp/ncsi.c
@@ -128,7 +128,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
     memset(reh->h_source, 0xff, ETH_ALEN);
     reh->h_proto = htons(ETH_P_NCSI);
 
-    for (i = 0; i < ARRAY_SIZE(ncsi_rsp_handlers); i++) {
+    for (i = 0; i < G_N_ELEMENTS(ncsi_rsp_handlers); i++) {
         if (ncsi_rsp_handlers[i].type == nh->type + 0x80) {
             handler = &ncsi_rsp_handlers[i];
             break;
diff --git a/slirp/tftp.c b/slirp/tftp.c
index dddb614b8a..ef8d0352b4 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -360,7 +360,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
       return;
   }
 
-  while (k < pktlen && nb_options < ARRAY_SIZE(option_name)) {
+  while (k < pktlen && nb_options < G_N_ELEMENTS(option_name)) {
       const char *key, *value;
 
       key = &tp->x.tp_buf[k];
@@ -404,7 +404,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
   }
 
   if (nb_options > 0) {
-      assert(nb_options <= ARRAY_SIZE(option_name));
+      assert(nb_options <= G_N_ELEMENTS(option_name));
       tftp_send_oack(spt, option_name, option_value, nb_options, tp);
       return;
   }
-- 
2.19.1.708.g4ede3d42df


Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
Posted by Philippe Mathieu-Daudé 6 years, 11 months ago
On 14/11/18 13:36, Marc-André Lureau wrote:
> Do not require QEMU macro.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   slirp/ncsi.c | 2 +-
>   slirp/tftp.c | 4 ++--
>   2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/slirp/ncsi.c b/slirp/ncsi.c
> index 10decfb5ef..8594382270 100644
> --- a/slirp/ncsi.c
> +++ b/slirp/ncsi.c
> @@ -128,7 +128,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
>       memset(reh->h_source, 0xff, ETH_ALEN);
>       reh->h_proto = htons(ETH_P_NCSI);
>   
> -    for (i = 0; i < ARRAY_SIZE(ncsi_rsp_handlers); i++) {
> +    for (i = 0; i < G_N_ELEMENTS(ncsi_rsp_handlers); i++) {
>           if (ncsi_rsp_handlers[i].type == nh->type + 0x80) {
>               handler = &ncsi_rsp_handlers[i];
>               break;
> diff --git a/slirp/tftp.c b/slirp/tftp.c
> index dddb614b8a..ef8d0352b4 100644
> --- a/slirp/tftp.c
> +++ b/slirp/tftp.c
> @@ -360,7 +360,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
>         return;
>     }
>   
> -  while (k < pktlen && nb_options < ARRAY_SIZE(option_name)) {
> +  while (k < pktlen && nb_options < G_N_ELEMENTS(option_name)) {
>         const char *key, *value;
>   
>         key = &tp->x.tp_buf[k];
> @@ -404,7 +404,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas,
>     }
>   
>     if (nb_options > 0) {
> -      assert(nb_options <= ARRAY_SIZE(option_name));
> +      assert(nb_options <= G_N_ELEMENTS(option_name));
>         tftp_send_oack(spt, option_name, option_value, nb_options, tp);
>         return;
>     }
> 

Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
Posted by Daniel P. Berrangé 6 years, 11 months ago
On Wed, Nov 14, 2018 at 04:36:39PM +0400, Marc-André Lureau wrote:
> Do not require QEMU macro.

As with the endian thing, we should really purge ARRAY_SIZE from
the entire QEMU codebase and just defer to glib. ARRAY_SIZE made
sense before glib was a hard dep in QEMU, but there's no reason
beyond bike shed colour choice to preserve it now.

I'm fine with this patch being targetted to slirp to avoid getting
dragged into a broader discussion, but I'd encourage the global
cleanup. I've personally used G_N_ELEMENTS in all QEMU code I've
been writing since its more familiar from glib than a QEMU
specific macro name.

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



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 :|

Re: [Qemu-devel] [PATCH for-3.2 37/41] slirp: replace ARRAY_SIZE with G_N_ELEMENTS
Posted by Samuel Thibault 6 years, 11 months ago
Philippe Mathieu-Daudé, le mer. 14 nov. 2018 14:17:56 +0100, a ecrit:
> On 14/11/18 13:36, Marc-André Lureau wrote:
> > Do not require QEMU macro.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Daniel P. Berrangé, le mer. 14 nov. 2018 14:15:15 +0000, a ecrit:
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Applied to my tree, thanks!