From c809185307d06f33c17c2ca46024e226ba2ba444 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Wed, 5 May 2010 13:27:37 +0200 Subject: [PATCH 2/5] Implement DBUS_TYPE_MAYBE, 'm', "m" --- dbus/dbus-marshal-basic.c | 4 ++++ dbus/dbus-marshal-byteswap.c | 1 + dbus/dbus-marshal-recursive.c | 9 +++++++-- dbus/dbus-marshal-validate.c | 2 ++ dbus/dbus-message-factory.c | 1 + dbus/dbus-message.c | 6 ++++-- dbus/dbus-protocol.h | 4 ++++ 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c index ea18dbf..a37ff02 100644 --- a/dbus/dbus-marshal-basic.c +++ b/dbus/dbus-marshal-basic.c @@ -1213,6 +1213,7 @@ _dbus_type_get_alignment (int typecode) case DBUS_TYPE_STRING: case DBUS_TYPE_OBJECT_PATH: case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: return 4; case DBUS_TYPE_INT64: case DBUS_TYPE_UINT64: @@ -1260,6 +1261,7 @@ _dbus_type_is_valid (int typecode) case DBUS_TYPE_OBJECT_PATH: case DBUS_TYPE_SIGNATURE: case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: case DBUS_TYPE_STRUCT: case DBUS_TYPE_DICT_ENTRY: case DBUS_TYPE_VARIANT: @@ -1314,6 +1316,8 @@ _dbus_type_to_string (int typecode) return "dict_entry"; case DBUS_TYPE_ARRAY: return "array"; + case DBUS_TYPE_MAYBE: + return "maybe"; case DBUS_TYPE_VARIANT: return "variant"; case DBUS_STRUCT_BEGIN_CHAR: diff --git a/dbus/dbus-marshal-byteswap.c b/dbus/dbus-marshal-byteswap.c index 82758d0..2258e95 100644 --- a/dbus/dbus-marshal-byteswap.c +++ b/dbus/dbus-marshal-byteswap.c @@ -83,6 +83,7 @@ byteswap_body_helper (DBusTypeReader *reader, break; case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: case DBUS_TYPE_STRING: case DBUS_TYPE_OBJECT_PATH: { diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index 493864a..7b7b06a 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -463,6 +463,7 @@ base_reader_next (DBusTypeReader *reader, break; case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: { if (!reader->klass->types_only) _dbus_marshal_skip_array (reader->value_str, @@ -584,6 +585,7 @@ array_reader_next (DBusTypeReader *reader, break; case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: { _dbus_marshal_skip_array (reader->value_str, _dbus_first_type_in_signature (reader->type_str, @@ -995,6 +997,7 @@ _dbus_type_reader_recurse (DBusTypeReader *reader, sub->klass = &dict_entry_reader_class; break; case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: if (reader->klass->types_only) sub->klass = &array_types_only_reader_class; else @@ -1794,6 +1797,7 @@ writer_recurse_struct_or_dict_entry (DBusTypeWriter *writer, static dbus_bool_t writer_recurse_array (DBusTypeWriter *writer, + int array_type, const DBusString *contained_type, int contained_type_start, int contained_type_len, @@ -1850,7 +1854,7 @@ writer_recurse_array (DBusTypeWriter *writer, if (!_dbus_string_insert_byte (writer->type_str, writer->type_pos, - DBUS_TYPE_ARRAY)) + array_type)) _dbus_assert_not_reached ("failed to insert array typecode after prealloc"); if (!_dbus_string_copy_len (contained_type, @@ -2064,7 +2068,8 @@ _dbus_type_writer_recurse_contained_len (DBusTypeWriter *writer, sub); break; case DBUS_TYPE_ARRAY: - return writer_recurse_array (writer, + case DBUS_TYPE_MAYBE: + return writer_recurse_array (writer, container_type, contained_type, contained_type_start, contained_type_len, sub, is_array_append); break; diff --git a/dbus/dbus-marshal-validate.c b/dbus/dbus-marshal-validate.c index 36ba266..81a6112 100644 --- a/dbus/dbus-marshal-validate.c +++ b/dbus/dbus-marshal-validate.c @@ -112,6 +112,7 @@ _dbus_validate_signature_with_reason (const DBusString *type_str, break; case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: array_depth += 1; if (array_depth > DBUS_MAXIMUM_TYPE_RECURSION_DEPTH) { @@ -354,6 +355,7 @@ validate_body_helper (DBusTypeReader *reader, break; case DBUS_TYPE_ARRAY: + case DBUS_TYPE_MAYBE: case DBUS_TYPE_STRING: case DBUS_TYPE_OBJECT_PATH: { diff --git a/dbus/dbus-message-factory.c b/dbus/dbus-message-factory.c index 7432cf2..b414422 100644 --- a/dbus/dbus-message-factory.c +++ b/dbus/dbus-message-factory.c @@ -944,6 +944,7 @@ static const int typecodes[] = { DBUS_TYPE_OBJECT_PATH, DBUS_TYPE_SIGNATURE, DBUS_TYPE_ARRAY, + DBUS_TYPE_MAYBE, DBUS_TYPE_VARIANT, DBUS_STRUCT_BEGIN_CHAR, DBUS_STRUCT_END_CHAR, diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 540cf0f..7f671ce 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -1706,8 +1706,9 @@ dbus_message_append_args_valist (DBusMessage *message, buf[0] = element_type; buf[1] = '\0'; + if (!dbus_message_iter_open_container (&iter, - DBUS_TYPE_ARRAY, + type, buf, &array)) goto failed; @@ -2620,7 +2621,8 @@ dbus_message_iter_append_fixed_array (DBusMessageIter *iter, _dbus_return_val_if_fail (_dbus_message_iter_append_check (real), FALSE); _dbus_return_val_if_fail (real->iter_type == DBUS_MESSAGE_ITER_TYPE_WRITER, FALSE); _dbus_return_val_if_fail (dbus_type_is_fixed (element_type) && element_type != DBUS_TYPE_UNIX_FD, FALSE); - _dbus_return_val_if_fail (real->u.writer.container_type == DBUS_TYPE_ARRAY, FALSE); + _dbus_return_val_if_fail (_DBUS_TYPE_IS_ARRAYLIKE (real->u.writer.container_type), FALSE); + _dbus_return_val_if_fail (real->u.writer.container_type == DBUS_TYPE_MAYBE && n_elements < 2, FALSE); _dbus_return_val_if_fail (value != NULL, FALSE); _dbus_return_val_if_fail (n_elements >= 0, FALSE); _dbus_return_val_if_fail (n_elements <= diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h index 17798e9..ad27fd8 100644 --- a/dbus/dbus-protocol.h +++ b/dbus/dbus-protocol.h @@ -120,6 +120,10 @@ extern "C" { #define DBUS_TYPE_ARRAY ((int) 'a') /** #DBUS_TYPE_ARRAY as a string literal instead of a int literal */ #define DBUS_TYPE_ARRAY_AS_STRING "a" +/** Type code marking a D-Bus maybe type */ +#define DBUS_TYPE_MAYBE ((int) 'm') +/** #DBUS_TYPE_MAYBE as a string literal instead of an int literal */ +#define DBUS_TYPE_MAYBE_AS_STRING "m" /** Type code marking a D-Bus variant type */ #define DBUS_TYPE_VARIANT ((int) 'v') /** #DBUS_TYPE_VARIANT as a string literal instead of a int literal */ -- 1.7.3.2