X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fstruct.c;h=6012447bc2a678194aa4ba5dc8a278ea3e58073e;hp=211d1b02dd16bbc199695f29a976c6eb3c4c8759;hb=312623540c466defab45503fbe0ce7ec79dcce85;hpb=d11e9c4975d88591e2324b6b11f426a22995833f diff --git a/types/struct.c b/types/struct.c index 211d1b02..6012447b 100644 --- a/types/struct.c +++ b/types/struct.c @@ -30,17 +30,21 @@ struct definition *_struct_definition_new(struct declaration *declaration, static void _struct_definition_free(struct definition *definition); -void struct_rw(struct stream_pos *ppos, struct definition *definition) +int struct_rw(struct stream_pos *ppos, struct definition *definition) { struct definition_struct *struct_definition = container_of(definition, struct definition_struct, p); unsigned long i; + int ret; for (i = 0; i < struct_definition->fields->len; i++) { - struct field *field = &g_array_index(struct_definition->fields, - struct field, i); - 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; } + return 0; } static @@ -104,25 +108,23 @@ struct definition * _struct->declaration = struct_declaration; _struct->p.ref = 1; _struct->p.index = index; + _struct->p.name = field_name; + _struct->p.path = new_definition_path(parent_scope, 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); } @@ -138,9 +140,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); @@ -207,11 +208,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); }