From 607f87994e6653fd926aec43189a6bfb3591c378 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 5 May 2010 13:00:47 +0200 Subject: [PATCH 1/7] Use generic DBUS_TYPE_IS_ARRAY for array checks --- dbus/dbus-marshal-byteswap.c | 2 +- dbus/dbus-marshal-header.c | 2 +- dbus/dbus-marshal-recursive.c | 22 +++++++++++----------- dbus/dbus-marshal-validate.c | 14 +++++++------- dbus/dbus-message.c | 8 ++++---- dbus/dbus-protocol.h | 4 ++++ dbus/dbus-signature.c | 6 +++--- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/dbus/dbus-marshal-byteswap.c b/dbus/dbus-marshal-byteswap.c index 22d7e22..7c32a32 100644 --- a/dbus/dbus-marshal-byteswap.c +++ b/dbus/dbus-marshal-byteswap.c @@ -95,7 +95,7 @@ byteswap_body_helper (DBusTypeReader *reader, *((dbus_uint32_t*)p) = DBUS_UINT32_SWAP_LE_BE (*((dbus_uint32_t*)p)); p += 4; - if (current_type == DBUS_TYPE_ARRAY) + if (DBUS_TYPE_IS_ARRAY (current_type)) { int elem_type; int alignment; diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c index 3f31d7a..c2b10e6 100644 --- a/dbus/dbus-marshal-header.c +++ b/dbus/dbus-marshal-header.c @@ -1099,7 +1099,7 @@ _dbus_header_load (DBusHeader *header, goto invalid; } - _dbus_assert (_dbus_type_reader_get_current_type (&reader) == DBUS_TYPE_ARRAY); + _dbus_assert (DBUS_TYPE_IS_ARRAY (_dbus_type_reader_get_current_type (&reader))); _dbus_assert (_dbus_type_reader_get_value_pos (&reader) == FIELDS_ARRAY_LENGTH_OFFSET); _dbus_type_reader_recurse (&reader, &array_reader); diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index cb10854..e9c7abb 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -340,7 +340,7 @@ _dbus_type_signature_next (const char *type_str, _dbus_assert (*p != DBUS_STRUCT_END_CHAR); _dbus_assert (*p != DBUS_DICT_ENTRY_END_CHAR); - while (*p == DBUS_TYPE_ARRAY) + while (DBUS_TYPE_IS_ARRAY (*p)) ++p; _dbus_assert (*p != DBUS_STRUCT_END_CHAR); @@ -809,7 +809,7 @@ _dbus_type_reader_get_element_type (const DBusTypeReader *reader) { int element_type; - _dbus_assert (_dbus_type_reader_get_current_type (reader) == DBUS_TYPE_ARRAY); + _dbus_assert (DBUS_TYPE_IS_ARRAY (_dbus_type_reader_get_current_type (reader))); element_type = _dbus_first_type_in_signature (reader->type_str, reader->type_pos + 1); @@ -1632,7 +1632,7 @@ writer_recurse_init_and_check (DBusTypeWriter *writer, sub->container_type = container_type; if (writer->type_pos_is_expectation || - (sub->container_type == DBUS_TYPE_ARRAY || sub->container_type == DBUS_TYPE_VARIANT)) + (DBUS_TYPE_IS_ARRAY (sub->container_type) || sub->container_type == DBUS_TYPE_VARIANT)) sub->type_pos_is_expectation = TRUE; else sub->type_pos_is_expectation = FALSE; @@ -1733,7 +1733,7 @@ write_or_verify_typecode (DBusTypeWriter *writer, * so the expected type doesn't change; if inside a struct or something * below an array, we need to move through said struct or something. */ - if (writer->container_type != DBUS_TYPE_ARRAY) + if (!DBUS_TYPE_IS_ARRAY (writer->container_type)) writer->type_pos += 1; } else @@ -1805,7 +1805,7 @@ writer_recurse_array (DBusTypeWriter *writer, int aligned; #ifndef DBUS_DISABLE_CHECKS - if (writer->container_type == DBUS_TYPE_ARRAY && + if (DBUS_TYPE_IS_ARRAY (writer->container_type) && writer->type_str) { if (!_dbus_string_equal_substring (contained_type, @@ -1865,7 +1865,7 @@ writer_recurse_array (DBusTypeWriter *writer, /* If the parent is an array, we hold type_pos pointing at the array element type; * otherwise advance it to reflect the array value we just recursed into */ - if (writer->container_type != DBUS_TYPE_ARRAY) + if (!DBUS_TYPE_IS_ARRAY (writer->container_type)) writer->type_pos += 1 + contained_type_len; else _dbus_assert (writer->type_pos_is_expectation); /* because it's an array */ @@ -2148,7 +2148,7 @@ _dbus_type_writer_append_array (DBusTypeWriter *writer, static int writer_get_array_len (DBusTypeWriter *writer) { - _dbus_assert (writer->container_type == DBUS_TYPE_ARRAY); + _dbus_assert (DBUS_TYPE_IS_ARRAY (writer->container_type)); return writer->value_pos - writer->u.array.start_pos; } @@ -2188,7 +2188,7 @@ _dbus_type_writer_unrecurse (DBusTypeWriter *writer, if (!write_or_verify_typecode (sub, DBUS_DICT_ENTRY_END_CHAR)) return FALSE; } - else if (sub->container_type == DBUS_TYPE_ARRAY) + else if (DBUS_TYPE_IS_ARRAY (sub->container_type)) { if (sub->u.array.len_pos >= 0) /* len_pos == -1 if we weren't enabled when we passed it */ { @@ -2346,7 +2346,7 @@ _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer, const void *value, int n_elements) { - _dbus_assert (writer->container_type == DBUS_TYPE_ARRAY); + _dbus_assert (DBUS_TYPE_IS_ARRAY (writer->container_type)); _dbus_assert (dbus_type_is_fixed (element_type)); _dbus_assert (writer->type_pos_is_expectation); _dbus_assert (n_elements >= 0); @@ -2468,7 +2468,7 @@ writer_write_reader_helper (DBusTypeWriter *writer, _dbus_type_reader_recurse (reader, &subreader); - if (current_type == DBUS_TYPE_ARRAY) + if (DBUS_TYPE_IS_ARRAY (current_type)) { reader_array_len_pos = ARRAY_READER_LEN_POS (&subreader); reader_array_start_pos = subreader.u.array.start_pos; @@ -2537,7 +2537,7 @@ writer_write_reader_helper (DBusTypeWriter *writer, */ if (start_after != NULL && !enabled_at_recurse && past_start_after && - current_type == DBUS_TYPE_ARRAY && + DBUS_TYPE_IS_ARRAY (current_type) && fixups != NULL) { DBusArrayLenFixup fixup; diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c index aa470fc..38a535c 100644 --- a/dbus/dbus-marshal-validate.c +++ b/dbus/dbus-marshal-validate.c @@ -212,8 +212,8 @@ _dbus_validate_signature_with_reason (const DBusString *type_str, goto out; } - if (*p != DBUS_TYPE_ARRAY && - *p != DBUS_DICT_ENTRY_BEGIN_CHAR && + if (!DBUS_TYPE_IS_ARRAY (*p) && + *p != DBUS_DICT_ENTRY_BEGIN_CHAR && *p != DBUS_STRUCT_BEGIN_CHAR) { element_count = @@ -231,7 +231,7 @@ _dbus_validate_signature_with_reason (const DBusString *type_str, if (array_depth > 0) { - if (*p == DBUS_TYPE_ARRAY && p != end) + if (DBUS_TYPE_IS_ARRAY (*p) && p != end) { const char *p1; p1 = p + 1; @@ -280,7 +280,7 @@ _dbus_validate_signature_with_reason (const DBusString *type_str, goto out; } - _dbus_assert (last != DBUS_TYPE_ARRAY); + _dbus_assert (!DBUS_TYPE_IS_ARRAY (last)); _dbus_assert (last != DBUS_STRUCT_BEGIN_CHAR); _dbus_assert (last != DBUS_DICT_ENTRY_BEGIN_CHAR); @@ -375,7 +375,7 @@ validate_body_helper (DBusTypeReader *reader, /* p may now be == end */ _dbus_assert (p <= end); - if (current_type == DBUS_TYPE_ARRAY) + if (DBUS_TYPE_IS_ARRAY (current_type)) { int array_elem_type = _dbus_type_reader_get_element_type (reader); @@ -423,7 +423,7 @@ validate_body_helper (DBusTypeReader *reader, p += claimed_len; } - else if (current_type == DBUS_TYPE_ARRAY && claimed_len > 0) + else if (DBUS_TYPE_IS_ARRAY (current_type) && claimed_len > 0) { DBusTypeReader sub; DBusValidity validity; @@ -488,7 +488,7 @@ validate_body_helper (DBusTypeReader *reader, } /* check nul termination */ - if (current_type != DBUS_TYPE_ARRAY) + if (!DBUS_TYPE_IS_ARRAY (current_type)) { if (p == end) return DBUS_INVALID_NOT_ENOUGH_DATA; diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 3b5941b..0bab8ef 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -791,7 +791,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter, _dbus_type_reader_read_basic (&real->u.reader, ptr); } - else if (spec_type == DBUS_TYPE_ARRAY) + else if (DBUS_TYPE_IS_ARRAY (spec_type)) { int element_type; int spec_element_type; @@ -1695,7 +1695,7 @@ dbus_message_append_args_valist (DBusMessage *message, value)) goto failed; } - else if (type == DBUS_TYPE_ARRAY) + else if (DBUS_TYPE_IS_ARRAY (type)) { int element_type; DBusMessageIter array; @@ -2012,7 +2012,7 @@ dbus_message_iter_get_element_type (DBusMessageIter *iter) _dbus_return_val_if_fail (_dbus_message_iter_check (real), DBUS_TYPE_INVALID); _dbus_return_val_if_fail (real->iter_type == DBUS_MESSAGE_ITER_TYPE_READER, DBUS_TYPE_INVALID); - _dbus_return_val_if_fail (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_ARRAY, DBUS_TYPE_INVALID); + _dbus_return_val_if_fail (DBUS_TYPE_IS_ARRAY (dbus_message_iter_get_arg_type (iter)), DBUS_TYPE_INVALID); return _dbus_type_reader_get_element_type (&real->u.reader); } @@ -2672,7 +2672,7 @@ dbus_message_iter_open_container (DBusMessageIter *iter, contained_signature == NULL) || (type == DBUS_TYPE_VARIANT && contained_signature != NULL) || - (type == DBUS_TYPE_ARRAY && + (DBUS_TYPE_IS_ARRAY (type) && contained_signature != NULL), FALSE); /* this would fail if the contained_signature is a dict entry, since diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h index 17798e9..734cdb4 100644 --- a/dbus/dbus-protocol.h +++ b/dbus/dbus-protocol.h @@ -125,6 +125,10 @@ extern "C" { /** #DBUS_TYPE_VARIANT as a string literal instead of a int literal */ #define DBUS_TYPE_VARIANT_AS_STRING "v" +#define DBUS_TYPE_IS_ARRAY(typeliteral) \ + (typeliteral == DBUS_TYPE_ARRAY \ + || typeliteral == DBUS_TYPE_MAYBE) + /** STRUCT and DICT_ENTRY are sort of special since their codes can't * appear in a type string, instead * DBUS_STRUCT_BEGIN_CHAR/DBUS_DICT_ENTRY_BEGIN_CHAR have to appear diff --git a/dbus/dbus-signature.c b/dbus/dbus-signature.c index ddc0bcc..3c763cb 100644 --- a/dbus/dbus-signature.c +++ b/dbus/dbus-signature.c @@ -44,7 +44,7 @@ typedef struct ((typecode) == DBUS_TYPE_STRUCT || \ (typecode) == DBUS_TYPE_DICT_ENTRY || \ (typecode) == DBUS_TYPE_VARIANT || \ - (typecode) == DBUS_TYPE_ARRAY) + DBUS_TYPE_IS_ARRAY (typecode)) /** @@ -147,7 +147,7 @@ dbus_signature_iter_get_element_type (const DBusSignatureIter *iter) { DBusSignatureRealIter *real_iter = (DBusSignatureRealIter *) iter; - _dbus_return_val_if_fail (dbus_signature_iter_get_current_type (iter) == DBUS_TYPE_ARRAY, DBUS_TYPE_INVALID); + _dbus_return_val_if_fail (DBUS_TYPE_IS_ARRAY (dbus_signature_iter_get_current_type (iter)), DBUS_TYPE_INVALID); return _dbus_first_type_in_signature_c_str (real_iter->pos, 1); } @@ -216,7 +216,7 @@ dbus_signature_iter_recurse (const DBusSignatureIter *iter, real_sub_iter->in_array = FALSE; real_sub_iter->pos++; - if (dbus_signature_iter_get_current_type (iter) == DBUS_TYPE_ARRAY) + if (DBUS_TYPE_IS_ARRAY (dbus_signature_iter_get_current_type (iter))) real_sub_iter->in_array = TRUE; } -- 1.7.1