X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=formats%2Fctf%2Fmetadata%2Fctf-visitor-generate-io-struct.c;h=29068563f7657d7786d4a74b8323f40e794e5a65;hb=81dee1bb528a95f7bf2bc622948807150794a75e;hp=9a5cda096f321509527492b24d0510dc613dda4b;hpb=b4c19c1e0a905f94146e6f319218fb16b7ebbca1;p=babeltrace.git diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 9a5cda09..29068563 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -325,7 +325,7 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth, */ integer_declaration = integer_declaration_new(integer_declaration->len, integer_declaration->byte_order, integer_declaration->signedness, - integer_declaration->p.alignment, 16); + integer_declaration->p.alignment, 16, integer_declaration->encoding); nested_declaration = &integer_declaration->p; } } @@ -1076,6 +1076,7 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, int signedness = 0; int has_alignment = 0, has_size = 0; int base = 0; + enum ctf_string_encoding encoding = CTF_STRING_NONE; struct declaration_integer *integer_declaration; cds_list_for_each_entry(expression, expressions, siblings) { @@ -1164,6 +1165,34 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, __func__); return NULL; } + } else if (!strcmp(left->u.unary_expression.u.string, "encoding")) { + char *s_right; + + if (right->u.unary_expression.type != UNARY_STRING) { + fprintf(fd, "[error] %s: encoding: expecting unary string\n", + __func__); + return NULL; + } + s_right = concatenate_unary_strings(&expression->u.ctf_expression.right); + if (!s_right) { + fprintf(fd, "[error] %s: unexpected unary expression for integer base\n", __func__); + g_free(s_right); + return NULL; + } + if (!strcmp(s_right, "UTF8") + || !strcmp(s_right, "utf8") + || !strcmp(s_right, "utf-8") + || !strcmp(s_right, "UTF-8")) + encoding = CTF_STRING_UTF8; + else if (!strcmp(s_right, "ASCII") + || !strcmp(s_right, "ascii")) + encoding = CTF_STRING_ASCII; + else { + fprintf(fd, "[error] %s: unknown string encoding \"%s\"\n", __func__, s_right); + g_free(s_right); + return NULL; + } + g_free(s_right); } else { fprintf(fd, "[error] %s: unknown attribute name %s\n", __func__, left->u.unary_expression.u.string); @@ -1184,7 +1213,8 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, } } integer_declaration = integer_declaration_new(size, - byte_order, signedness, alignment, base); + byte_order, signedness, alignment, + base, encoding); return &integer_declaration->p; } @@ -1888,7 +1918,8 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru CTF_TRACE_SET_FIELD(trace, minor); } else if (!strcmp(left, "uuid")) { uuid_t uuid; - ret = get_unary_uuid(&node->u.ctf_expression.right, &trace->uuid); + + ret = get_unary_uuid(&node->u.ctf_expression.right, &uuid); if (ret) { fprintf(fd, "[error] %s: unexpected unary expression for trace uuid\n", __func__); ret = -EINVAL; @@ -1899,22 +1930,27 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru fprintf(fd, "[error] %s: uuid mismatch\n", __func__); ret = -EPERM; goto error; + } else { + memcpy(trace->uuid, uuid, sizeof(uuid)); } CTF_TRACE_SET_FIELD(trace, uuid); } else if (!strcmp(left, "byte_order")) { struct ctf_node *right; int byte_order; - if (CTF_TRACE_FIELD_IS_SET(trace, byte_order)) { - fprintf(fd, "[error] %s: endianness already declared in trace declaration\n", __func__); - ret = -EPERM; - goto error; - } right = _cds_list_first_entry(&node->u.ctf_expression.right, struct ctf_node, siblings); byte_order = get_trace_byte_order(fd, depth, right); if (byte_order < 0) return -EINVAL; - trace->byte_order = byte_order; + + if (CTF_TRACE_FIELD_IS_SET(trace, byte_order) + && byte_order != trace->byte_order) { + fprintf(fd, "[error] %s: endianness mismatch\n", __func__); + ret = -EPERM; + goto error; + } else { + trace->byte_order = byte_order; + } CTF_TRACE_SET_FIELD(trace, byte_order); } else if (!strcmp(left, "packet.header")) { struct declaration *declaration; @@ -2081,7 +2117,6 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, printf_verbose("CTF visitor: metadata construction... "); trace->root_declaration_scope = new_declaration_scope(NULL); - trace->streams = g_ptr_array_new(); trace->byte_order = byte_order; switch (node->type) { @@ -2091,26 +2126,27 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, ret = ctf_root_declaration_visit(fd, depth + 1, iter, trace); if (ret) { fprintf(fd, "[error] %s: root declaration error\n", __func__); - return ret; + goto error; } } cds_list_for_each_entry(iter, &node->u.root.trace, siblings) { ret = ctf_trace_visit(fd, depth + 1, iter, trace); if (ret) { fprintf(fd, "[error] %s: trace declaration error\n", __func__); - return ret; + goto error; } } if (!trace->streams) { fprintf(fd, "[error] %s: missing trace declaration\n", __func__); - return -EINVAL; + ret = -EINVAL; + goto error; } cds_list_for_each_entry(iter, &node->u.root.stream, siblings) { ret = ctf_stream_visit(fd, depth + 1, iter, trace->root_declaration_scope, trace); if (ret) { fprintf(fd, "[error] %s: stream declaration error\n", __func__); - return ret; + goto error; } } cds_list_for_each_entry(iter, &node->u.root.event, siblings) { @@ -2118,7 +2154,7 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, trace->root_declaration_scope, trace); if (ret) { fprintf(fd, "[error] %s: event declaration error\n", __func__); - return ret; + goto error; } } break; @@ -2126,8 +2162,13 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, default: fprintf(fd, "[error] %s: unknown node type %d\n", __func__, (int) node->type); - return -EINVAL; + ret = -EINVAL; + goto error; } printf_verbose("done.\n"); return ret; + +error: + free_declaration_scope(trace->root_declaration_scope); + return ret; }