move content of struct field into struct definition
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 11:05:28 +0000 (07:05 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 9 May 2011 11:05:28 +0000 (07:05 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 files changed:
converter/babeltrace-lib.c
formats/ctf/ctf.c
include/babeltrace/types.h
types/array.c
types/enum.c
types/float.c
types/integer.c
types/sequence.c
types/string.c
types/struct.c
types/types.c
types/variant.c

index 35f50719359c527f6db230bd05739b0b71727d8f..c96f38904fba89dd2dee7c8b0876d87ec9ec8d82 100644 (file)
@@ -52,11 +52,11 @@ int convert_event(struct ctf_text_stream_pos *sout,
                                g_quark_from_static_string("id"));
                if (len_index >= 0) {
                        struct definition_integer *defint;
-                       struct field *field;
+                       struct definition *field;
 
                        field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
-                       assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
-                       defint = container_of(field->definition, struct definition_integer, p);
+                       assert(field->declaration->id == CTF_TYPE_INTEGER);
+                       defint = container_of(field, struct definition_integer, p);
                        assert(defint->declaration->signedness == FALSE);
                        id = defint->value._unsigned;   /* set id */
                }
index aae7187284bfe5317d2b4e8e338cf7c858087454..1e7fedd8d3319cae443e838c45a9e2f0e74a302e 100644 (file)
@@ -331,11 +331,11 @@ int create_stream_packet_index(struct ctf_trace *td,
                        len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("magic"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
-                               struct field *field;
+                               struct definition *field;
 
                                field = struct_definition_get_field_from_index(td->packet_header, len_index);
-                               assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
-                               defint = container_of(field->definition, struct definition_integer, p);
+                               assert(field->declaration->id == CTF_TYPE_INTEGER);
+                               defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
                                if (defint->value._unsigned != CTF_MAGIC) {
                                        fprintf(stdout, "[error] Invalid magic number 0x%" PRIX64 " at packet %u (file offset %zd).\n",
@@ -350,13 +350,13 @@ int create_stream_packet_index(struct ctf_trace *td,
                        len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("trace_uuid"));
                        if (len_index >= 0) {
                                struct definition_array *defarray;
-                               struct field *field;
+                               struct definition *field;
                                uint64_t i;
                                uint8_t uuidval[UUID_LEN];
 
                                field = struct_definition_get_field_from_index(td->packet_header, len_index);
-                               assert(field->definition->declaration->id == CTF_TYPE_ARRAY);
-                               defarray = container_of(field->definition, struct definition_array, p);
+                               assert(field->declaration->id == CTF_TYPE_ARRAY);
+                               defarray = container_of(field, struct definition_array, p);
                                assert(array_len(defarray) == UUID_LEN);
                                assert(defarray->declaration->elem->id == CTF_TYPE_INTEGER);
 
@@ -380,11 +380,11 @@ int create_stream_packet_index(struct ctf_trace *td,
                        len_index = struct_declaration_lookup_field_index(td->packet_header->declaration, g_quark_from_static_string("stream_id"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
-                               struct field *field;
+                               struct definition *field;
 
                                field = struct_definition_get_field_from_index(td->packet_header, len_index);
-                               assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
-                               defint = container_of(field->definition, struct definition_integer, p);
+                               assert(field->declaration->id == CTF_TYPE_INTEGER);
+                               defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
                                stream_id = defint->value._unsigned;
                        }
@@ -418,11 +418,11 @@ int create_stream_packet_index(struct ctf_trace *td,
                        len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
-                               struct field *field;
+                               struct definition *field;
 
                                field = struct_definition_get_field_from_index(stream->packet_context, len_index);
-                               assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
-                               defint = container_of(field->definition, struct definition_integer, p);
+                               assert(field->declaration->id == CTF_TYPE_INTEGER);
+                               defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
                                packet_index.content_size = defint->value._unsigned;
                        } else {
@@ -434,11 +434,11 @@ int create_stream_packet_index(struct ctf_trace *td,
                        len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("packet_size"));
                        if (len_index >= 0) {
                                struct definition_integer *defint;
-                               struct field *field;
+                               struct definition *field;
 
                                field = struct_definition_get_field_from_index(stream->packet_context, len_index);
-                               assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
-                               defint = container_of(field->definition, struct definition_integer, p);
+                               assert(field->declaration->id == CTF_TYPE_INTEGER);
+                               defint = container_of(field, struct definition_integer, p);
                                assert(defint->declaration->signedness == FALSE);
                                packet_index.packet_size = defint->value._unsigned;
                        } else {
index cb0044e0471d57e73453452ac60657b3e717674b..059c371dea37cd2323b74a1d29d256ef338997d0 100644 (file)
@@ -100,6 +100,7 @@ struct declaration {
 struct definition {
        struct declaration *declaration;
        int index;              /* Position of the definition in its container */
+       GQuark name;            /* Field name in its container (or 0 if unset) */
        int ref;                /* number of references to the definition */
 };
 
@@ -239,11 +240,6 @@ struct declaration_field {
        struct declaration *declaration;
 };
 
-struct field {
-       GQuark name;
-       struct definition *definition;
-};
-
 struct declaration_struct {
        struct declaration p;
        GHashTable *fields_by_name;     /* Tuples (field name, field index) */
@@ -255,7 +251,7 @@ struct definition_struct {
        struct definition p;
        struct declaration_struct *declaration;
        struct definition_scope *scope;
-       GArray *fields;                 /* Array of struct field */
+       GPtrArray *fields;              /* Array of pointers to struct definition */
 };
 
 struct declaration_untagged_variant {
@@ -277,8 +273,8 @@ struct definition_variant {
        struct declaration_variant *declaration;
        struct definition_scope *scope;
        struct definition *enum_tag;
-       GArray *fields;                 /* Array of struct field */
-       struct field *current_field;    /* Last field read */
+       GPtrArray *fields;              /* Array of pointers to struct definition */
+       struct definition *current_field;       /* Last field read */
 };
 
 struct declaration_array {
@@ -292,7 +288,7 @@ struct definition_array {
        struct definition p;
        struct declaration_array *declaration;
        struct definition_scope *scope;
-       GArray *elems;                  /* struct field */
+       GPtrArray *elems;               /* Array of pointers to struct definition */
 };
 
 struct declaration_sequence {
@@ -307,7 +303,7 @@ struct definition_sequence {
        struct declaration_sequence *declaration;
        struct definition_scope *scope;
        struct definition_integer *len;
-       GArray *elems;                  /* struct field */
+       GPtrArray *elems;               /* Array of pointers to struct definition */
 };
 
 int register_declaration(GQuark declaration_name,
@@ -434,7 +430,7 @@ int struct_declaration_lookup_field_index(struct declaration_struct *struct_decl
 struct declaration_field *
 struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
                                        int index);
-struct field *
+struct definition *
 struct_definition_get_field_from_index(struct definition_struct *struct_definition,
                                       int index);
 int struct_rw(struct stream_pos *pos, struct definition *definition);
@@ -465,7 +461,7 @@ int variant_definition_set_tag(struct definition_variant *variant,
  * field returned only valid as long as the variant structure is not appended
  * to.
  */
-struct field *variant_get_current_field(struct definition_variant *variant);
+struct definition *variant_get_current_field(struct definition_variant *variant);
 int variant_rw(struct stream_pos *pos, struct definition *definition);
 
 /*
index f592dba1ebdf9905cf3230586aaf990d0db9556c..92b8dd065d527818eead5833a74ddcdaaab29808 100644 (file)
@@ -38,9 +38,9 @@ int array_rw(struct stream_pos *pos, struct definition *definition)
 
        /* No need to align, because the first field will align itself. */
        for (i = 0; i < array_declaration->len; i++) {
-               struct definition *elem =
-                       g_array_index(array_definition->elems, struct field, i).definition;
-               ret = generic_rw(pos, elem);
+               struct definition *field =
+                       g_ptr_array_index(array_definition->elems, i);
+               ret = generic_rw(pos, field);
                if (ret)
                        return ret;
        }
@@ -99,12 +99,12 @@ struct definition *
        array->declaration = array_declaration;
        array->p.ref = 1;
        array->p.index = index;
+       array->p.name = field_name;
        array->scope = new_definition_scope(parent_scope, field_name);
-       array->elems = g_array_sized_new(FALSE, TRUE, sizeof(struct field),
-                                        array_declaration->len);
-       g_array_set_size(array->elems, array_declaration->len);
+       array->elems = g_ptr_array_sized_new(array_declaration->len);
+       g_ptr_array_set_size(array->elems, array_declaration->len);
        for (i = 0; i < array_declaration->len; i++) {
-               struct field *field;
+               struct definition **field;
                GString *str;
                GQuark name;
 
@@ -113,9 +113,8 @@ struct definition *
                name = g_quark_from_string(str->str);
                (void) g_string_free(str, TRUE);
 
-               field = &g_array_index(array->elems, struct field, i);
-               field->name = name;
-               field->definition = array_declaration->elem->definition_new(array_declaration->elem,
+               field = (struct definition **) &g_ptr_array_index(array->elems, i);
+               *field = array_declaration->elem->definition_new(array_declaration->elem,
                                          array->scope,
                                          name, i);
        }
@@ -130,12 +129,12 @@ void _array_definition_free(struct definition *definition)
        uint64_t i;
 
        for (i = 0; i < array->elems->len; i++) {
-               struct field *field;
+               struct definition *field;
 
-               field = &g_array_index(array->elems, struct field, i);
-               field->definition->declaration->definition_free(field->definition);
+               field = g_ptr_array_index(array->elems, i);
+               field->declaration->definition_free(field);
        }
-       (void) g_array_free(array->elems, TRUE);
+       (void) g_ptr_array_free(array->elems, TRUE);
        free_definition_scope(array->scope);
        declaration_unref(array->p.declaration);
        g_free(array);
@@ -150,5 +149,5 @@ struct definition *array_index(struct definition_array *array, uint64_t i)
 {
        if (i >= array->elems->len)
                return NULL;
-       return g_array_index(array->elems, struct field, i).definition;
+       return g_ptr_array_index(array->elems, i);
 }
index 5e19231192e799e0323d3aa8607910377ff7a401..82a02dfe26e189096c4bf36343ea0357070b942c 100644 (file)
@@ -409,10 +409,12 @@ struct definition *
        _enum->declaration = enum_declaration;
        _enum->p.ref = 1;
        _enum->p.index = index;
+       _enum->p.name = field_name;
        _enum->value = NULL;
        definition_integer_parent =
                enum_declaration->integer_declaration->p.definition_new(&enum_declaration->integer_declaration->p,
-                                       parent_scope, field_name, 0);
+                               parent_scope,
+                               g_quark_from_static_string("container"), 0);
        _enum->integer = container_of(definition_integer_parent,
                                      struct definition_integer, p);
        return &_enum->p;
index 1efd5ed3624ccf4be0c9469d1a88aabd55d44e5a..7ae4df6e4f39ae77ef58e93080851fe422f8f686 100644 (file)
@@ -103,6 +103,7 @@ struct definition *
        }
        _float->p.ref = 1;
        _float->p.index = index;
+       _float->p.name = field_name;
        _float->value = 0.0;
        return &_float->p;
 }
index 4f79c4ab8642516df07dbd707a200fae30f560b0..c43f55e64c68bd623c0b1c214c1d269f85e20ec4 100644 (file)
@@ -71,6 +71,7 @@ struct definition *
        integer->declaration = integer_declaration;
        integer->p.ref = 1;
        integer->p.index = index;
+       integer->p.name = field_name;
        integer->value._unsigned = 0;
        return &integer->p;
 }
index 965fd30ac841ab1ea48cf16b46091ae1c79868ef..5fcf77aa7e9c1e93b656b0fc996fac10e30ec296 100644 (file)
@@ -54,10 +54,10 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition)
         */
        oldlen = sequence_definition->elems->len;
        if (oldlen < len)
-               g_array_set_size(sequence_definition->elems, len);
+               g_ptr_array_set_size(sequence_definition->elems, len);
 
        for (i = oldlen; i < len; i++) {
-               struct field *field;
+               struct definition **field;
                GString *str;
                GQuark name;
 
@@ -66,12 +66,11 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition)
                (void) g_string_free(str, TRUE);
                name = g_quark_from_string(str->str);
 
-               field = &g_array_index(sequence_definition->elems, struct field, i);
-               field->name = name;
-               field->definition = sequence_declaration->elem->definition_new(sequence_declaration->elem,
+               field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i);
+               *field = sequence_declaration->elem->definition_new(sequence_declaration->elem,
                                          sequence_definition->scope,
                                          name, i);
-               ret = generic_rw(pos, field->definition);
+               ret = generic_rw(pos, *field);
                if (ret)
                        return ret;
        }
@@ -131,13 +130,14 @@ struct definition *_sequence_definition_new(struct declaration *declaration,
        sequence->declaration = sequence_declaration;
        sequence->p.ref = 1;
        sequence->p.index = index;
+       sequence->p.name = field_name;
        sequence->scope = new_definition_scope(parent_scope, field_name);
        len_parent = sequence_declaration->len_declaration->p.definition_new(&sequence_declaration->len_declaration->p,
                                sequence->scope,
                                g_quark_from_static_string("length"), 0);
        sequence->len =
                container_of(len_parent, struct definition_integer, p);
-       sequence->elems = g_array_new(FALSE, TRUE, sizeof(struct field));
+       sequence->elems = g_ptr_array_new();
        return &sequence->p;
 }
 
@@ -150,12 +150,12 @@ void _sequence_definition_free(struct definition *definition)
        uint64_t i;
 
        for (i = 0; i < sequence->elems->len; i++) {
-               struct field *field;
+               struct definition *field;
 
-               field = &g_array_index(sequence->elems, struct field, i);
-               field->definition->declaration->definition_free(field->definition);
+               field = g_ptr_array_index(sequence->elems, i);
+               field->declaration->definition_free(field);
        }
-       (void) g_array_free(sequence->elems, TRUE);
+       (void) g_ptr_array_free(sequence->elems, TRUE);
        len_definition->declaration->definition_free(len_definition);
        free_definition_scope(sequence->scope);
        declaration_unref(sequence->p.declaration);
@@ -172,5 +172,5 @@ struct definition *sequence_index(struct definition_sequence *sequence, uint64_t
        if (i >= sequence->len->value._unsigned)
                return NULL;
        assert(i < sequence->elems->len);
-       return g_array_index(sequence->elems, struct field, i).definition;
+       return g_ptr_array_index(sequence->elems, i);
 }
index a83a1541bb89a8f3ac1ef2149e5d9c0fbcd7281b..f940155399d9a4df2497489d0dc017c4eebd3096 100644 (file)
@@ -67,6 +67,7 @@ struct definition *
        string->declaration = string_declaration;
        string->p.ref = 1;
        string->p.index = index;
+       string->p.name = field_name;
        string->value = NULL;
        string->len = 0;
        string->alloc_len = 0;
index 6e82b57fb845e13d1c69d837efca679928dedd12..1a2b59d51e26e9cbb319f313aac798dba2bd0d51 100644 (file)
@@ -38,9 +38,9 @@ int struct_rw(struct stream_pos *ppos, struct definition *definition)
        int ret;
 
        for (i = 0; i < struct_definition->fields->len; i++) {
-               struct field *field = &g_array_index(struct_definition->fields,
-                                                    struct field, i);
-               ret = generic_rw(ppos, field->definition);
+               struct definition *field =
+                       g_ptr_array_index(struct_definition->fields, i);
+               ret = generic_rw(ppos, field);
                if (ret)
                        return ret;
        }
@@ -108,25 +108,22 @@ struct definition *
        _struct->declaration = struct_declaration;
        _struct->p.ref = 1;
        _struct->p.index = index;
+       _struct->p.name = field_name;
        _struct->scope = new_definition_scope(parent_scope, field_name);
-       _struct->fields = g_array_sized_new(FALSE, TRUE,
-                                           sizeof(struct field),
-                                           DEFAULT_NR_STRUCT_FIELDS);
-       g_array_set_size(_struct->fields, struct_declaration->fields->len);
+       _struct->fields = g_ptr_array_sized_new(DEFAULT_NR_STRUCT_FIELDS);
+       g_ptr_array_set_size(_struct->fields, struct_declaration->fields->len);
        for (i = 0; i < struct_declaration->fields->len; i++) {
                struct declaration_field *declaration_field =
                        &g_array_index(struct_declaration->fields,
                                       struct declaration_field, i);
-               struct field *field = &g_array_index(_struct->fields,
-                                                    struct field, i);
+               struct definition **field =
+                       (struct definition **) &g_ptr_array_index(_struct->fields, i);
 
-               field->name = declaration_field->name;
-               field->definition =
-                       declaration_field->declaration->definition_new(declaration_field->declaration,
+               *field = declaration_field->declaration->definition_new(declaration_field->declaration,
                                                          _struct->scope,
-                                                         field->name, i);
-               ret = register_field_definition(field->name,
-                                               field->definition,
+                                                         declaration_field->name, i);
+               ret = register_field_definition(declaration_field->name,
+                                               *field,
                                                _struct->scope);
                assert(!ret);
        }
@@ -142,9 +139,8 @@ void _struct_definition_free(struct definition *definition)
 
        assert(_struct->fields->len == _struct->declaration->fields->len);
        for (i = 0; i < _struct->fields->len; i++) {
-               struct field *field = &g_array_index(_struct->fields,
-                                                    struct field, i);
-               definition_unref(field->definition);
+               struct definition *field = g_ptr_array_index(_struct->fields, i);
+               definition_unref(field);
        }
        free_definition_scope(_struct->scope);
        declaration_unref(_struct->p.declaration);
@@ -211,11 +207,11 @@ struct declaration_field *
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
-struct field *
+struct definition *
 struct_definition_get_field_from_index(struct definition_struct *_struct,
                                        int index)
 {
        if (index < 0)
                return NULL;
-       return &g_array_index(_struct->fields, struct field, index);
+       return g_ptr_array_index(_struct->fields, index);
 }
index 08324acc481dd5e594525282d3329d4a15459f41..1766c61b1cd5e953c761720b901a2ad24292d98e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * declarations.c
+ * types.c
  *
  * BabelTrace - Converter
  *
index 2a4087254a3f739b80a3683e01e09ed77fdd5fd0..479b4ba4079e8ab80f4535677ae9a7aafedfe79f 100644 (file)
@@ -31,10 +31,10 @@ int variant_rw(struct stream_pos *ppos, struct definition *definition)
 {
        struct definition_variant *variant_definition =
                container_of(definition, struct definition_variant, p);
-       struct field *field;
+       struct definition *field;
 
        field = variant_get_current_field(variant_definition);
-       return generic_rw(ppos, field->definition);
+       return generic_rw(ppos, field);
 }
 
 static
@@ -174,6 +174,7 @@ struct definition *
        variant->declaration = variant_declaration;
        variant->p.ref = 1;
        variant->p.index = index;
+       variant->p.name = field_name;
        variant->scope = new_definition_scope(parent_scope, field_name);
        variant->enum_tag = lookup_definition(variant->scope->scope_path,
                                              variant_declaration->tag_name,
@@ -183,26 +184,22 @@ struct definition *
            || check_enum_tag(variant, variant->enum_tag) < 0)
                goto error;
        definition_ref(variant->enum_tag);
-       variant->fields = g_array_sized_new(FALSE, TRUE,
-                                           sizeof(struct field),
-                                           variant_declaration->untagged_variant->fields->len);
-       g_array_set_size(variant->fields, variant_declaration->untagged_variant->fields->len);
+       variant->fields = g_ptr_array_sized_new(variant_declaration->untagged_variant->fields->len);
+       g_ptr_array_set_size(variant->fields, variant_declaration->untagged_variant->fields->len);
        for (i = 0; i < variant_declaration->untagged_variant->fields->len; i++) {
                struct declaration_field *declaration_field =
                        &g_array_index(variant_declaration->untagged_variant->fields,
                                       struct declaration_field, i);
-               struct field *field = &g_array_index(variant->fields,
-                                                    struct field, i);
+               struct definition **field =
+                       (struct definition **) &g_ptr_array_index(variant->fields, i);
 
-               field->name = declaration_field->name;
                /*
                 * All child definition are at index 0, because they are
                 * various choices of the same field.
                 */
-               field->definition =
-                       declaration_field->declaration->definition_new(declaration_field->declaration,
-                                                         variant->scope,
-                                                         field->name, 0);
+               *field = declaration_field->declaration->definition_new(declaration_field->declaration,
+                                                 variant->scope,
+                                                 declaration_field->name, 0);
        }
        variant->current_field = NULL;
        return &variant->p;
@@ -222,9 +219,8 @@ void _variant_definition_free(struct definition *definition)
 
        assert(variant->fields->len == variant->declaration->untagged_variant->fields->len);
        for (i = 0; i < variant->fields->len; i++) {
-               struct field *field = &g_array_index(variant->fields,
-                                                    struct field, i);
-               definition_unref(field->definition);
+               struct definition *field = g_ptr_array_index(variant->fields, i);
+               definition_unref(field);
        }
        definition_unref(variant->enum_tag);
        free_definition_scope(variant->scope);
@@ -269,7 +265,7 @@ untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_vari
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
-struct field *variant_get_current_field(struct definition_variant *variant)
+struct definition *variant_get_current_field(struct definition_variant *variant)
 {
        struct definition_enum *_enum =
                container_of(variant->enum_tag, struct definition_enum, p);
@@ -287,6 +283,6 @@ struct field *variant_get_current_field(struct definition_variant *variant)
        tag = g_array_index(tag_array, GQuark, 0);
        index = (unsigned long) g_hash_table_lookup(variant_declaration->untagged_variant->fields_by_tag,
                                                    (gconstpointer) (unsigned long) tag);
-       variant->current_field = &g_array_index(variant->fields, struct field, index);
+       variant->current_field = g_ptr_array_index(variant->fields, index);
        return variant->current_field;
 }
This page took 0.054517 seconds and 4 git commands to generate.