X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fctf%2Fcommon%2Fmetadata%2Fvisitor-generate-ir.c;h=cf7b4611e3e81ac80bfffd82dcbe8aa2736dde65;hb=dd031dcc44f3552751136b9863fbf808827f3749;hp=af63595c5cc520a03b2158bcfee1e9b2af389544;hpb=e31e3b2abf9daf5f5cc13c54cf5d744ec2e05df9;p=babeltrace.git diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index af63595c..cf7b4611 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -592,8 +592,8 @@ struct ctx *ctx_create(struct bt_ctf_trace *trace, goto error; } - ctx->stream_classes = g_hash_table_new_full(g_direct_hash, - g_direct_equal, NULL, (GDestroyNotify) bt_put); + ctx->stream_classes = g_hash_table_new_full(g_int64_hash, + g_int64_equal, g_free, (GDestroyNotify) bt_put); if (!ctx->stream_classes) { BT_LOGE_STR("Failed to allocate a GHashTable."); goto error; @@ -882,7 +882,6 @@ int get_unary_signed(struct bt_list_head *head, int64_t *value) int uexpr_type = node->u.unary_expression.type; int uexpr_link = node->u.unary_expression.link; int cond = node->type != NODE_UNARY_EXPRESSION || - (uexpr_type != UNARY_UNSIGNED_CONSTANT) || (uexpr_type != UNARY_UNSIGNED_CONSTANT && uexpr_type != UNARY_SIGNED_CONSTANT) || uexpr_link != UNARY_LINK_UNKNOWN || i != 0; @@ -891,7 +890,7 @@ int get_unary_signed(struct bt_list_head *head, int64_t *value) goto end; } - switch (node->u.unary_expression.type) { + switch (uexpr_type) { case UNARY_UNSIGNED_CONSTANT: *value = (int64_t) node->u.unary_expression.u.unsigned_constant; @@ -3622,6 +3621,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) if (!_IS_SET(&set, _EVENT_STREAM_ID_SET)) { GList *keys = NULL; + int64_t *new_stream_id; struct bt_ctf_stream_class *new_stream_class; size_t stream_class_count = g_hash_table_size(ctx->stream_classes) + @@ -3651,18 +3651,24 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) goto error; } - stream_id = 0; + new_stream_id = g_new0(int64_t, 1); + if (!new_stream_id) { + BT_LOGE_STR("Failed to allocate a int64_t."); + ret = -ENOMEM; + goto error; + } /* Move reference to visitor's context */ g_hash_table_insert(ctx->stream_classes, - (gpointer) stream_id, new_stream_class); + new_stream_id, new_stream_class); + new_stream_id = NULL; new_stream_class = NULL; break; case 1: /* Single stream class: get its ID */ if (g_hash_table_size(ctx->stream_classes) == 1) { keys = g_hash_table_get_keys(ctx->stream_classes); - stream_id = (int64_t) keys->data; + stream_id = *((int64_t *) keys->data); g_list_free(keys); } else { assert(bt_ctf_trace_get_stream_class_count( @@ -3687,8 +3693,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) assert(stream_id >= 0); /* We have the stream ID now; get the stream class if found */ - stream_class = g_hash_table_lookup(ctx->stream_classes, - (gpointer) stream_id); + stream_class = g_hash_table_lookup(ctx->stream_classes, &stream_id); bt_get(stream_class); if (!stream_class) { stream_class = bt_ctf_trace_get_stream_class_by_id(ctx->trace, @@ -3966,8 +3971,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - ptr = g_hash_table_lookup(ctx->stream_classes, - (gpointer) id); + ptr = g_hash_table_lookup(ctx->stream_classes, &id); if (ptr) { _BT_LOGE_NODE(node, "Duplicate stream class (same ID): id=%" PRId64, @@ -4129,6 +4133,7 @@ static int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) { int64_t id; + int64_t *new_id; int set = 0; int ret = 0; struct ctf_node *iter; @@ -4229,7 +4234,7 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) */ existing_stream_class = bt_ctf_trace_get_stream_class_by_id(ctx->trace, id); - if (g_hash_table_lookup(ctx->stream_classes, (gpointer) id) || + if (g_hash_table_lookup(ctx->stream_classes, &id) || existing_stream_class) { _BT_LOGE_NODE(node, "Duplicate stream class (same ID): id=%" PRId64, @@ -4238,8 +4243,16 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node) goto error; } + new_id = g_new0(int64_t, 1); + if (!new_id) { + BT_LOGE_STR("Failed to allocate a int64_t."); + ret = -ENOMEM; + goto error; + } + *new_id = id; + /* Move reference to visitor's context */ - g_hash_table_insert(ctx->stream_classes, (gpointer) (int64_t) id, + g_hash_table_insert(ctx->stream_classes, new_id, stream_class); stream_class = NULL; goto end; @@ -4833,7 +4846,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, _SET(set, _CLOCK_PRECISION_SET); } else if (!strcmp(left, "offset_s")) { - uint64_t offset_s; + int64_t offset_s; if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) { _BT_LOGE_DUP_ATTR(entry_node, "offset_s", @@ -4842,7 +4855,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = get_unary_unsigned( + ret = get_unary_signed( &entry_node->u.ctf_expression.right, &offset_s); if (ret) { _BT_LOGE_NODE(entry_node, @@ -4860,7 +4873,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, _SET(set, _CLOCK_OFFSET_S_SET); } else if (!strcmp(left, "offset")) { - uint64_t offset; + int64_t offset; if (_IS_SET(set, _CLOCK_OFFSET_SET)) { _BT_LOGE_DUP_ATTR(entry_node, "offset", "clock class"); @@ -4868,7 +4881,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, goto error; } - ret = get_unary_unsigned( + ret = get_unary_signed( &entry_node->u.ctf_expression.right, &offset); if (ret) { _BT_LOGE_NODE(entry_node,