[systemd-devel] [PATCH] Big endian and the size of the gcc builtin type bool from stdbool.h

David Herrmann dh.herrmann at gmail.com
Thu Sep 18 03:43:00 PDT 2014


Hi

On Thu, Sep 18, 2014 at 11:16 AM, Werner Fink <werner at suse.de> wrote:
> On s390 the big endianness and cast from pointers of integers to
> the type of bool leads to the funny status messages that e.g.
> all targets are set to AllowIsolate=no even for multi-user.target.
>
> The gcc builtin type bool or _Bool has the size of one byte which
> should be taken into account in sd_bus_message_read_basic() as well
> as in bus_message_append_ap()

We don't support "bool" in public APIs. sd-bus requires you to use
"int" for boolean types. If a caller uses "bool", they must be fixed.

Thanks
David

> ---
>  src/libsystemd/sd-bus/bus-message.c |   19 +++++++++++++++----
>  1 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git src/libsystemd/sd-bus/bus-message.c src/libsystemd/sd-bus/bus-message.c
> index bfb14fc..b70d814 100644
> --- src/libsystemd/sd-bus/bus-message.c
> +++ src/libsystemd/sd-bus/bus-message.c
> @@ -2263,14 +2263,25 @@ int bus_message_append_ap(
>                          r = sd_bus_message_append_basic(m, *t, &x);
>                          break;
>                  }
> +                case SD_BUS_TYPE_BOOLEAN: {
> +                        if (sizeof(bool) == sizeof(uint32_t)) {
> +                                uint32_t x;
>
> -                case SD_BUS_TYPE_BOOLEAN:
> +                                x = va_arg(ap, uint32_t);
> +                                r = sd_bus_message_append_basic(m, *t, &x);
> +                        } else {
> +                                uint8_t x;
> +
> +                                x = (uint8_t) va_arg(ap, int);
> +                                r = sd_bus_message_append_basic(m, *t, &x);
> +                        }
> +                        break;
> +                }
>                  case SD_BUS_TYPE_INT32:
>                  case SD_BUS_TYPE_UINT32:
>                  case SD_BUS_TYPE_UNIX_FD: {
>                          uint32_t x;
>
> -                        /* We assume a boolean is the same as int32_t */
>                          assert_cc(sizeof(int32_t) == sizeof(int));
>
>                          x = va_arg(ap, uint32_t);
> @@ -3233,7 +3244,7 @@ _public_ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) {
>
>                          case SD_BUS_TYPE_BOOLEAN:
>                                  if (p)
> -                                        *(int*) p = !!*(uint8_t*) q;
> +                                        *(bool*) p = !!*(uint8_t*) q;
>                                  break;
>
>                          case SD_BUS_TYPE_INT16:
> @@ -3343,7 +3354,7 @@ _public_ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) {
>
>                          case SD_BUS_TYPE_BOOLEAN:
>                                  if (p)
> -                                        *(int*) p = !!*(uint32_t*) q;
> +                                        *(bool*) p = !!*(uint32_t*) q;
>                                  break;
>
>                          case SD_BUS_TYPE_INT16:
> --
> 1.7.7
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list