From 6ee5115efee00adab0c8f384bc9c0f38fed8a84e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 27 Feb 2011 11:02:53 -0500 Subject: [PATCH] Build fixes. Signed-off-by: Mathieu Desnoyers --- formats/ctf/types/Makefile.am | 3 ++- include/babeltrace/types.h | 4 ++-- types/Makefile.am | 1 + types/array.c | 29 ++++++++------------------ types/enum.c | 30 ++++++++------------------- types/float.c | 28 +++---------------------- types/integer.c | 13 +++--------- types/sequence.c | 39 ++++++++++++----------------------- types/string.c | 13 +++--------- types/struct.c | 24 ++++++--------------- types/types.c | 5 ++++- types/variant.c | 33 +++++++++-------------------- 12 files changed, 65 insertions(+), 157 deletions(-) diff --git a/formats/ctf/types/Makefile.am b/formats/ctf/types/Makefile.am index 81c7bf71..9ce41a6b 100644 --- a/formats/ctf/types/Makefile.am +++ b/formats/ctf/types/Makefile.am @@ -9,4 +9,5 @@ libctf_types_a_SOURCES = \ integer.c \ sequence.c \ string.c \ - struct.c + struct.c \ + variant.c diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index fe7ab629..3d396c86 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -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 */ }; diff --git a/types/Makefile.am b/types/Makefile.am index d98733da..36c4337b 100644 --- a/types/Makefile.am +++ b/types/Makefile.am @@ -10,4 +10,5 @@ libtypes_a_SOURCES = \ sequence.c \ string.c \ struct.c \ + variant.c \ types.c diff --git a/types/array.c b/types/array.c index 6dd3b9ca..e6a6c218 100644 --- a/types/array.c +++ b/types/array.c @@ -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); diff --git a/types/enum.c b/types/enum.c index a6d56ac9..e29df080 100644 --- a/types/enum.c +++ b/types/enum.c @@ -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); } diff --git a/types/float.c b/types/float.c index a945fd29..ae23a96c 100644 --- a/types/float.c +++ b/types/float.c @@ -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; diff --git a/types/integer.c b/types/integer.c index 40deeb2b..1a8601eb 100644 --- a/types/integer.c +++ b/types/integer.c @@ -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; diff --git a/types/sequence.c b/types/sequence.c index 40a69983..e769b81e 100644 --- a/types/sequence.c +++ b/types/sequence.c @@ -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); diff --git a/types/string.c b/types/string.c index 3b3cb074..c6cbb54c 100644 --- a/types/string.c +++ b/types/string.c @@ -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; diff --git a/types/struct.c b/types/struct.c index ba3295f9..92ede586 100644 --- a/types/struct.c +++ b/types/struct.c @@ -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, diff --git a/types/types.c b/types/types.c index b766f8d8..8272b814 100644 --- a/types/types.c +++ b/types/types.c @@ -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; diff --git a/types/variant.c b/types/variant.c index 87cf9632..91b323ff 100644 --- a/types/variant.c +++ b/types/variant.c @@ -18,7 +18,7 @@ #include #include - +#include 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; -- 2.34.1