Enum printing fix, enum / variant header handling
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 22 May 2011 16:26:13 +0000 (12:26 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 22 May 2011 16:26:13 +0000 (12:26 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf-text/ctf-text.c
formats/ctf-text/types/enum.c
formats/ctf/ctf.c
types/enum.c

index 9c44958996deca5503c701601e5355b86f3ce9a3..82578dca139afb4aeae48e35edebdb48d6942dc8 100644 (file)
@@ -63,23 +63,32 @@ int ctf_text_write_event(struct stream_pos *ppos,
        int field_nr_saved;
        struct ctf_event *event_class;
        uint64_t id = 0;
-       int len_index;
        int ret;
 
        /* print event header */
        if (stream_class->event_header) {
+               struct definition_integer *integer_definition;
+               struct definition *variant;
+
                /* lookup event id */
-               len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
-                               g_quark_from_static_string("id"));
-               if (len_index >= 0) {
-                       struct definition_integer *defint;
-                       struct definition *field;
-
-                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
-                       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 */
+               integer_definition = lookup_integer(&stream_class->event_header->p, "id", FALSE);
+               if (integer_definition) {
+                       id = integer_definition->value._unsigned;
+               } else {
+                       struct definition_enum *enum_definition;
+
+                       enum_definition = lookup_enum(&stream_class->event_header->p, "id", FALSE);
+                       if (enum_definition) {
+                               id = enum_definition->integer->value._unsigned;
+                       }
+               }
+
+               variant = lookup_variant(&stream_class->event_header->p, "v");
+               if (variant) {
+                       integer_definition = lookup_integer(variant, "id", FALSE);
+                       if (integer_definition) {
+                               id = integer_definition->value._unsigned;
+                       }
                }
        }
 
index 381491a4dc81e68560ac6c1467c4b107b339d6af..7a9a948d3e5ee0fbe080e79766578fbac2743391 100644 (file)
@@ -29,6 +29,7 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
        GArray *qs;
        int i, ret;
+       int field_nr_saved;
 
        if (pos->dummy)
                return 0;
@@ -40,24 +41,29 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
                fprintf(pos->fp, "%s = ",
                        g_quark_to_string(definition->name));
 
+       field_nr_saved = pos->field_nr;
+       pos->field_nr = 0;
        fprintf(pos->fp, "(");
        pos->depth++;
        ret = generic_rw(ppos, &integer_definition->p);
-       fprintf(pos->fp, " :");
+       fprintf(pos->fp, ":");
 
        qs = enum_definition->value;
        assert(qs);
 
+       pos->field_nr = 0;
        for (i = 0; i < qs->len; i++) {
                GQuark q = g_array_index(qs, GQuark, i);
                const char *str = g_quark_to_string(q);
 
-               if (i != 0)
+               assert(str);
+               if (pos->field_nr++ != 0)
                        fprintf(pos->fp, ",");
                fprintf(pos->fp, " ");
-               fprintf(pos->fp, "%s\n", str);
+               fprintf(pos->fp, "%s", str);
        }
        pos->depth--;
        fprintf(pos->fp, " )");
+       pos->field_nr = field_nr_saved;
        return ret;
 }
index e84e19d870e0d5bd1531e8cdb9266effa2d6806b..730e2a3ae1fee0a7613475d38e1bedd22d0649a3 100644 (file)
@@ -101,6 +101,7 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
        /* Read event header */
        if (stream_class->event_header) {
                struct definition_integer *integer_definition;
+               struct definition *variant;
 
                ret = generic_rw(ppos, &stream_class->event_header->p);
                if (ret)
@@ -118,20 +119,21 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream *stream)
                        }
                }
 
+               variant = lookup_variant(&stream_class->event_header->p, "v");
+               if (variant) {
+                       integer_definition = lookup_integer(variant, "id", FALSE);
+                       if (integer_definition) {
+                               id = integer_definition->value._unsigned;
+                       }
+               }
+
                /* lookup timestamp */
                integer_definition = lookup_integer(&stream_class->event_header->p, "timestamp", FALSE);
                if (integer_definition) {
                        stream->timestamp = integer_definition->value._unsigned;
                } else {
-                       struct definition *definition;
-
-                       definition = lookup_variant(&stream_class->event_header->p, "v");
-                       if (definition) {
-                               integer_definition = lookup_integer(definition, "id", FALSE);
-                               if (integer_definition) {
-                                       id = integer_definition->value._unsigned;
-                               }
-                               integer_definition = lookup_integer(definition, "timestamp", FALSE);
+                       if (variant) {
+                               integer_definition = lookup_integer(variant, "timestamp", FALSE);
                                if (integer_definition) {
                                        stream->timestamp = integer_definition->value._unsigned;
                                }
@@ -183,23 +185,32 @@ int ctf_write_event(struct stream_pos *pos, struct ctf_stream *stream)
        struct ctf_stream_class *stream_class = stream->stream_class;
        struct ctf_event *event_class;
        uint64_t id = 0;
-       int len_index;
        int ret;
 
        /* print event header */
        if (stream_class->event_header) {
+               struct definition_integer *integer_definition;
+               struct definition *variant;
+
                /* lookup event id */
-               len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
-                               g_quark_from_static_string("id"));
-               if (len_index >= 0) {
-                       struct definition_integer *defint;
-                       struct definition *field;
-
-                       field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
-                       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 */
+               integer_definition = lookup_integer(&stream_class->event_header->p, "id", FALSE);
+               if (integer_definition) {
+                       id = integer_definition->value._unsigned;
+               } else {
+                       struct definition_enum *enum_definition;
+
+                       enum_definition = lookup_enum(&stream_class->event_header->p, "id", FALSE);
+                       if (enum_definition) {
+                               id = enum_definition->integer->value._unsigned;
+                       }
+               }
+
+               variant = lookup_variant(&stream_class->event_header->p, "v");
+               if (variant) {
+                       integer_definition = lookup_integer(variant, "id", FALSE);
+                       if (integer_definition) {
+                               id = integer_definition->value._unsigned;
+                       }
                }
 
                ret = generic_rw(pos, &stream_class->event_header->p);
index 6fcbe683a9ab12a9c11042e5c2c809332dd3cca8..5e7b8a4d61dd94f8df96261298bdddb88a240ef6 100644 (file)
@@ -125,18 +125,18 @@ GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
                        if (qs)
                                qs_len = qs->len;
                        ranges = g_array_sized_new(FALSE, TRUE,
-                                       sizeof(struct enum_range),
+                                       sizeof(GQuark),
                                        qs_len + 1);
                        g_array_set_size(ranges, qs_len + 1);
                        if (qs)
                                memcpy(ranges->data, qs->data,
-                                      sizeof(struct enum_range) * qs_len);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                                      sizeof(GQuark) * qs_len);
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                } else {
                        size_t qs_len = ranges->len;
 
                        g_array_set_size(ranges, qs_len + 1);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                }
        }
        if (!ranges) {
@@ -172,18 +172,18 @@ GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
                        if (qs)
                                qs_len = qs->len;
                        ranges = g_array_sized_new(FALSE, TRUE,
-                                       sizeof(struct enum_range),
+                                       sizeof(GQuark),
                                        qs_len + 1);
                        g_array_set_size(ranges, qs_len + 1);
                        if (qs)
                                memcpy(ranges->data, qs->data,
-                                      sizeof(struct enum_range) * qs_len);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                                      sizeof(GQuark) * qs_len);
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                } else {
                        size_t qs_len = ranges->len;
 
                        g_array_set_size(ranges, qs_len + 1);
-                       g_array_index(ranges, struct enum_range, qs_len) = iter->range;
+                       g_array_index(ranges, GQuark, qs_len) = iter->quark;
                }
        }
        if (!ranges) {
This page took 0.040733 seconds and 4 git commands to generate.