Fix integer/float/string read: keep value in definition structure
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 5 May 2011 16:52:41 +0000 (12:52 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 5 May 2011 16:52:41 +0000 (12:52 -0400)
Makes magic number read works.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/ctf/metadata/ctf-test/succeed/ctf-embedded-2.txt
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
include/babeltrace/ctf/types.h
include/babeltrace/format.h
types/float.c
types/integer.c
types/string.c

index 515e478357b3e519d1f4cb5e43fbf8bd5f83fb0d..54aaed7e426749b80f246bf6eccc5210809c9cad 100644 (file)
@@ -59,6 +59,8 @@ static struct format ctf_format = {
        .int_write = ctf_int_write,
        .double_read = ctf_double_read,
        .double_write = ctf_double_write,
+       .ldouble_read = ctf_ldouble_read,
+       .ldouble_write = ctf_ldouble_write,
        .float_copy = ctf_float_copy,
        .string_copy = ctf_string_copy,
        .string_read = ctf_string_read,
@@ -209,8 +211,8 @@ int create_stream_packet_index(struct trace_descriptor *td,
                /* map new base. Need mapping length from header. */
                pos->base = mmap(NULL, MAX_PACKET_HEADER_LEN, PROT_READ,
                                 MAP_PRIVATE, pos->fd, pos->mmap_offset);
-               pos->content_size = 0;  /* Unknown at this point */
-               pos->packet_size = 0;   /* Unknown at this point */
+               pos->content_size = MAX_PACKET_HEADER_LEN;      /* Unknown at this point */
+               pos->packet_size = MAX_PACKET_HEADER_LEN;       /* Unknown at this point */
                pos->offset = 0;        /* Position of the packet header */
 
                /* read and check header, set stream id (and check) */
@@ -299,38 +301,45 @@ int create_stream_packet_index(struct trace_descriptor *td,
                }
                first_packet = 0;
 
-               /* Read packet context */
-               stream->packet_context->p.declaration->copy(NULL, NULL,
-                               pos, &ctf_format, &stream->packet_context->p);
-
-               /* read content size from header */
-               len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
-               if (len_index >= 0) {
-                       struct definition_integer *defint;
-                       struct field *field;
-
-                       field = struct_definition_get_field_from_index(stream->packet_context, len_index);
-                       assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
-                       defint = container_of(field->definition, struct definition_integer, p);
-                       assert(defint->declaration->signedness == FALSE);
-                       pos->content_size = defint->value._unsigned;
+               if (stream->packet_context) {
+                       /* Read packet context */
+                       stream->packet_context->p.declaration->copy(NULL, NULL,
+                                       pos, &ctf_format, &stream->packet_context->p);
+
+                       /* read content size from header */
+                       len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("content_size"));
+                       if (len_index >= 0) {
+                               struct definition_integer *defint;
+                               struct field *field;
+
+                               field = struct_definition_get_field_from_index(stream->packet_context, len_index);
+                               assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
+                               defint = container_of(field->definition, struct definition_integer, p);
+                               assert(defint->declaration->signedness == FALSE);
+                               pos->content_size = defint->value._unsigned;
+                       } else {
+                               /* Use file size for packet size */
+                               pos->content_size = filestats.st_size * CHAR_BIT;
+                       }
+
+                       /* read packet size from header */
+                       len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("packet_size"));
+                       if (len_index >= 0) {
+                               struct definition_integer *defint;
+                               struct field *field;
+
+                               field = struct_definition_get_field_from_index(stream->packet_context, len_index);
+                               assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
+                               defint = container_of(field->definition, struct definition_integer, p);
+                               assert(defint->declaration->signedness == FALSE);
+                               pos->packet_size = defint->value._unsigned;
+                       } else {
+                               /* Use content size if non-zero, else file size */
+                               pos->packet_size = pos->content_size ? : filestats.st_size * CHAR_BIT;
+                       }
                } else {
                        /* Use file size for packet size */
                        pos->content_size = filestats.st_size * CHAR_BIT;
-               }
-
-               /* read packet size from header */
-               len_index = struct_declaration_lookup_field_index(stream->packet_context->declaration, g_quark_from_static_string("packet_size"));
-               if (len_index >= 0) {
-                       struct definition_integer *defint;
-                       struct field *field;
-
-                       field = struct_definition_get_field_from_index(stream->packet_context, len_index);
-                       assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
-                       defint = container_of(field->definition, struct definition_integer, p);
-                       assert(defint->declaration->signedness == FALSE);
-                       pos->packet_size = defint->value._unsigned;
-               } else {
                        /* Use content size if non-zero, else file size */
                        pos->packet_size = pos->content_size ? : filestats.st_size * CHAR_BIT;
                }
@@ -392,14 +401,14 @@ int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags
        /* Open trace directory */
        td->ctf_trace.dir = opendir(path);
        if (!td->ctf_trace.dir) {
-               fprintf(stdout, "Unable to open trace directory.\n");
+               fprintf(stdout, "[error] Unable to open trace directory.\n");
                ret = -ENOENT;
                goto error;
        }
 
        td->ctf_trace.dirfd = open(path, 0);
        if (td->ctf_trace.dirfd < 0) {
-               fprintf(stdout, "Unable to open trace directory file descriptor.\n");
+               fprintf(stdout, "[error] Unable to open trace directory file descriptor.\n");
                ret = -ENOENT;
                goto error_dirfd;
        }
@@ -429,7 +438,7 @@ int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags
        for (;;) {
                ret = readdir_r(td->ctf_trace.dir, dirent, &diriter);
                if (ret) {
-                       fprintf(stdout, "Readdir error.\n");
+                       fprintf(stdout, "[error] Readdir error.\n");
                        goto readdir_error;
                }
                if (!diriter)
@@ -438,7 +447,11 @@ int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags
                                || !strcmp(diriter->d_name, "..")
                                || !strcmp(diriter->d_name, "metadata"))
                        continue;
-               /* TODO: open file stream */
+               ret = ctf_open_file_stream_read(td, diriter->d_name, flags);
+               if (ret) {
+                       fprintf(stdout, "[error] Open file stream error.\n");
+                       goto readdir_error;
+               }
        }
 
        free(dirent);
index db436ae30e211383cade053e8d9e1b3db9995609..b9340158995e6b35b857c477ba3edf38ce2f828a 100644 (file)
@@ -11,6 +11,7 @@ trace {
        major = 0;
        minor = 1;
        uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+       byte_order = be;
        packet.header := struct {
                uint32_t magic;
                uint8_t  trace_uuid[16];
index 1981832e4bb6a7372a32cc5073912ae9787a9f52..f54307118f2601029688326f231360eb7d017ea4 100644 (file)
@@ -1859,6 +1859,11 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
                fprintf(fd, "[error] %s: missing uuid field in trace declaration\n", __func__);
                goto error;
        }
+       if (!CTF_TRACE_FIELD_IS_SET(trace, byte_order)) {
+               ret = -EPERM;
+               fprintf(fd, "[error] %s: missing byte_order field in trace declaration\n", __func__);
+               goto error;
+       }
 
        parent_def_scope = NULL;
        if (trace->packet_header_decl) {
index 91c3303c2835b92529d773966b9a8cd0adbc52b7..8c98ff2c76a263155ffb0e77752bcf50fe2b2db6 100644 (file)
@@ -133,7 +133,7 @@ void init_pos(struct stream_pos *pos, int fd)
 static inline
 void move_pos(struct stream_pos *pos, size_t offset)
 {
-       if (pos->fd >= 0 && pos->offset + offset >= pos->content_size)
+       if (pos->fd >= 0 && (pos->offset + offset >= pos->content_size))
                move_pos_slow(pos, offset);
        else
                pos->offset += offset;
index cddc41a129e32bda61915df26c2b46367e5a8201..151bd65a1e1effd4082c17282efe26682b677d92 100644 (file)
@@ -48,6 +48,11 @@ struct format {
        void (*double_write)(struct stream_pos *pos,
                const struct declaration_float *float_declaration,
                double v);
+       long double (*ldouble_read)(struct stream_pos *pos,
+               const struct declaration_float *float_declaration);
+       void (*ldouble_write)(struct stream_pos *pos,
+               const struct declaration_float *float_declaration,
+               long double v);
 
        void (*string_copy)(struct stream_pos *dest, struct stream_pos *src,
                const struct declaration_string *string_declaration);
index 3b2523e24f5c6fee571c367852b04667a9f8d88a..9113bb8c1cfc3927ad0d845f9f5a174cfc359f28 100644 (file)
@@ -35,16 +35,12 @@ void float_copy(struct stream_pos *destp,
        struct definition_float *_float =
                container_of(definition, struct definition_float, p);
        struct declaration_float *float_declaration = _float->declaration;
+       long double v;
 
-       if (fsrc->float_copy == fdest->float_copy) {
-               fsrc->float_copy(destp, srcp, float_declaration);
-       } else {
-               double v;
-
-               v = fsrc->double_read(srcp, float_declaration);
-               if (fdest)
-                       fdest->double_write(destp, float_declaration, v);
-       }
+       v = fsrc->ldouble_read(srcp, float_declaration);
+       _float->value = v;
+       if (fdest)
+               fdest->ldouble_write(destp, float_declaration, v);
 }
 
 static
index 16cd903dc8aa8b7740859b0e7e30aae9bd4109a4..254dcbcb874c5d5b72ae57c6c44673d52f981697 100644 (file)
@@ -40,12 +40,14 @@ void integer_copy(struct stream_pos *dest, const struct format *fdest,
                uint64_t v;
 
                v = fsrc->uint_read(src, integer_declaration);
+               integer->value._unsigned = v;
                if (fdest)
                        fdest->uint_write(dest, integer_declaration, v);
        } else {
                int64_t v;
 
                v = fsrc->int_read(src, integer_declaration);
+               integer->value._signed = v;
                if (fdest)
                        fdest->int_write(dest, integer_declaration, v);
        }
index 796f05cd6a47f555c2584993d89956b9479adf02..6e5c6f472b41d115181e05c57962a3c9f8676476 100644 (file)
@@ -35,16 +35,11 @@ void string_copy(struct stream_pos *dest, const struct format *fdest,
                container_of(definition, struct definition_string, p);
        struct declaration_string *string_declaration = string->declaration;
 
-       if (fdest && (fsrc->string_copy == fdest->string_copy)) {
-               fsrc->string_copy(dest, src, string_declaration);
-       } else {
-               char *tmp = NULL;
-
-               fsrc->string_read(&tmp, src, string_declaration);
-               if (fdest)
-                       fdest->string_write(dest, tmp, string_declaration);
-               fsrc->string_free_temp(tmp);
-       }
+       g_free(string->value);
+       string->value = NULL;
+       fsrc->string_read(&string->value, src, string_declaration);
+       if (fdest)
+               fdest->string_write(dest, string->value, string_declaration);
 }
 
 static
This page took 0.041688 seconds and 4 git commands to generate.