diff options
| author | Havoc Pennington <hp@redhat.com> | 2005-01-17 19:49:52 +0000 | 
|---|---|---|
| committer | Havoc Pennington <hp@redhat.com> | 2005-01-17 19:49:52 +0000 | 
| commit | 62e465339a306fa564b69935da494dad6e1b474a (patch) | |
| tree | 0c75e656937e148983dbf3ea313b0bb9efb9f6c6 | |
| parent | 7bf62e31a3c820852271768fafc04ba95c31a19f (diff) | |
2005-01-17  Havoc Pennington  <hp@redhat.com>
	* dbus/dbus-types.h: hardcode dbus_bool_t to 32 bits
	* Throughout: modify DBUS_TYPE_BOOLEAN to be a 32-bit type instead
	of an 8-bit type. Now dbus_bool_t is the type to use whenever you
	are marshaling/unmarshaling a boolean.
| -rw-r--r-- | ChangeLog | 8 | ||||
| -rw-r--r-- | bus/driver.c | 2 | ||||
| -rw-r--r-- | dbus/dbus-marshal-basic.c | 21 | ||||
| -rw-r--r-- | dbus/dbus-marshal-basic.h | 1 | ||||
| -rw-r--r-- | dbus/dbus-marshal-recursive-util.c | 8 | ||||
| -rw-r--r-- | dbus/dbus-marshal-validate.c | 14 | ||||
| -rw-r--r-- | dbus/dbus-message-builder.c | 4 | ||||
| -rw-r--r-- | dbus/dbus-message-util.c | 12 | ||||
| -rw-r--r-- | dbus/dbus-types.h | 3 | ||||
| -rw-r--r-- | glib/dbus-gvalue.c | 4 | ||||
| -rw-r--r-- | qt/message.cpp | 4 | ||||
| -rw-r--r-- | tools/dbus-send.c | 9 | 
12 files changed, 54 insertions, 36 deletions
| @@ -1,3 +1,11 @@ +2005-01-17  Havoc Pennington  <hp@redhat.com> + +	* dbus/dbus-types.h: hardcode dbus_bool_t to 32 bits + +	* Throughout: modify DBUS_TYPE_BOOLEAN to be a 32-bit type instead +	of an 8-bit type. Now dbus_bool_t is the type to use whenever you  +	are marshaling/unmarshaling a boolean. +  2005-01-16  Havoc Pennington  <hp@redhat.com>          This is about it on what can be disabled/deleted from libdbus diff --git a/bus/driver.c b/bus/driver.c index cb641031..0eef59e1 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -519,7 +519,7 @@ bus_driver_handle_service_exists (DBusConnection *connection,    DBusMessage *reply;    DBusString service_name;    BusService *service; -  unsigned char service_exists; +  dbus_bool_t service_exists;    const char *name;    dbus_bool_t retval;    BusRegistry *registry; diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c index 94161af0..fce935fa 100644 --- a/dbus/dbus-marshal-basic.c +++ b/dbus/dbus-marshal-basic.c @@ -343,7 +343,6 @@ _dbus_marshal_set_basic (DBusString       *str,    switch (type)      {      case DBUS_TYPE_BYTE: -    case DBUS_TYPE_BOOLEAN:        _dbus_string_set_byte (str, pos, vp->byt);        if (old_end_pos)          *old_end_pos = pos + 1; @@ -351,6 +350,7 @@ _dbus_marshal_set_basic (DBusString       *str,          *new_end_pos = pos + 1;        return TRUE;        break; +    case DBUS_TYPE_BOOLEAN:      case DBUS_TYPE_INT32:      case DBUS_TYPE_UINT32:        pos = _DBUS_ALIGN_VALUE (pos, 4); @@ -457,12 +457,12 @@ _dbus_marshal_read_basic (const DBusString      *str,    switch (type)      {      case DBUS_TYPE_BYTE: -    case DBUS_TYPE_BOOLEAN:        vp->byt = _dbus_string_get_byte (str, pos);        (pos)++;        break;      case DBUS_TYPE_INT32:      case DBUS_TYPE_UINT32: +    case DBUS_TYPE_BOOLEAN:        pos = _DBUS_ALIGN_VALUE (pos, 4);        vp->u32 = *(dbus_uint32_t *)(str_data + pos);        if (byte_order != DBUS_COMPILER_BYTE_ORDER) @@ -756,13 +756,16 @@ _dbus_marshal_write_basic (DBusString *str,    switch (type)      {      case DBUS_TYPE_BYTE: -    case DBUS_TYPE_BOOLEAN:        if (!_dbus_string_insert_byte (str, insert_at, vp->byt))          return FALSE;        if (pos_after)          *pos_after = insert_at + 1;        return TRUE;        break; +    case DBUS_TYPE_BOOLEAN: +      return marshal_4_octets (str, insert_at, vp->u32 != FALSE, +                               byte_order, pos_after); +      break;      case DBUS_TYPE_INT32:      case DBUS_TYPE_UINT32:        return marshal_4_octets (str, insert_at, vp->u32, @@ -952,12 +955,12 @@ _dbus_marshal_write_fixed_multi (DBusString *str,    switch (element_type)      { -    case DBUS_TYPE_BOOLEAN: -      /* FIXME: we canonicalize to 0 or 1 for the single boolean case -       * should we here too ? */      case DBUS_TYPE_BYTE:        return marshal_1_octets_array (str, insert_at, vp, n_elements, byte_order, pos_after);        break; +      /* FIXME: we canonicalize to 0 or 1 for the single boolean case +       * should we here too ? */ +    case DBUS_TYPE_BOOLEAN:      case DBUS_TYPE_INT32:      case DBUS_TYPE_UINT32:        return marshal_fixed_multi (str, insert_at, vp, n_elements, byte_order, 4, pos_after); @@ -998,9 +1001,9 @@ _dbus_marshal_skip_basic (const DBusString      *str,    switch (type)      {      case DBUS_TYPE_BYTE: -    case DBUS_TYPE_BOOLEAN:        (*pos)++;        break; +    case DBUS_TYPE_BOOLEAN:      case DBUS_TYPE_INT32:      case DBUS_TYPE_UINT32:        *pos = _DBUS_ALIGN_VALUE (*pos, 4); @@ -1082,10 +1085,10 @@ _dbus_type_get_alignment (int typecode)    switch (typecode)      {      case DBUS_TYPE_BYTE: -    case DBUS_TYPE_BOOLEAN:      case DBUS_TYPE_VARIANT:      case DBUS_TYPE_SIGNATURE:        return 1; +    case DBUS_TYPE_BOOLEAN:      case DBUS_TYPE_INT32:      case DBUS_TYPE_UINT32:        /* this stuff is 4 since it starts with a length */ @@ -1528,7 +1531,7 @@ _dbus_marshal_test (void)    dbus_int64_t v_INT64;    dbus_uint64_t v_UINT64;    unsigned char v_BYTE; -  unsigned char v_BOOLEAN; +  dbus_bool_t v_BOOLEAN;    const char *v_STRING;    const char *v_SIGNATURE;    const char *v_OBJECT_PATH; diff --git a/dbus/dbus-marshal-basic.h b/dbus/dbus-marshal-basic.h index f416689c..f4a8c2fa 100644 --- a/dbus/dbus-marshal-basic.h +++ b/dbus/dbus-marshal-basic.h @@ -141,7 +141,6 @@ typedef union  #endif    double dbl;          /**< as double */    unsigned char byt;   /**< as byte */ -  unsigned char boo;   /**< as boolean */    char *str;           /**< as char* */  } DBusBasicValue; diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c index cd80ea07..28797099 100644 --- a/dbus/dbus-marshal-recursive-util.c +++ b/dbus/dbus-marshal-recursive-util.c @@ -2141,7 +2141,7 @@ string_set_value (TestTypeNode   *node,                                        realign_root);  } -#define BOOL_FROM_SEED(seed) (seed % 2) +#define BOOL_FROM_SEED(seed) ((dbus_bool_t)((seed) % 2))  static dbus_bool_t  bool_write_value (TestTypeNode   *node, @@ -2149,7 +2149,7 @@ bool_write_value (TestTypeNode   *node,                    DBusTypeWriter *writer,                    int             seed)  { -  unsigned char v; +  dbus_bool_t v;    v = BOOL_FROM_SEED (seed); @@ -2163,7 +2163,7 @@ bool_read_value (TestTypeNode   *node,                   DBusTypeReader *reader,                   int             seed)  { -  unsigned char v; +  dbus_bool_t v;    check_expected_type (reader, node->klass->typecode); @@ -2181,7 +2181,7 @@ bool_set_value (TestTypeNode   *node,                  DBusTypeReader *realign_root,                  int             seed)  { -  unsigned char v; +  dbus_bool_t v;    v = BOOL_FROM_SEED (seed); diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c index d3507739..05148604 100644 --- a/dbus/dbus-marshal-validate.c +++ b/dbus/dbus-marshal-validate.c @@ -159,11 +159,6 @@ validate_body_helper (DBusTypeReader       *reader,            break;          case DBUS_TYPE_BOOLEAN: -          if (!(*p == 0 || *p == 1)) -            return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE; -          ++p; -          break; -          case DBUS_TYPE_INT32:          case DBUS_TYPE_UINT32:          case DBUS_TYPE_INT64: @@ -179,6 +174,15 @@ validate_body_helper (DBusTypeReader       *reader,                  return DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL;                ++p;              } +           +          if (current_type == DBUS_TYPE_BOOLEAN) +            { +              dbus_uint32_t v = _dbus_unpack_uint32 (byte_order, +                                                     p); +              if (!(v == 0 || v == 1)) +                return DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE; +            } +                      p += alignment;            break; diff --git a/dbus/dbus-message-builder.c b/dbus/dbus-message-builder.c index 58718f6d..83b37aff 100644 --- a/dbus/dbus-message-builder.c +++ b/dbus/dbus-message-builder.c @@ -456,9 +456,9 @@ parse_basic_type (DBusString *src, char type,    switch (type)      {      case DBUS_TYPE_BYTE: -    case DBUS_TYPE_BOOLEAN:        align = 1;        break; +    case DBUS_TYPE_BOOLEAN:      case DBUS_TYPE_UINT32:      case DBUS_TYPE_INT32:        align = 4; @@ -514,9 +514,9 @@ parse_basic_array (DBusString *src, char type,    switch (type)      {      case DBUS_TYPE_BYTE: -    case DBUS_TYPE_BOOLEAN:        elem_size = 1;        break; +    case DBUS_TYPE_BOOLEAN:      case DBUS_TYPE_UINT32:      case DBUS_TYPE_INT32:        elem_size = 4; diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c index 47370702..a64c3e5b 100644 --- a/dbus/dbus-message-util.c +++ b/dbus/dbus-message-util.c @@ -599,7 +599,7 @@ message_iter_test (DBusMessage *message)    dbus_uint64_t v_UINT64;  #endif    unsigned char v_BYTE; -  unsigned char v_BOOLEAN; +  dbus_bool_t v_BOOLEAN;    const dbus_int32_t *our_int_array;    int len; @@ -659,7 +659,7 @@ verify_test_message (DBusMessage *message)    dbus_int32_t our_int;    const char *our_str;    double our_double; -  unsigned char our_bool; +  dbus_bool_t our_bool;    unsigned char our_byte_1, our_byte_2;    dbus_uint32_t our_uint32;    const dbus_int32_t *our_uint32_array = (void*)0xdeadbeef; @@ -678,7 +678,7 @@ verify_test_message (DBusMessage *message)    int our_double_array_len;    const unsigned char *our_byte_array = (void*)0xdeadbeef;    int our_byte_array_len; -  const unsigned char *our_boolean_array = (void*)0xdeadbeef; +  const dbus_bool_t *our_boolean_array = (void*)0xdeadbeef;    int our_boolean_array_len;    dbus_message_iter_init (message, &iter); @@ -844,8 +844,8 @@ _dbus_message_test (const char *test_data_dir)    const double *v_ARRAY_DOUBLE = our_double_array;    const unsigned char our_byte_array[] = { 'a', 'b', 'c', 234 };    const unsigned char *v_ARRAY_BYTE = our_byte_array; -  const unsigned char our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE }; -  const unsigned char *v_ARRAY_BOOLEAN = our_boolean_array; +  const dbus_bool_t our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE }; +  const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;    char sig[64];    const char *s;    char *t; @@ -860,7 +860,7 @@ _dbus_message_test (const char *test_data_dir)  #endif    unsigned char v_BYTE;    unsigned char v2_BYTE; -  unsigned char v_BOOLEAN; +  dbus_bool_t v_BOOLEAN;    message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",                                            "/org/freedesktop/TestPath", diff --git a/dbus/dbus-types.h b/dbus/dbus-types.h index 9f41c3c3..0bbc9295 100644 --- a/dbus/dbus-types.h +++ b/dbus/dbus-types.h @@ -29,12 +29,13 @@  #include <stddef.h> -typedef unsigned int   dbus_bool_t;  typedef unsigned short dbus_uint16_t;  typedef short          dbus_int16_t;  typedef unsigned int   dbus_uint32_t;  typedef int            dbus_int32_t;  typedef dbus_uint32_t  dbus_unichar_t; +/* boolean size must be fixed at 4 bytes due to wire protocol! */ +typedef dbus_uint32_t  dbus_bool_t;  /* Normally docs are in .c files, but there isn't a .c file for this. */  /** diff --git a/glib/dbus-gvalue.c b/glib/dbus-gvalue.c index b44640ce..1fed0cf7 100644 --- a/glib/dbus-gvalue.c +++ b/glib/dbus-gvalue.c @@ -34,6 +34,8 @@ dbus_gvalue_demarshal (DBusMessageIter *iter, GValue *value)        g_value_init (value, G_TYPE_##g_t);                       \        dbus_message_iter_get_basic (iter, &value->data[0]);      \        break + +  g_assert (sizeof (dbus_bool_t) == sizeof (value->data[0].v_int));    switch (dbus_message_iter_get_arg_type (iter))      { @@ -98,7 +100,7 @@ dbus_gvalue_marshal (DBusMessageIter *iter, GValue *value)        break;      case G_TYPE_BOOLEAN:        { -        unsigned char b = g_value_get_boolean (value); +        dbus_bool_t b = g_value_get_boolean (value);          if (!dbus_message_iter_append_basic (iter,                                               DBUS_TYPE_BOOLEAN,                                               &b)) diff --git a/qt/message.cpp b/qt/message.cpp index 8064ed7a..256c2b23 100644 --- a/qt/message.cpp +++ b/qt/message.cpp @@ -505,8 +505,8 @@ Message::message() const  Message& Message::operator<<( bool b )  { -  const unsigned char byte = b; -  dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, &byte, +  const dbus_bool_t right_size_bool = b; +  dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, &right_size_bool,                              DBUS_TYPE_INVALID );  } diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 87352eb9..412f5fdc 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -179,6 +179,7 @@ main (int argc, char *argv[])        dbus_int32_t int32;        double d;        unsigned char byte; +      dbus_bool_t v_BOOLEAN;        type = DBUS_TYPE_INVALID;        arg = argv[i++]; @@ -240,13 +241,13 @@ main (int argc, char *argv[])  	case DBUS_TYPE_BOOLEAN:            if (strcmp(c, "true") == 0)              { -              byte = TRUE; -              dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &c); +              v_BOOLEAN = TRUE; +              dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);              }  	  else if (strcmp(c, "false") == 0)              { -              byte = FALSE; -              dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &c); +              v_BOOLEAN = FALSE; +              dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);              }  	  else  	    { | 
