Build fixes.
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 27 Feb 2011 16:02:53 +0000 (11:02 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 27 Feb 2011 16:02:53 +0000 (11:02 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 files changed:
formats/ctf/types/Makefile.am
include/babeltrace/types.h
types/Makefile.am
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 81c7bf71cf269cf3cc274773141175e1b52ab5f4..9ce41a6bec267ab8a4cb5b53c08426f527236b72 100644 (file)
@@ -9,4 +9,5 @@ libctf_types_a_SOURCES = \
        integer.c \
        sequence.c \
        string.c \
-       struct.c
+       struct.c \
+       variant.c
index fe7ab62950f10604a1f4971b03f901bb6ab71f3c..3d396c86b03b5d161ab35bace26cc2b965ad4eed 100644 (file)
@@ -229,7 +229,7 @@ struct type_field {
 };
 
 struct field {
-       struct declaration *type;
+       struct declaration *declaration;
 };
 
 struct type_struct {
@@ -255,7 +255,7 @@ struct declaration_variant {
        struct declaration p;
        struct type_variant *type;
        struct declaration_scope *scope;
-       struct declaration *tag;
+       struct declaration *enum_tag;
        GArray *fields;                 /* Array of struct field */
        struct field *current_field;    /* Last field read */
 };
index d98733da8ebfcb49ffaa414f7134aced9dac0f96..36c4337b4c4c19464b82e094bcb5b31e39fd7df7 100644 (file)
@@ -10,4 +10,5 @@ libtypes_a_SOURCES = \
        sequence.c \
        string.c \
        struct.c \
+       variant.c \
        types.c
index 6dd3b9ca8a6c869e419ef17c54ff9141ebf8c31f..e6a6c218c9c6c4d025ba8dc115f10a95cf4f5465 100644 (file)
@@ -38,8 +38,8 @@ void array_copy(struct stream_pos *dest, const struct format *fdest,
        fdest->array_begin(dest, array_type);
 
        for (i = 0; i < array_type->len; i++) {
-               struct type *elem_type = array->current_element.type;
-               elem_type->p.type->copy(dest, fdest, src, fsrc, elem_type);
+               struct declaration *elem = array->current_element.declaration;
+               elem->type->copy(dest, fdest, src, fsrc, elem);
        }
        fsrc->array_end(src, array_type);
        fdest->array_end(dest, array_type);
@@ -60,7 +60,6 @@ struct type_array *
 {
        struct type_array *array_type;
        struct type *type;
-       int ret;
 
        array_type = g_new(struct type_array, 1);
        type = &array_type->p;
@@ -75,18 +74,7 @@ struct type_array *
        type->declaration_new = _array_declaration_new;
        type->declaration_free = _array_declaration_free;
        type->ref = 1;
-
-       if (type->name) {
-               ret = register_type(type);
-               if (ret)
-                       goto error_register;
-       }
        return array_type;
-
-error_register:
-       type_unref(array_type->elem);
-       g_free(array_type);
-       return NULL;
 }
 
 static
@@ -100,24 +88,25 @@ struct declaration *
 
        array = g_new(struct declaration_array, 1);
        type_ref(&array_type->p);
-       array->p.type = array_type;
+       array->p.type = type;
+       array->type = array_type;
        array->p.ref = 1;
        array->scope = new_declaration_scope(parent_scope);
        array->current_element.declaration =
-               array_type->elem.p->declaration_new(&array_type->elem.p,
-                                                   parent_scope);
+               array_type->elem->declaration_new(array_type->elem,
+                                                 parent_scope);
        return &array->p;
 }
 
 static
 void _array_declaration_free(struct declaration *declaration)
 {
-       struct type_array *array =
-               container_of(declaration, struct type_array, p);
+       struct declaration_array *array =
+               container_of(declaration, struct declaration_array, p);
        struct declaration *elem_declaration =
                array->current_element.declaration;
 
-       elem_type->p.type->declaration_free(elem_type);
+       elem_declaration->type->declaration_free(elem_declaration);
        free_declaration_scope(array->scope);
        type_unref(array->p.type);
        g_free(array);
index a6d56ac9dae131ef07be01b6fc185e0a643f19ef..e29df080240b0cd7b08cea34c393e799cd47ff34 100644 (file)
@@ -361,7 +361,7 @@ void enum_copy(struct stream_pos *dest, const struct format *fdest,
        assert(array);
        /* unref previous array */
        if (_enum->value)
-               g_array_unref(_enum->value, TRUE);
+               g_array_unref(_enum->value);
        _enum->value = array;
        /*
         * Arbitrarily choose the first one.
@@ -376,7 +376,7 @@ static
 void _enum_type_free(struct type *type)
 {
        struct type_enum *enum_type =
-               container_of(type, struct enum_type, p);
+               container_of(type, struct type_enum, p);
        struct enum_range_to_quark *iter, *tmp;
 
        g_hash_table_destroy(enum_type->table.value_to_quark_set);
@@ -385,7 +385,7 @@ void _enum_type_free(struct type *type)
                g_free(iter);
        }
        g_hash_table_destroy(enum_type->table.quark_to_range_set);
-       type_unref(enum_type->integer_type);
+       type_unref(&enum_type->integer_type->p);
        g_free(enum_type);
 }
 
@@ -393,7 +393,6 @@ struct type_enum *
        _enum_type_new(const char *name, struct type_integer *integer_type)
 {
        struct type_enum *enum_type;
-       int ret;
 
        enum_type = g_new(struct type_enum, 1);
 
@@ -405,7 +404,7 @@ struct type_enum *
        enum_type->table.quark_to_range_set = g_hash_table_new_full(g_int_hash,
                                                        g_int_equal,
                                                        NULL, enum_range_set_free);
-       type_ref(integer_type);
+       type_ref(&integer_type->p);
        enum_type->integer_type = integer_type;
        enum_type->p.name = g_quark_from_string(name);
        enum_type->p.alignment = 1;
@@ -414,19 +413,7 @@ struct type_enum *
        enum_type->p.declaration_new = _enum_declaration_new;
        enum_type->p.declaration_free = _enum_declaration_free;
        enum_type->p.ref = 1;
-       if (enum_type->p.name) {
-               ret = register_type(&enum_type->p);
-               if (ret)
-                       goto register_error;
-       }
        return enum_type;
-
-register_error:
-       g_hash_table_destroy(enum_type->table.value_to_quark_set);
-       g_hash_table_destroy(enum_type->table.quark_to_range_set);
-       type_unref(enum_type->integer_type);
-       g_free(enum_type);
-       return NULL;
 }
 
 static
@@ -437,11 +424,12 @@ struct declaration *
        struct type_enum *enum_type =
                container_of(type, struct type_enum, p);
        struct declaration_enum *_enum;
-       struct declaration_integer_parent *declaration_integer_parent;
+       struct declaration *declaration_integer_parent;
 
        _enum = g_new(struct declaration_enum, 1);
        type_ref(&enum_type->p);
-       _enum->p.type = enum_type;
+       _enum->p.type = type;
+       _enum->type = enum_type;
        _enum->p.ref = 1;
        _enum->value = NULL;
        declaration_integer_parent =
@@ -458,9 +446,9 @@ void _enum_declaration_free(struct declaration *declaration)
        struct declaration_enum *_enum =
                container_of(declaration, struct declaration_enum, p);
 
-       declaration_unref(_enum->integer);
+       declaration_unref(&_enum->integer->p);
        type_unref(_enum->p.type);
        if (_enum->value)
-               g_array_unref(_enum->value, TRUE);
+               g_array_unref(_enum->value);
        g_free(_enum);
 }
index a945fd290e73308f2f093819ab44c9b485b7a4d9..ae23a96c261ef92ce62404b40e1cac2e69e70def 100644 (file)
@@ -63,7 +63,6 @@ struct type_float *
 {
        struct type_float *float_type;
        struct type *type;
-       int ret;
 
        float_type = g_new(struct type_float, 1);
        type = &float_type->p;
@@ -78,33 +77,11 @@ struct type_float *
 
        float_type->sign = integer_type_new(NULL, 1,
                                            byte_order, false, 1);
-       if (!float_type->mantissa)
-               goto error_sign;
        float_type->mantissa = integer_type_new(NULL, mantissa_len - 1,
                                                byte_order, false, 1);
-       if (!float_type->mantissa)
-               goto error_mantissa;
        float_type->exp = integer_type_new(NULL, exp_len,
                                           byte_order, true, 1);
-       if (!float_type->exp)
-               goto error_exp;
-
-       if (float_type->p.name) {
-               ret = register_type(&float_type->p);
-               if (ret)
-                       goto error_register;
-       }
        return float_type;
-
-error_register:
-       type_unref(&float_type->exp->p);
-error_exp:
-       type_unref(&float_type->mantissa->p);
-error_mantissa:
-       type_unref(&float_type->sign->p);
-error_sign:
-       g_free(float_type);
-       return NULL;
 }
 
 static
@@ -117,8 +94,9 @@ struct declaration *
        struct declaration_float *_float;
 
        _float = g_new(struct declaration_float, 1);
-       type_ref(&_float_type->p);
-       _float->p.type= _float_type;
+       type_ref(&float_type->p);
+       _float->p.type= type;
+       _float->type= float_type;
        _float->p.ref = 1;
        _float->value = 0.0;
        return &_float->p;
index 40deeb2b6f969a2d45ef353359488b1f0c718c93..1a8601ebbeb88c57b5d65e87f80d1c05fb954a5a 100644 (file)
@@ -32,7 +32,7 @@ void integer_copy(struct stream_pos *dest, const struct format *fdest,
                  struct declaration *declaration)
 {
        struct declaration_integer *integer =
-               container_of(type, struct declaration_integer, p);
+               container_of(declaration, struct declaration_integer, p);
        struct type_integer *integer_type = integer->type;
 
        if (!integer_type->signedness) {
@@ -61,7 +61,6 @@ struct type_integer *
                         int signedness, size_t alignment)
 {
        struct type_integer *integer_type;
-       int ret;
 
        integer_type = g_new(struct type_integer, 1);
        integer_type->p.name = g_quark_from_string(name);
@@ -74,13 +73,6 @@ struct type_integer *
        integer_type->len = len;
        integer_type->byte_order = byte_order;
        integer_type->signedness = signedness;
-       if (integer_type->p.name) {
-               ret = register_type(&integer_type->p);
-               if (ret) {
-                       g_free(integer_type);
-                       return NULL;
-               }
-       }
        return integer_type;
 }
 
@@ -95,7 +87,8 @@ struct declaration *
 
        integer = g_new(struct declaration_integer, 1);
        type_ref(&integer_type->p);
-       integer->p.type = integer_type;
+       integer->p.type = type;
+       integer->type = integer_type;
        integer->p.ref = 1;
        integer->value._unsigned = 0;
        return &integer->p;
index 40a6998376b2e02b386edd2c1df40ebc9ea9e7d0..e769b81e4e5d1776ead3c748a8acf11d7c8cf5a9 100644 (file)
@@ -45,9 +45,9 @@ void sequence_copy(struct stream_pos *dest, const struct format *fdest,
                                    &sequence->len->p);
 
        for (i = 0; i < sequence->len->value._unsigned; i++) {
-               struct declaration *elem_type =
+               struct declaration *elem =
                        sequence->current_element.declaration;
-               elem_type->p.type->copy(dest, fdest, src, fsrc, elem_type);
+               elem->type->copy(dest, fdest, src, fsrc, elem);
        }
        fsrc->sequence_end(src, sequence_type);
        fdest->sequence_end(dest, sequence_type);
@@ -70,7 +70,6 @@ struct type_sequence *
 {
        struct type_sequence *sequence_type;
        struct type *type;
-       int ret;
 
        sequence_type = g_new(struct type_sequence, 1);
        type = &sequence_type->p;
@@ -86,19 +85,7 @@ struct type_sequence *
        type->declaration_new = _sequence_declaration_new;
        type->declaration_free = _sequence_declaration_free;
        type->ref = 1;
-
-       if (type->name) {
-               ret = register_type(type);
-               if (ret)
-                       goto error_register;
-       }
        return sequence_type;
-
-error_register:
-       type_unref(&len_type->p);
-       type_unref(elem_type);
-       g_free(sequence_type);
-       return NULL;
 }
 
 static
@@ -112,31 +99,31 @@ struct declaration *_sequence_declaration_new(struct type *type,
 
        sequence = g_new(struct declaration_sequence, 1);
        type_ref(&sequence_type->p);
-       sequence->p.type = sequence_type;
+       sequence->p.type = type;
+       sequence->type = sequence_type;
        sequence->p.ref = 1;
        sequence->scope = new_declaration_scope(parent_scope);
-       len_parent = 
-               sequence_type->len_type.p->type_new(&sequence_type->len_type.p,
-                                                   parent_scope);
+       len_parent = sequence_type->len_type->p.declaration_new(&sequence_type->len_type->p,
+                                                               parent_scope);
        sequence->len =
                container_of(len_parent, struct declaration_integer, p);
        sequence->current_element.declaration =
-               sequence_type->elem.p->type_new(&sequence_type->elem.p,
-                                               parent_scope);
+               sequence_type->elem->declaration_new(sequence_type->elem,
+                                                    parent_scope);
        return &sequence->p;
 }
 
 static
 void _sequence_declaration_free(struct declaration *declaration)
 {
-       struct type_sequence *sequence =
-               container_of(declaration, struct type_sequence, p);
-       struct declaration *len_declaration = sequence->len;
+       struct declaration_sequence *sequence =
+               container_of(declaration, struct declaration_sequence, p);
+       struct declaration *len_declaration = &sequence->len->p;
        struct declaration *elem_declaration =
                sequence->current_element.declaration;
 
-       len_declaration->p.type->declaration_free(len_declaration);
-       elem_declaration->p.type->declaration_free(elem_declaration);
+       len_declaration->type->declaration_free(len_declaration);
+       elem_declaration->type->declaration_free(elem_declaration);
        free_declaration_scope(sequence->scope);
        type_unref(sequence->p.type);
        g_free(sequence);
index 3b3cb07416cce808e4f5c299d92b5c4220b1fcb3..c6cbb54cbe45ea005c01fd0f4273245f4a5d3847 100644 (file)
@@ -56,7 +56,6 @@ void _string_type_free(struct type *type)
 struct type_string *string_type_new(const char *name)
 {
        struct type_string *string_type;
-       int ret;
 
        string_type = g_new(struct type_string, 1);
        string_type->p.name = g_quark_from_string(name);
@@ -64,15 +63,8 @@ struct type_string *string_type_new(const char *name)
        string_type->p.copy = string_copy;
        string_type->p.type_free = _string_type_free;
        string_type->p.declaration_new = _string_declaration_new;
-       string_type->p.declaration_free = _strin_declaration_free;
+       string_type->p.declaration_free = _string_declaration_free;
        string_type->p.ref = 1;
-       if (string_type->p.name) {
-               ret = register_type(&string_type->p);
-               if (ret) {
-                       g_free(string_type);
-                       return NULL;
-               }
-       }
        return string_type;
 }
 
@@ -87,7 +79,8 @@ struct declaration *
 
        string = g_new(struct declaration_string, 1);
        type_ref(&string_type->p);
-       string->p.type = string_type;
+       string->p.type = type;
+       string->type = string_type;
        string->p.ref = 1;
        string->value = NULL;
        return &string->p;
index ba3295f9a67eeedfe286dd2f812f76bebac03bfe..92ede5866d65130f90ecc50bf381374eadefb7a9 100644 (file)
@@ -44,9 +44,9 @@ void struct_copy(struct stream_pos *dest, const struct format *fdest,
        for (i = 0; i < _struct->fields->len; i++) {
                struct field *field = &g_array_index(_struct->fields,
                                                     struct field, i);
-               struct type *field_type = field->type->p.type;
+               struct type *field_type = field->declaration->type;
 
-               field_type->copy(dest, fdest, src, fsrc, &field->type->p);
+               field_type->copy(dest, fdest, src, fsrc, field->declaration);
 
        }
        fsrc->struct_end(src, struct_type);
@@ -63,10 +63,10 @@ void _struct_type_free(struct type *type)
        g_hash_table_destroy(struct_type->fields_by_name);
 
        for (i = 0; i < struct_type->fields->len; i++) {
-               struct field *type_field =
+               struct type_field *type_field =
                        &g_array_index(struct_type->fields,
                                       struct type_field, i);
-               type_unref(field->type);
+               type_unref(type_field->type);
        }
        g_array_free(struct_type->fields, true);
        g_free(struct_type);
@@ -76,7 +76,6 @@ struct type_struct *struct_type_new(const char *name)
 {
        struct type_struct *struct_type;
        struct type *type;
-       int ret;
 
        struct_type = g_new(struct type_struct, 1);
        type = &struct_type->p;
@@ -92,19 +91,7 @@ struct type_struct *struct_type_new(const char *name)
        type->declaration_new = _struct_declaration_new;
        type->declaration_free = _struct_declaration_free;
        type->ref = 1;
-
-       if (type->name) {
-               ret = register_type(type);
-               if (ret)
-                       goto error_register;
-       }
        return struct_type;
-
-error_register:
-       g_hash_table_destroy(struct_type->fields_by_name);
-       g_array_free(struct_type->fields, true);
-       g_free(struct_type);
-       return NULL;
 }
 
 static
@@ -118,7 +105,8 @@ struct declaration *
 
        _struct = g_new(struct declaration_struct, 1);
        type_ref(&struct_type->p);
-       _struct->p.type = struct_type;
+       _struct->p.type = type;
+       _struct->type = struct_type;
        _struct->p.ref = 1;
        _struct->scope = new_declaration_scope(parent_scope);
        _struct->fields = g_array_sized_new(FALSE, TRUE,
index b766f8d8d4cb415e23011c82eaf217ded71b110a..8272b8147db08fdc822a153d44050beabd9fb19c 100644 (file)
@@ -49,11 +49,14 @@ static void free_type(struct type *type)
 
 static void free_declaration(struct declaration *declaration)
 {
-       declaration->p.declaration_free(declaration);
+       declaration->type->declaration_free(declaration);
 }
 
 int register_type(struct type *type, struct declaration_scope *scope)
 {
+       if (!type->name)
+               return -EPERM;
+
        /* Only lookup in local scope */
        if (lookup_type_scope(type->name, scope))
                return -EEXIST;
index 87cf9632a8a4b868602f92bb6c4e3e4d3375bf02..91b323ffa70cc6f47f0f02e794abfdf28665d245 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <babeltrace/compiler.h>
 #include <babeltrace/format.h>
-
+#include <errno.h>
 
 static
 struct declaration *_variant_declaration_new(struct type *type,
@@ -35,14 +35,13 @@ void variant_copy(struct stream_pos *dest, const struct format *fdest,
        struct type_variant *variant_type = variant->type;
        struct field *field;
        struct type *field_type;
-       unsigned long i;
 
        fsrc->variant_begin(src, variant_type);
        fdest->variant_begin(dest, variant_type);
 
        field = variant_get_current_field(variant);
-       field_type = field->type->p.type;
-       field_type->copy(dest, fdest, src, fsrc, &field->type->p);
+       field_type = field->declaration->type;
+       field_type->copy(dest, fdest, src, fsrc, field->declaration);
 
        fsrc->variant_end(src, variant_type);
        fdest->variant_end(dest, variant_type);
@@ -58,10 +57,10 @@ void _variant_type_free(struct type *type)
        g_hash_table_destroy(variant_type->fields_by_tag);
 
        for (i = 0; i < variant_type->fields->len; i++) {
-               struct field *type_field =
+               struct type_field *type_field =
                        &g_array_index(variant_type->fields,
                                       struct type_field, i);
-               type_unref(field->type);
+               type_unref(type_field->type);
        }
        g_array_free(variant_type->fields, true);
        g_free(variant_type);
@@ -71,7 +70,6 @@ struct type_variant *variant_type_new(const char *name)
 {
        struct type_variant *variant_type;
        struct type *type;
-       int ret;
 
        variant_type = g_new(struct type_variant, 1);
        type = &variant_type->p;
@@ -87,19 +85,7 @@ struct type_variant *variant_type_new(const char *name)
        type->declaration_new = _variant_declaration_new;
        type->declaration_free = _variant_declaration_free;
        type->ref = 1;
-
-       if (type->name) {
-               ret = register_type(type);
-               if (ret)
-                       goto error_register;
-       }
        return variant_type;
-
-error_register:
-       g_hash_table_destroy(variant_type->fields_by_tag);
-       g_array_free(variant_type->fields, true);
-       g_free(variant_type);
-       return NULL;
 }
 
 static
@@ -113,7 +99,8 @@ struct declaration *
 
        variant = g_new(struct declaration_variant, 1);
        type_ref(&variant_type->p);
-       variant->p.type = variant_type;
+       variant->p.type = type;
+       variant->type = variant_type;
        variant->p.ref = 1;
        variant->scope = new_declaration_scope(parent_scope);
        variant->fields = g_array_sized_new(FALSE, TRUE,
@@ -124,7 +111,7 @@ struct declaration *
 }
 
 static
-void variant_declaration_free(struct declaration *declaration)
+void _variant_declaration_free(struct declaration *declaration)
 {
        struct declaration_variant *variant =
                container_of(declaration, struct declaration_variant, p);
@@ -154,7 +141,7 @@ void variant_type_add_field(struct type_variant *variant_type,
        type_ref(tag_type);
        field->type = tag_type;
        /* Keep index in hash rather than pointer, because array can relocate */
-       g_hash_table_insert(variant_type->fields_by_name,
+       g_hash_table_insert(variant_type->fields_by_tag,
                            (gpointer) (unsigned long) field->name,
                            (gpointer) index);
        /*
@@ -227,7 +214,7 @@ struct field *variant_get_current_field(struct declaration_variant *variant)
 {
        struct declaration_enum *_enum =
                container_of(variant->enum_tag, struct declaration_enum, p);
-       struct variant_type *variant_type = variant->type;
+       struct type_variant *variant_type = variant->type;
        unsigned long index;
        GArray *tag_array;
        GQuark tag;
This page took 0.053222 seconds and 4 git commands to generate.