From: Mathieu Desnoyers Date: Thu, 5 May 2011 04:41:15 +0000 (-0400) Subject: Add array and sequence "len" accessor X-Git-Tag: v0.1~115 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=3838df2736cd000c3ada39f4ebbb310a0782e4fd;hp=0f980a3595f61930659e392b1248c59490dd5a22;p=babeltrace.git Add array and sequence "len" accessor Signed-off-by: Mathieu Desnoyers --- diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 0c635d57..515e4783 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -247,7 +247,7 @@ int create_stream_packet_index(struct trace_descriptor *td, field = struct_definition_get_field_from_index(td->ctf_trace.packet_header, len_index); assert(field->definition->declaration->id == CTF_TYPE_ARRAY); defarray = container_of(field->definition, struct definition_array, p); - assert(defarray->declaration->len == UUID_LEN); + assert(array_len(defarray) == UUID_LEN); assert(defarray->declaration->elem->id == CTF_TYPE_INTEGER); for (i = 0; i < UUID_LEN; i++) { diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index d01b6724..232cc203 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -457,6 +457,7 @@ struct field *variant_get_current_field(struct definition_variant *variant); struct declaration_array * array_declaration_new(size_t len, struct declaration *elem_declaration, struct declaration_scope *parent_scope); +uint64_t array_len(struct definition_array *array); struct definition *array_index(struct definition_array *array, uint64_t i); /* @@ -467,6 +468,7 @@ struct declaration_sequence * sequence_declaration_new(struct declaration_integer *len_declaration, struct declaration *elem_declaration, struct declaration_scope *parent_scope); +uint64_t sequence_len(struct definition_sequence *sequence); struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i); /* diff --git a/types/array.c b/types/array.c index d8ddd637..ae994301 100644 --- a/types/array.c +++ b/types/array.c @@ -145,6 +145,11 @@ void _array_definition_free(struct definition *definition) g_free(array); } +uint64_t array_len(struct definition_array *array) +{ + return array->elems->len; +} + struct definition *array_index(struct definition_array *array, uint64_t i) { if (i >= array->elems->len) diff --git a/types/sequence.c b/types/sequence.c index 50763d7a..e3586d38 100644 --- a/types/sequence.c +++ b/types/sequence.c @@ -167,6 +167,11 @@ void _sequence_definition_free(struct definition *definition) g_free(sequence); } +uint64_t sequence_len(struct definition_sequence *sequence) +{ + return sequence->len->value._unsigned; +} + struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i) { if (i >= sequence->len->value._unsigned)