X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fmetadata%2Fctf-visitor-generate-io-struct.c;h=f4776a0a0dc70577cbfe85ffbd787f38b53239ed;hp=db97dbc01dfa29dbd71a349d0fe108cb066ca431;hb=ff00cad2a14ea6dad073761b3dbb4aaa259723d0;hpb=427c09b7f5d932748ee0eee050388c9873bcb6c3 diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index db97dbc0..f4776a0a 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -351,20 +351,29 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth, declaration = &array_declaration->p; break; } - case NODE_INTEGER: - case NODE_TYPE_SPECIFIER: + case NODE_TYPE_SPECIFIER_LIST: { struct declaration_sequence *sequence_declaration; struct declaration_integer *integer_declaration; - GQuark dummy_id; - declaration = ctf_type_declarator_visit(fd, depth, - length, - &dummy_id, NULL, - declaration_scope, - NULL, trace); - assert(declaration->id == CTF_TYPE_INTEGER); + declaration = ctf_type_specifier_list_visit(fd, depth, + length, declaration_scope, trace); + if (!declaration) { + fprintf(fd, "[error] %s: unable to find declaration type for sequence length\n", __func__); + return NULL; + } + if (declaration->id != CTF_TYPE_INTEGER) { + fprintf(fd, "[error] %s: length type for sequence is expected to be an integer (unsigned).\n", __func__); + declaration_unref(declaration); + return NULL; + } integer_declaration = container_of(declaration, struct declaration_integer, p); + if (integer_declaration->signedness != false) { + fprintf(fd, "[error] %s: length type for sequence should always be an unsigned integer.\n", __func__); + declaration_unref(declaration); + return NULL; + } + sequence_declaration = sequence_declaration_new(integer_declaration, nested_declaration, declaration_scope); declaration = &sequence_declaration->p; @@ -402,6 +411,10 @@ int ctf_struct_type_declarators_visit(FILE *fd, int depth, &field_name, iter, struct_declaration->scope, NULL, trace); + if (!field_declaration) { + fprintf(fd, "[error] %s: unable to find struct field declaration type\n", __func__); + return -EINVAL; + } struct_declaration_add_field(struct_declaration, g_quark_to_string(field_name), field_declaration); @@ -428,6 +441,10 @@ int ctf_variant_type_declarators_visit(FILE *fd, int depth, &field_name, iter, untagged_variant_declaration->scope, NULL, trace); + if (!field_declaration) { + fprintf(fd, "[error] %s: unable to find variant field declaration type\n", __func__); + return -EINVAL; + } untagged_variant_declaration_add_field(untagged_variant_declaration, g_quark_to_string(field_name), field_declaration); @@ -452,6 +469,19 @@ int ctf_typedef_visit(FILE *fd, int depth, struct declaration_scope *scope, type_specifier_list, &identifier, iter, scope, NULL, trace); + if (!type_declaration) { + fprintf(fd, "[error] %s: problem creating type declaration\n", __func__); + return -EINVAL; + } + /* + * Don't allow typedef and typealias of untagged + * variants. + */ + if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) { + fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__); + declaration_unref(type_declaration); + return -EPERM; + } ret = register_declaration(identifier, type_declaration, scope); if (ret) { type_declaration->declaration_free(type_declaration); @@ -492,6 +522,15 @@ int ctf_typealias_visit(FILE *fd, int depth, struct declaration_scope *scope, err = -EINVAL; goto error; } + /* + * Don't allow typedef and typealias of untagged + * variants. + */ + if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) { + fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__); + declaration_unref(type_declaration); + return -EPERM; + } /* * The semantic validator does not check whether the target is * abstract or not (if it has an identifier). Check it here. @@ -719,7 +758,7 @@ struct declaration *ctf_declaration_variant_visit(FILE *fd, return &variant_declaration->p; } error: - untagged_variant_declaration->p.declaration_free(&variant_declaration->p); + untagged_variant_declaration->p.declaration_free(&untagged_variant_declaration->p); return NULL; } @@ -845,24 +884,28 @@ struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth, } } if (!container_type) { - fprintf(fd, "[error] %s: missing container type for enumeration\n", __func__); + declaration = lookup_declaration(g_quark_from_static_string("int"), + declaration_scope); + if (!declaration) { + fprintf(fd, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__); return NULL; - - } - switch (container_type->type) { - case NODE_INTEGER: - case NODE_TYPE_SPECIFIER: + } + } else { declaration = ctf_type_declarator_visit(fd, depth, container_type, &dummy_id, NULL, declaration_scope, NULL, trace); - assert(declaration->id == CTF_TYPE_INTEGER); - integer_declaration = container_of(declaration, struct declaration_integer, p); - break; - default: - assert(0); } + if (!declaration) { + fprintf(fd, "[error] %s: unable to create container type for enumeration\n", __func__); + return NULL; + } + if (declaration->id != CTF_TYPE_INTEGER) { + fprintf(fd, "[error] %s: container type for enumeration is not integer\n", __func__); + return NULL; + } + integer_declaration = container_of(declaration, struct declaration_integer, p); enum_declaration = enum_declaration_new(integer_declaration); declaration_unref(&integer_declaration->p); /* leave ref to enum */ cds_list_for_each_entry(iter, enumerator_list, siblings) { @@ -1177,7 +1220,7 @@ struct declaration *ctf_type_specifier_list_visit(FILE *fd, &node->u.integer.expressions, trace); case TYPESPEC_STRING: return ctf_declaration_string_visit(fd, depth, - &first->u.string.expressions, trace); + &node->u.string.expressions, trace); case TYPESPEC_STRUCT: return ctf_declaration_struct_visit(fd, depth, node->u._struct.name, @@ -1522,7 +1565,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node, stream = g_new0(struct ctf_stream, 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_int_hash, g_int_equal); + stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal); 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) @@ -1639,17 +1682,6 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru return -EINVAL; } CTF_TRACE_SET_FIELD(trace, minor); - } else if (!strcmp(left, "word_size")) { - if (CTF_TRACE_FIELD_IS_SET(trace, word_size)) { - fprintf(fd, "[error] %s: word_size already declared in trace declaration\n", __func__); - return -EPERM; - } - ret = get_unary_unsigned(&node->u.ctf_expression.right, &trace->word_size); - if (ret) { - fprintf(fd, "[error] %s: unexpected unary expression for trace word_size\n", __func__); - return -EINVAL; - } - CTF_TRACE_SET_FIELD(trace, word_size); } else if (!strcmp(left, "uuid")) { if (CTF_TRACE_FIELD_IS_SET(trace, uuid)) { fprintf(fd, "[error] %s: uuid already declared in trace declaration\n", __func__); @@ -1703,11 +1735,6 @@ 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, word_size)) { - ret = -EPERM; - fprintf(fd, "[error] %s: missing word_size field in trace declaration\n", __func__); - goto error; - } return 0; error: @@ -1788,6 +1815,10 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, return ret; } } + if (!trace->streams) { + fprintf(fd, "[error] %s: missing trace declaration\n", __func__); + return -EINVAL; + } cds_list_for_each_entry(iter, &node->u.root.stream, siblings) { ret = ctf_stream_visit(fd, depth + 1, iter, trace->root_declaration_scope, trace);