X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fsequence.c;h=736e866439bfbcf90b17df5be9a6ffe000da2eec;hp=119522d7de7a084f42345aef5a73b999755ebf7e;hb=13fad8b6d8ad53a55baca25234a0c59aeff83a3b;hpb=98df1c9fb24d5e7e10bf628692011e130e0d8339 diff --git a/types/sequence.c b/types/sequence.c index 119522d7..736e8664 100644 --- a/types/sequence.c +++ b/types/sequence.c @@ -3,7 +3,9 @@ * * BabelTrace - Sequence Type Converter * - * Copyright 2010, 2011 - Mathieu Desnoyers + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -14,10 +16,19 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ #include #include +#include #include static @@ -57,13 +68,18 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition) str = g_string_new(""); g_string_printf(str, "[%" PRIu64 "]", i); - (void) g_string_free(str, TRUE); name = g_quark_from_string(str->str); + (void) g_string_free(str, TRUE); field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i); *field = sequence_declaration->elem->definition_new(sequence_declaration->elem, - sequence_definition->scope, + sequence_definition->p.scope, name, i, NULL); + } + for (i = 0; i < len; i++) { + struct definition **field; + + field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i); ret = generic_rw(pos, *field); if (ret) return ret; @@ -79,7 +95,7 @@ void _sequence_declaration_free(struct declaration *declaration) free_declaration_scope(sequence_declaration->scope); g_array_free(sequence_declaration->length_name, TRUE); - declaration_unref(sequence_declaration->elem); + bt_declaration_unref(sequence_declaration->elem); g_free(sequence_declaration); } @@ -95,9 +111,9 @@ struct declaration_sequence * declaration = &sequence_declaration->p; sequence_declaration->length_name = g_array_new(FALSE, TRUE, sizeof(GQuark)); - append_scope_path(length, sequence_declaration->length_name); + bt_append_scope_path(length, sequence_declaration->length_name); - declaration_ref(elem_declaration); + bt_declaration_ref(elem_declaration); sequence_declaration->elem = elem_declaration; sequence_declaration->scope = new_declaration_scope(parent_scope); declaration->id = CTF_TYPE_SEQUENCE; @@ -122,7 +138,7 @@ struct definition *_sequence_definition_new(struct declaration *declaration, int ret; sequence = g_new(struct definition_sequence, 1); - declaration_ref(&sequence_declaration->p); + bt_declaration_ref(&sequence_declaration->p); sequence->p.declaration = declaration; sequence->declaration = sequence_declaration; sequence->p.ref = 1; @@ -133,13 +149,13 @@ struct definition *_sequence_definition_new(struct declaration *declaration, sequence->p.index = root_name ? INT_MAX : index; sequence->p.name = field_name; sequence->p.path = new_definition_path(parent_scope, field_name, root_name); - sequence->scope = new_definition_scope(parent_scope, field_name, root_name); + sequence->p.scope = new_definition_scope(parent_scope, field_name, root_name); ret = register_field_definition(field_name, &sequence->p, parent_scope); assert(!ret); - len_parent = lookup_definition(sequence->scope->scope_path, - sequence_declaration->length_name, - parent_scope); + len_parent = lookup_path_definition(sequence->p.scope->scope_path, + sequence_declaration->length_name, + parent_scope); if (!len_parent) { printf("[error] Lookup for sequence length field failed.\n"); goto error; @@ -150,13 +166,33 @@ struct definition *_sequence_definition_new(struct declaration *declaration, printf("[error] Sequence length field should be unsigned.\n"); goto error; } - definition_ref(len_parent); + bt_definition_ref(len_parent); + + sequence->string = NULL; + sequence->elems = NULL; + + if (sequence_declaration->elem->id == CTF_TYPE_INTEGER) { + struct declaration_integer *integer_declaration = + container_of(sequence_declaration->elem, struct declaration_integer, p); + + if (integer_declaration->encoding == CTF_STRING_UTF8 + || integer_declaration->encoding == CTF_STRING_ASCII) { + + sequence->string = g_string_new(""); + + if (integer_declaration->len == CHAR_BIT + && integer_declaration->p.alignment == CHAR_BIT) { + return &sequence->p; + } + } + } + sequence->elems = g_ptr_array_new(); return &sequence->p; error: - free_definition_scope(sequence->scope); - declaration_unref(&sequence_declaration->p); + free_definition_scope(sequence->p.scope); + bt_declaration_unref(&sequence_declaration->p); g_free(sequence); return NULL; } @@ -169,16 +205,20 @@ void _sequence_definition_free(struct definition *definition) struct definition *len_definition = &sequence->length->p; uint64_t i; - for (i = 0; i < sequence->elems->len; i++) { - struct definition *field; + if (sequence->string) + (void) g_string_free(sequence->string, TRUE); + if (sequence->elems) { + for (i = 0; i < sequence->elems->len; i++) { + struct definition *field; - field = g_ptr_array_index(sequence->elems, i); - field->declaration->definition_free(field); + field = g_ptr_array_index(sequence->elems, i); + field->declaration->definition_free(field); + } + (void) g_ptr_array_free(sequence->elems, TRUE); } - (void) g_ptr_array_free(sequence->elems, TRUE); - definition_unref(len_definition); - free_definition_scope(sequence->scope); - declaration_unref(sequence->p.declaration); + bt_definition_unref(len_definition); + free_definition_scope(sequence->p.scope); + bt_declaration_unref(sequence->p.declaration); g_free(sequence); } @@ -189,6 +229,8 @@ uint64_t sequence_len(struct definition_sequence *sequence) struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i) { + if (!sequence->elems) + return NULL; if (i >= sequence->length->value._unsigned) return NULL; assert(i < sequence->elems->len);