[PATCH 03/16] ui: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check

Philippe Mathieu-Daudé posted 16 patches 1 month ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, Stefano Garzarella <sgarzare@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Jason Wang <jasowang@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Paolo Bonzini <pbonzini@redhat.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
[PATCH 03/16] ui: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check
Posted by Philippe Mathieu-Daudé 1 month ago
Replace compile-time #ifdef with a runtime check to ensure all code
paths are built and tested. This reduces build-time configuration
complexity and improves maintainability.

No functional change intended.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 ui/vdagent.c | 16 ++++++++--------
 ui/vnc.c     |  6 +-----
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/ui/vdagent.c b/ui/vdagent.c
index ddb91e75c64..66dc33567df 100644
--- a/ui/vdagent.c
+++ b/ui/vdagent.c
@@ -660,14 +660,14 @@ static void vdagent_chr_open(Chardev *chr,
     VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr);
     ChardevQemuVDAgent *cfg = backend->u.qemu_vdagent.data;
 
-#if HOST_BIG_ENDIAN
-    /*
-     * TODO: vdagent protocol is defined to be LE,
-     * so we have to byteswap everything on BE hosts.
-     */
-    error_setg(errp, "vdagent is not supported on bigendian hosts");
-    return;
-#endif
+    if (HOST_BIG_ENDIAN) {
+        /*
+         * TODO: vdagent protocol is defined to be LE,
+         * so we have to byteswap everything on BE hosts.
+         */
+        error_setg(errp, "vdagent is not supported on bigendian hosts");
+        return;
+    }
 
     vd->mouse = VDAGENT_MOUSE_DEFAULT;
     if (cfg->has_mouse) {
diff --git a/ui/vnc.c b/ui/vnc.c
index 77c823bf2e8..e93b5335690 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2348,11 +2348,7 @@ static void pixel_format_message (VncState *vs) {
     vnc_write_u8(vs, vs->client_pf.bits_per_pixel); /* bits-per-pixel */
     vnc_write_u8(vs, vs->client_pf.depth); /* depth */
 
-#if HOST_BIG_ENDIAN
-    vnc_write_u8(vs, 1);             /* big-endian-flag */
-#else
-    vnc_write_u8(vs, 0);             /* big-endian-flag */
-#endif
+    vnc_write_u8(vs, HOST_BIG_ENDIAN);         /* big-endian-flag */
     vnc_write_u8(vs, 1);             /* true-color-flag */
     vnc_write_u16(vs, vs->client_pf.rmax);     /* red-max */
     vnc_write_u16(vs, vs->client_pf.gmax);     /* green-max */
-- 
2.51.0


Re: [PATCH 03/16] ui: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check
Posted by Marc-André Lureau 1 month ago
On Fri, Oct 10, 2025 at 5:42 PM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:

> Replace compile-time #ifdef with a runtime check to ensure all code
> paths are built and tested. This reduces build-time configuration
> complexity and improves maintainability.
>
> No functional change intended.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  ui/vdagent.c | 16 ++++++++--------
>  ui/vnc.c     |  6 +-----
>  2 files changed, 9 insertions(+), 13 deletions(-)
>
> diff --git a/ui/vdagent.c b/ui/vdagent.c
> index ddb91e75c64..66dc33567df 100644
> --- a/ui/vdagent.c
> +++ b/ui/vdagent.c
> @@ -660,14 +660,14 @@ static void vdagent_chr_open(Chardev *chr,
>      VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr);
>      ChardevQemuVDAgent *cfg = backend->u.qemu_vdagent.data;
>
> -#if HOST_BIG_ENDIAN
> -    /*
> -     * TODO: vdagent protocol is defined to be LE,
> -     * so we have to byteswap everything on BE hosts.
> -     */
> -    error_setg(errp, "vdagent is not supported on bigendian hosts");
> -    return;
> -#endif
> +    if (HOST_BIG_ENDIAN) {
> +        /*
> +         * TODO: vdagent protocol is defined to be LE,
> +         * so we have to byteswap everything on BE hosts.
> +         */
> +        error_setg(errp, "vdagent is not supported on bigendian hosts");
> +        return;
> +    }
>
>      vd->mouse = VDAGENT_MOUSE_DEFAULT;
>      if (cfg->has_mouse) {
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 77c823bf2e8..e93b5335690 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -2348,11 +2348,7 @@ static void pixel_format_message (VncState *vs) {
>      vnc_write_u8(vs, vs->client_pf.bits_per_pixel); /* bits-per-pixel */
>      vnc_write_u8(vs, vs->client_pf.depth); /* depth */
>
> -#if HOST_BIG_ENDIAN
> -    vnc_write_u8(vs, 1);             /* big-endian-flag */
> -#else
> -    vnc_write_u8(vs, 0);             /* big-endian-flag */
> -#endif
> +    vnc_write_u8(vs, HOST_BIG_ENDIAN);         /* big-endian-flag */
>      vnc_write_u8(vs, 1);             /* true-color-flag */
>      vnc_write_u16(vs, vs->client_pf.rmax);     /* red-max */
>      vnc_write_u16(vs, vs->client_pf.gmax);     /* green-max */
> --
> 2.51.0
>
>