Debug a call to method ssa(sv)a(sa(sv)) from libdbus

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Fri Mar 11 00:01:04 UTC 2022


On Thu, 10 Mar 2022 19:50:10 +0100, Felip Moll wrote:

> For the real code please check https://pastebin.com/raw/Ev73xzMJ

Maybe not relevant to the actual problem, but I couldn’t help noticing
the endless repetition of abandon-container calls in
_dbus_asv_add_fixed_array. Here is what I think is a simpler way of
writing it (not tested):

static dbus_bool_t _dbus_asv_add_fixed_array
  (
    DBusMessageIter *arr_iter,
    const char *key,
    char element_type,
    const void *value,
    int n_elements
  )
  {
    bool success = false;
    const char type[] = { DBUS_TYPE_ARRAY, element_type, 0 };
    DBusMessageIter entry_iter = DBUS_MESSAGE_ITER_INIT_CLOSED;
    DBusMessageIter var_iter = DBUS_MESSAGE_ITER_INIT_CLOSED;
    DBusMessageIter array_iter = DBUS_MESSAGE_ITER_INIT_CLOSED;

    do /*once*/
      {
        if
          (
            not dbus_message_iter_open_container
              (
                /*iter =*/ arr_iter,
                /*type =*/ DBUS_TYPE_DICT_ENTRY,
                /*contained_signature =*/ NULL,
                /*sub =*/ &entry_iter
              )
          )
            break;
        if
          (
            not dbus_message_iter_append_basic
              (
                /*iter =*/ &entry_iter,
                /*type =*/ DBUS_TYPE_STRING,
                /*value =*/ &key
              )
          )
            break;
        if
          (
            not dbus_message_iter_open_container
              (
                /*iter =*/ &entry_iter,
                /*type =*/ DBUS_TYPE_VARIANT,
                /*contained_signature =*/ type,
                /*sub =*/ &var_iter
              )
          )
            break;
        if
          (
            not dbus_message_iter_open_container
              (
                /*iter =*/ &var_iter,
                /*type =*/ DBUS_TYPE_ARRAY,
                /*contained_signature =*/ type + 1,
                /*sub =*/ &array_iter
              )
          )
            break;
        if
          (
            not dbus_message_iter_append_fixed_array(&array_iter, element_type, &value, n_elements)
          )
            break;
        if (not dbus_message_iter_close_container(&var_iter, &array_iter))
            break;
        if (not dbus_message_iter_close_container(&entry_iter, &var_iter))
            break;
        if (not dbus_message_iter_close_container(arr_iter, &entry_iter))
            break;
      /* all done */
        success = true;
      }
    while (false);

    dbus_message_iter_abandon_container_if_open(var_iter, &array_iter);
    dbus_message_iter_abandon_container_if_open(entry_iter, &var_iter);
    dbus_message_iter_abandon_container_if_open(arr_iter, &entry_iter);

    return success;
  } /*_dbus_asv_add_fixed_array*/

I have an extended discussion of the general technique here
<https://github.com/ldo/a_structured_discipline_of_programming>.


More information about the dbus mailing list