From 62e465339a306fa564b69935da494dad6e1b474a Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 17 Jan 2005 19:49:52 +0000 Subject: 2005-01-17 Havoc Pennington * 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. --- dbus/dbus-marshal-basic.c | 21 ++++++++++++--------- dbus/dbus-marshal-basic.h | 1 - dbus/dbus-marshal-recursive-util.c | 8 ++++---- dbus/dbus-marshal-validate.c | 14 +++++++++----- dbus/dbus-message-builder.c | 4 ++-- dbus/dbus-message-util.c | 12 ++++++------ dbus/dbus-types.h | 3 ++- 7 files changed, 35 insertions(+), 28 deletions(-) (limited to 'dbus') 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 -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. */ /** -- cgit