lib: make trace IR API const-correct
[babeltrace.git] / plugins / ctf / common / metadata / visitor-generate-ir.c
index 4258781f52d12e7f6677437675f8b2628e2af226..d746b27e551dac3d38a769e6b73794cfdcbab22b 100644 (file)
@@ -554,7 +554,7 @@ void ctx_destroy(struct ctx *ctx)
                scope = parent_scope;
        }
 
-       bt_put(ctx->trace);
+       bt_object_put_ref(ctx->trace);
 
        if (ctx->ctf_tc) {
                ctf_trace_class_destroy(ctx->ctf_tc);
@@ -1349,7 +1349,7 @@ int visit_field_class_declarator(struct ctx *ctx,
                                goto error;
                        }
 
-                       if (nested_decl->id == CTF_FIELD_CLASS_ID_INT) {
+                       if (nested_decl->type == CTF_FIELD_CLASS_TYPE_INT) {
                                /* Pointer: force integer's base to 16 */
                                struct ctf_field_class_int *int_fc =
                                        (void *) nested_decl;
@@ -1684,7 +1684,7 @@ int visit_field_class_def(struct ctx *ctx, struct ctf_node *cls_specifier_list,
                }
 
                /* Do not allow field class def and alias of untagged variants */
-               if (class_decl->id == CTF_FIELD_CLASS_ID_VARIANT) {
+               if (class_decl->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
                        struct ctf_field_class_variant *var_fc =
                                (void *) class_decl;
 
@@ -1742,7 +1742,7 @@ int visit_field_class_alias(struct ctx *ctx, struct ctf_node *target,
        }
 
        /* Do not allow field class def and alias of untagged variants */
-       if (class_decl->id == CTF_FIELD_CLASS_ID_VARIANT) {
+       if (class_decl->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
                struct ctf_field_class_variant *var_fc = (void *) class_decl;
 
                if (var_fc->tag_path.path->len == 0) {
@@ -2266,9 +2266,9 @@ int visit_enum_decl(struct ctx *ctx, const char *name,
 
                BT_ASSERT(integer_decl);
 
-               if (integer_decl->base.base.id != CTF_FIELD_CLASS_ID_INT) {
+               if (integer_decl->base.base.type != CTF_FIELD_CLASS_TYPE_INT) {
                        BT_LOGE("Container field class for enumeration field class is not an integer field class: "
-                               "fc-id=%d", integer_decl->base.base.id);
+                               "fc-type=%d", integer_decl->base.base.type);
                        ret = -EINVAL;
                        goto error;
                }
@@ -2719,7 +2719,8 @@ int visit_integer_decl(struct ctx *ctx,
        (*integer_decl)->is_signed = (signedness > 0);
        (*integer_decl)->disp_base = base;
        (*integer_decl)->encoding = encoding;
-       (*integer_decl)->mapped_clock_class = bt_get(mapped_clock_class);
+       (*integer_decl)->mapped_clock_class = mapped_clock_class;
+       bt_object_get_ref((*integer_decl)->mapped_clock_class);
        return 0;
 
 error:
@@ -3585,8 +3586,8 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                goto end;
        }
 
-       if (fc->id != CTF_FIELD_CLASS_ID_INT &&
-                       fc->id != CTF_FIELD_CLASS_ID_ENUM) {
+       if (fc->type != CTF_FIELD_CLASS_TYPE_INT &&
+                       fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
                goto end;
        }
 
@@ -3606,22 +3607,22 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                 */
                clock_class_to_map_to = bt_clock_class_create();
                BT_ASSERT(clock_class_to_map_to);
-               ret = bt_clock_class_set_frequency(clock_class_to_map_to,
+               bt_clock_class_set_frequency(clock_class_to_map_to,
                        UINT64_C(1000000000));
-               BT_ASSERT(ret == 0);
                ret = bt_clock_class_set_name(clock_class_to_map_to,
                        "default");
                BT_ASSERT(ret == 0);
                g_ptr_array_add(ctx->ctf_tc->clock_classes,
-                       bt_get(clock_class_to_map_to));
+                       clock_class_to_map_to);
+               bt_object_get_ref(clock_class_to_map_to);
                break;
        case 1:
                /*
                 * Only one clock class exists in the trace at this point: use
                 * this one.
                 */
-               clock_class_to_map_to =
-                       bt_get(ctx->ctf_tc->clock_classes->pdata[0]);
+               clock_class_to_map_to = ctx->ctf_tc->clock_classes->pdata[0];
+               bt_object_get_ref(clock_class_to_map_to);
                break;
        default:
                /*
@@ -3635,10 +3636,11 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
        }
 
        BT_ASSERT(clock_class_to_map_to);
-       int_fc->mapped_clock_class = bt_get(clock_class_to_map_to);
+       int_fc->mapped_clock_class = clock_class_to_map_to;
+       bt_object_get_ref(int_fc->mapped_clock_class);
 
 end:
-       bt_put(clock_class_to_map_to);
+       bt_object_put_ref(clock_class_to_map_to);
        return ret;
 }
 
@@ -3655,12 +3657,12 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx,
                goto end;
        }
 
-       if (root_fc->id != CTF_FIELD_CLASS_ID_STRUCT &&
-                       root_fc->id != CTF_FIELD_CLASS_ID_VARIANT) {
+       if (root_fc->type != CTF_FIELD_CLASS_TYPE_STRUCT &&
+                       root_fc->type != CTF_FIELD_CLASS_TYPE_VARIANT) {
                goto end;
        }
 
-       if (root_fc->id == CTF_FIELD_CLASS_ID_STRUCT) {
+       if (root_fc->type == CTF_FIELD_CLASS_TYPE_STRUCT) {
                count = struct_fc->members->len;
        } else {
                count = var_fc->options->len;
@@ -3669,10 +3671,10 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx,
        for (i = 0; i < count; i++) {
                struct ctf_named_field_class *named_fc = NULL;
 
-               if (root_fc->id == CTF_FIELD_CLASS_ID_STRUCT) {
+               if (root_fc->type == CTF_FIELD_CLASS_TYPE_STRUCT) {
                        named_fc = ctf_field_class_struct_borrow_member_by_index(
                                struct_fc, i);
-               } else if (root_fc->id == CTF_FIELD_CLASS_ID_VARIANT) {
+               } else if (root_fc->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
                        named_fc = ctf_field_class_variant_borrow_option_by_index(
                                var_fc, i);
                }
@@ -3931,8 +3933,8 @@ int visit_stream_decl(struct ctx *ctx, struct ctf_node *node)
                        goto error;
                }
 
-               if (named_fc->fc->id != CTF_FIELD_CLASS_ID_INT &&
-                               named_fc->fc->id != CTF_FIELD_CLASS_ID_ENUM) {
+               if (named_fc->fc->type != CTF_FIELD_CLASS_TYPE_INT &&
+                               named_fc->fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
                        _BT_LOGE_NODE(node,
                                "Stream class has a `id` attribute, "
                                "but trace's packet header field class's `stream_id` field is not an integer field class.");
@@ -4433,13 +4435,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               ret = bt_clock_class_set_uuid(clock, uuid);
-               if (ret) {
-                       _BT_LOGE_NODE(entry_node,
-                               "Cannot set clock class's UUID.");
-                       goto error;
-               }
-
+               bt_clock_class_set_uuid(clock, uuid);
                _SET(set, _CLOCK_UUID_SET);
        } else if (!strcmp(left, "description")) {
                char *right;
@@ -4496,13 +4492,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               ret = bt_clock_class_set_frequency(clock, freq);
-               if (ret) {
-                       _BT_LOGE_NODE(entry_node,
-                               "Cannot set clock class's frequency.");
-                       goto error;
-               }
-
+               bt_clock_class_set_frequency(clock, freq);
                _SET(set, _CLOCK_FREQ_SET);
        } else if (!strcmp(left, "precision")) {
                uint64_t precision;
@@ -4523,13 +4513,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               ret = bt_clock_class_set_precision(clock, precision);
-               if (ret) {
-                       _BT_LOGE_NODE(entry_node,
-                               "Cannot set clock class's precision.");
-                       goto error;
-               }
-
+               bt_clock_class_set_precision(clock, precision);
                _SET(set, _CLOCK_PRECISION_SET);
        } else if (!strcmp(left, "offset_s")) {
                if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) {
@@ -4587,13 +4571,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                        goto error;
                }
 
-               ret = bt_clock_class_set_is_absolute(clock, ret);
-               if (ret) {
-                       _BT_LOGE_NODE(entry_node,
-                               "Cannot set clock class's absolute flag.");
-                       goto error;
-               }
-
+               bt_clock_class_set_is_absolute(clock, ret);
                _SET(set, _CLOCK_ABSOLUTE_SET);
        } else {
                _BT_LOGW_NODE(entry_node,
@@ -4638,9 +4616,9 @@ void calibrate_clock_class_offsets(int64_t *offset_seconds,
 }
 
 static
-void apply_clock_class_offset(struct ctx *ctx, struct bt_clock_class *clock)
+void apply_clock_class_offset(struct ctx *ctx,
+               struct bt_clock_class *clock)
 {
-       int ret;
        uint64_t freq;
        int64_t offset_s_to_apply = ctx->decoder_config.clock_class_offset_s;
        uint64_t offset_ns_to_apply;
@@ -4675,7 +4653,8 @@ void apply_clock_class_offset(struct ctx *ctx, struct bt_clock_class *clock)
        }
 
        freq = bt_clock_class_get_frequency(clock);
-       bt_clock_class_get_offset(clock, &cur_offset_s, &cur_offset_cycles);
+       bt_clock_class_get_offset(clock,
+                                 &cur_offset_s, &cur_offset_cycles);
 
        /* Apply offsets */
        cur_offset_s += offset_s_to_apply;
@@ -4688,8 +4667,7 @@ void apply_clock_class_offset(struct ctx *ctx, struct bt_clock_class *clock)
        calibrate_clock_class_offsets(&cur_offset_s, &cur_offset_cycles, freq);
 
        /* Set final offsets */
-       ret = bt_clock_class_set_offset(clock, cur_offset_s, cur_offset_cycles);
-       BT_ASSERT(ret == 0);
+       bt_clock_class_set_offset(clock, cur_offset_s, cur_offset_cycles);
 
 end:
        return;
@@ -4724,12 +4702,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
        }
 
        /* CTF: not absolute by default */
-       ret = bt_clock_class_set_is_absolute(clock, BT_FALSE);
-       if (ret) {
-               _BT_LOGE_NODE(clock_node,
-                       "Cannot set clock class's absolute flag.");
-               goto end;
-       }
+       bt_clock_class_set_is_absolute(clock, BT_FALSE);
 
        bt_list_for_each_entry(entry_node, decl_list, siblings) {
                ret = visit_clock_decl_entry(ctx, entry_node, clock, &set,
@@ -4758,12 +4731,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                 * it's a condition to be able to sort notifications
                 * from different sources.
                 */
-               ret = bt_clock_class_set_is_absolute(clock, BT_TRUE);
-               if (ret) {
-                       _BT_LOGE_NODE(clock_node,
-                               "Cannot set clock class's absolute flag.");
-                       goto end;
-               }
+               bt_clock_class_set_is_absolute(clock, BT_TRUE);
        }
 
        /*
@@ -4773,13 +4741,13 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
        freq = bt_clock_class_get_frequency(clock);
        calibrate_clock_class_offsets(&offset_seconds, &offset_cycles, freq);
        BT_ASSERT(offset_cycles < bt_clock_class_get_frequency(clock));
-       ret = bt_clock_class_set_offset(clock, offset_seconds, offset_cycles);
-       BT_ASSERT(ret == 0);
+       bt_clock_class_set_offset(clock, offset_seconds, offset_cycles);
        apply_clock_class_offset(ctx, clock);
-       g_ptr_array_add(ctx->ctf_tc->clock_classes, bt_get(clock));
+       g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);
+       bt_object_get_ref(clock);
 
 end:
-       BT_PUT(clock);
+       BT_OBJECT_PUT_REF_AND_RESET(clock);
        return ret;
 }
 
@@ -4934,7 +4902,8 @@ struct bt_trace *ctf_visitor_generate_ir_get_ir_trace(
 
        BT_ASSERT(ctx);
        BT_ASSERT(ctx->trace);
-       return bt_get(ctx->trace);
+       bt_object_get_ref(ctx->trace);
+       return ctx->trace;
 }
 
 BT_HIDDEN
This page took 0.051972 seconds and 4 git commands to generate.