X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fmetadata%2Fctf-visitor-generate-io-struct.c;h=37d17f5839e2ebb4047a4f338e6634be44c9b2e8;hp=1eb763de79b1f407a9e4b268c9e1012a04386990;hb=53532829c4c9a9c22eccc72cd84bf5b0b57b33e0;hpb=8c572eba034b95716a4bbd019dfbe0827605ba90 diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 1eb763de..37d17f58 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,10 @@ struct declaration *ctf_type_specifier_list_visit(FILE *fd, struct declaration_scope *declaration_scope, struct ctf_trace *trace); +static +int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node, + struct declaration_scope *parent_declaration_scope, struct ctf_trace *trace); + /* * String returned must be freed by the caller using g_free. */ @@ -120,7 +125,7 @@ int get_unary_uuid(struct cds_list_head *head, uuid_t *uuid) } static -struct ctf_stream *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id) +struct ctf_stream_class *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id) { if (trace->streams->len <= stream_id) return NULL; @@ -1083,6 +1088,12 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, return NULL; } alignment = right->u.unary_expression.u.unsigned_constant; + /* Make sure alignment is a power of two */ + if (alignment == 0 || (alignment & (alignment - 1)) != 0) { + fprintf(fd, "[error] %s: align: expecting power of two\n", + __func__); + return NULL; + } has_alignment = 1; } else { fprintf(fd, "[error] %s: unknown attribute name %s\n", @@ -1151,6 +1162,12 @@ struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth, return NULL; } alignment = right->u.unary_expression.u.unsigned_constant; + /* Make sure alignment is a power of two */ + if (alignment == 0 || (alignment & (alignment - 1)) != 0) { + fprintf(fd, "[error] %s: align: expecting power of two\n", + __func__); + return NULL; + } has_alignment = 1; } else { fprintf(fd, "[error] %s: unknown attribute name %s\n", @@ -1444,10 +1461,17 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node, } if (!CTF_EVENT_FIELD_IS_SET(event, stream_id)) { /* Allow missing stream_id if there is only a single stream */ - if (trace->streams->len == 1) { + switch (trace->streams->len) { + case 0: /* Create stream if there was none. */ + ret = ctf_stream_visit(fd, depth, NULL, trace->root_declaration_scope, trace); + if (ret) + goto error; + /* Fall-through */ + case 1: event->stream_id = 0; event->stream = trace_stream_lookup(trace, event->stream_id); - } else { + break; + default: ret = -EPERM; fprintf(fd, "[error] %s: missing stream_id field in event declaration\n", __func__); goto error; @@ -1503,7 +1527,7 @@ error: static -int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream *stream, struct ctf_trace *trace) +int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream_class *stream, struct ctf_trace *trace) { int ret = 0; @@ -1625,18 +1649,20 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node, { int ret = 0; struct ctf_node *iter; - struct ctf_stream *stream; + struct ctf_stream_class *stream; struct definition_scope *parent_def_scope; - stream = g_new0(struct ctf_stream, 1); + stream = g_new0(struct ctf_stream_class, 1); stream->declaration_scope = new_declaration_scope(parent_declaration_scope); stream->events_by_id = g_ptr_array_new(); stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal); stream->files = g_ptr_array_new(); - cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) { - ret = ctf_stream_declaration_visit(fd, depth + 1, iter, stream, trace); - if (ret) - goto error; + if (node) { + cds_list_for_each_entry(iter, &node->u.stream.declaration_list, siblings) { + ret = ctf_stream_declaration_visit(fd, depth + 1, iter, stream, trace); + if (ret) + goto error; + } } if (CTF_STREAM_FIELD_IS_SET(stream, stream_id)) { /* check that packet header has stream_id field. */ @@ -1950,7 +1976,7 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, int ret = 0; struct ctf_node *iter; - fprintf(fd, "CTF visitor: metadata construction... "); + printf_verbose("CTF visitor: metadata construction... "); trace->root_declaration_scope = new_declaration_scope(NULL); trace->byte_order = byte_order; @@ -1998,6 +2024,6 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, (int) node->type); return -EINVAL; } - fprintf(fd, "done.\n"); + printf_verbose("done.\n"); return ret; }