Create copy of integer declaration before applying base-16 for pointers
[babeltrace.git] / types / array.c
index d8ddd637c69bb804e5401e8276da9ba22a69969d..0bb141ce33e14cf3ba2ca12858e734535f3856a4 100644 (file)
@@ -27,27 +27,24 @@ struct definition *_array_definition_new(struct declaration *declaration,
 static
 void _array_definition_free(struct definition *definition);
 
-void array_copy(struct stream_pos *dest, const struct format *fdest, 
-               struct stream_pos *src, const struct format *fsrc,
-               struct definition *definition)
+int array_rw(struct stream_pos *pos, struct definition *definition)
 {
-       struct definition_array *array =
+       struct definition_array *array_definition =
                container_of(definition, struct definition_array, p);
-       struct declaration_array *array_declaration = array->declaration;
+       const struct declaration_array *array_declaration =
+               array_definition->declaration;
        uint64_t i;
+       int ret;
 
-       fsrc->array_begin(src, array_declaration);
-       if (fdest)
-               fdest->array_begin(dest, array_declaration);
-
+       /* 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->elems, struct field, i).definition;
-               elem->declaration->copy(dest, fdest, src, fsrc, elem);
+               struct definition *field =
+                       g_ptr_array_index(array_definition->elems, i);
+               ret = generic_rw(pos, field);
+               if (ret)
+                       return ret;
        }
-       fsrc->array_end(src, array_declaration);
-       if (fdest)
-               fdest->array_end(dest, array_declaration);
+       return 0;
 }
 
 static
@@ -78,7 +75,6 @@ struct declaration_array *
        declaration->id = CTF_TYPE_ARRAY;
        /* No need to align the array, the first element will align itself */
        declaration->alignment = 1;
-       declaration->copy = array_copy;
        declaration->declaration_free = _array_declaration_free;
        declaration->definition_new = _array_definition_new;
        declaration->definition_free = _array_definition_free;
@@ -103,12 +99,13 @@ struct definition *
        array->declaration = array_declaration;
        array->p.ref = 1;
        array->p.index = index;
+       array->p.name = field_name;
+       array->p.path = new_definition_path(parent_scope, 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;
 
@@ -117,9 +114,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);
        }
@@ -134,20 +130,25 @@ 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);
 }
 
+uint64_t array_len(struct definition_array *array)
+{
+       return array->elems->len;
+}
+
 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);
 }
This page took 0.024869 seconds and 4 git commands to generate.