assert-pre-internal.h: add BT_ASSERT_PRE_VALID_INDEX()
[babeltrace.git] / lib / ctf-ir / resolve.c
index 2a6ba2b2f7b39b8ddc69425e11a8a933517c8d28..c4bf310d0369bf05309fdc60cc60bbbfee5ab40f 100644 (file)
 #define BT_LOG_TAG "RESOLVE"
 #include <babeltrace/lib-logging-internal.h>
 
-#include <babeltrace/ctf-ir/event.h>
 #include <babeltrace/ctf-ir/stream-class.h>
 #include <babeltrace/ctf-ir/resolve-internal.h>
 #include <babeltrace/ctf-ir/field-types.h>
 #include <babeltrace/ctf-ir/field-path.h>
 #include <babeltrace/ctf-ir/field-path-internal.h>
-#include <babeltrace/ctf-ir/event-internal.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/values.h>
 #include <babeltrace/types.h>
+#include <babeltrace/assert-internal.h>
 #include <limits.h>
 #include <inttypes.h>
 #include <stdlib.h>
@@ -88,13 +87,13 @@ struct resolve_context {
 
 /* TSDL dynamic scope prefixes as defined in CTF Section 7.3.2 */
 static const char * const absolute_path_prefixes[] = {
-       [BT_SCOPE_ENV]                  = "env.",
-       [BT_SCOPE_TRACE_PACKET_HEADER]  = "trace.packet.header.",
+       [BT_SCOPE_ENV]                          = "env.",
+       [BT_SCOPE_TRACE_PACKET_HEADER]          = "trace.packet.header.",
        [BT_SCOPE_STREAM_PACKET_CONTEXT]        = "stream.packet.context.",
-       [BT_SCOPE_STREAM_EVENT_HEADER]  = "stream.event.header.",
-       [BT_SCOPE_STREAM_EVENT_CONTEXT] = "stream.event.context.",
+       [BT_SCOPE_STREAM_EVENT_HEADER]          = "stream.event.header.",
+       [BT_SCOPE_STREAM_EVENT_CONTEXT]         = "stream.event.context.",
        [BT_SCOPE_EVENT_CONTEXT]                = "event.context.",
-       [BT_SCOPE_EVENT_FIELDS]         = "event.fields.",
+       [BT_SCOPE_EVENT_FIELDS]                 = "event.fields.",
 };
 
 /* Number of path tokens used for the absolute prefixes */
@@ -257,7 +256,7 @@ static
 struct bt_field_type *get_type_from_ctx(struct resolve_context *ctx,
                enum bt_scope scope)
 {
-       assert(scope >= BT_SCOPE_TRACE_PACKET_HEADER &&
+       BT_ASSERT(scope >= BT_SCOPE_TRACE_PACKET_HEADER &&
                scope <= BT_SCOPE_EVENT_FIELDS);
 
        return ctx->scopes[scope - BT_SCOPE_TRACE_PACKET_HEADER];
@@ -289,7 +288,7 @@ enum bt_scope get_root_scope_from_absolute_pathstr(const char *pathstr)
                        BT_LOGV("Prefix does not match: trying the next one: "
                                "path=\"%s\", path-prefix=\"%s\", scope=%s",
                                pathstr, absolute_path_prefixes[scope],
-                               bt_scope_string(scope));
+                               bt_common_scope_string(scope));
                        continue;
                }
 
@@ -297,7 +296,7 @@ enum bt_scope get_root_scope_from_absolute_pathstr(const char *pathstr)
                ret = scope;
                BT_LOGV("Found root scope from absolute path: "
                        "path=\"%s\", scope=%s", pathstr,
-                       bt_scope_string(scope));
+                       bt_common_scope_string(scope));
                goto end;
        }
 
@@ -450,7 +449,7 @@ int ptokens_to_field_path(GList *ptokens, struct bt_field_path *field_path,
                g_array_append_val(field_path->indexes, child_index);
 
                /* Get child field type */
-               child_type = bt_field_type_get_field_at_index(type,
+               child_type = bt_field_type_borrow_field_at_index(type,
                        child_index);
                if (!child_type) {
                        BT_LOGW("Cannot get child field type: "
@@ -461,6 +460,7 @@ int ptokens_to_field_path(GList *ptokens, struct bt_field_path *field_path,
                }
 
                /* Move child type to current type */
+               bt_get(child_type);
                BT_MOVE(type, child_type);
        }
 
@@ -495,7 +495,7 @@ int absolute_ptokens_to_field_path(GList *ptokens,
                /* Error: root type is not available */
                BT_LOGW("Root field type is not available: "
                        "root-scope=%s",
-                       bt_scope_string(field_path->root));
+                       bt_common_scope_string(field_path->root));
                ret = -1;
                goto end;
        }
@@ -593,7 +593,7 @@ int relative_ptokens_to_field_path(GList *ptokens,
                        bt_field_path_clear(field_path);
 
                        BT_LOGV("Looking into potential root scope: scope=%s",
-                               bt_scope_string(field_path->root));
+                               bt_common_scope_string(field_path->root));
                        root_type = get_type_from_ctx(ctx, field_path->root);
                        if (!root_type) {
                                field_path->root--;
@@ -660,13 +660,13 @@ struct bt_field_path *pathstr_to_field_path(const char *pathstr,
                /* Relative path: start with current root scope */
                field_path->root = ctx->root_scope;
                BT_LOGV("Detected relative path: starting with current root scope: "
-                       "scope=%s", bt_scope_string(field_path->root));
+                       "scope=%s", bt_common_scope_string(field_path->root));
                ret = relative_ptokens_to_field_path(ptokens, field_path, ctx);
                if (ret) {
                        BT_LOGW("Cannot get relative field path of path string: "
                                "path=\"%s\", start-scope=%s, end-scope=%s",
-                               pathstr, bt_scope_string(ctx->root_scope),
-                               bt_scope_string(field_path->root));
+                               pathstr, bt_common_scope_string(ctx->root_scope),
+                               bt_common_scope_string(field_path->root));
                        goto end;
                }
        } else if (root_scope == BT_SCOPE_ENV) {
@@ -678,12 +678,12 @@ struct bt_field_path *pathstr_to_field_path(const char *pathstr,
                /* Absolute path: use found root scope */
                field_path->root = root_scope;
                BT_LOGV("Detected absolute path: using root scope: "
-                       "scope=%s", bt_scope_string(field_path->root));
+                       "scope=%s", bt_common_scope_string(field_path->root));
                ret = absolute_ptokens_to_field_path(ptokens, field_path, ctx);
                if (ret) {
                        BT_LOGW("Cannot get absolute field path of path string: "
                                "path=\"%s\", root-scope=%s",
-                               pathstr, bt_scope_string(root_scope));
+                               pathstr, bt_common_scope_string(root_scope));
                        goto end;
                }
        }
@@ -731,7 +731,7 @@ struct bt_field_type *field_path_to_field_type(
        if (!type) {
                /* Error: root type is not available */
                BT_LOGW("Root field type is not available: root-scope=%s",
-                       bt_scope_string(field_path->root));
+                       bt_common_scope_string(field_path->root));
                goto error;
        }
 
@@ -742,7 +742,7 @@ struct bt_field_type *field_path_to_field_type(
                        g_array_index(field_path->indexes, int, i);
 
                /* Get child field type */
-               child_type = bt_field_type_get_field_at_index(type,
+               child_type = bt_field_type_borrow_field_at_index(type,
                        child_index);
                if (!child_type) {
                        BT_LOGW("Cannot get field type: "
@@ -751,6 +751,7 @@ struct bt_field_type *field_path_to_field_type(
                }
 
                /* Move child type to current type */
+               bt_get(child_type);
                BT_MOVE(type, child_type);
        }
 
@@ -833,7 +834,7 @@ int get_field_paths_lca_index(struct bt_field_path *field_path1,
        /*
         * Start from both roots and find the first mismatch.
         */
-       assert(field_path1->root == field_path2->root);
+       BT_ASSERT(field_path1->root == field_path2->root);
        field_path1_len = field_path1->indexes->len;
        field_path2_len = field_path2->indexes->len;
 
@@ -913,8 +914,8 @@ int validate_target_field_path(struct bt_field_path *target_field_path,
        if (target_field_path->root > ctx_field_path->root) {
                BT_LOGW("Target field type is located after source field type: "
                        "target-root=%s, source-root=%s",
-                       bt_scope_string(target_field_path->root),
-                       bt_scope_string(ctx_field_path->root));
+                       bt_common_scope_string(target_field_path->root),
+                       bt_common_scope_string(ctx_field_path->root));
                ret = -1;
                goto end;
        }
@@ -965,7 +966,7 @@ int validate_target_field_path(struct bt_field_path *target_field_path,
                        BT_LOGW("Variant field type's tag field type is not an enumeration field type: "
                                "tag-ft-addr=%p, tag-ft-id=%s",
                                target_type,
-                               bt_field_type_id_string(target_type_id));
+                               bt_common_field_type_id_string(target_type_id));
                        ret = -1;
                        goto end;
                }
@@ -976,7 +977,7 @@ int validate_target_field_path(struct bt_field_path *target_field_path,
                        BT_LOGW("Sequence field type's length field type is not an unsigned integer field type: "
                                "length-ft-addr=%p, length-ft-id=%s",
                                target_type,
-                               bt_field_type_id_string(target_type_id));
+                               bt_common_field_type_id_string(target_type_id));
                        ret = -1;
                        goto end;
                }
@@ -1168,7 +1169,7 @@ int resolve_type(struct bt_field_type *type, struct resolve_context *ctx)
 
                for (f_index = 0; f_index < field_count; f_index++) {
                        struct bt_field_type *child_type =
-                               bt_field_type_get_field_at_index(type,
+                               bt_field_type_borrow_field_at_index(type,
                                        f_index);
 
                        if (!child_type) {
@@ -1193,7 +1194,6 @@ int resolve_type(struct bt_field_type *type, struct resolve_context *ctx)
                                "index=%" PRId64 ", count=%" PRId64,
                                type, child_type, f_index, field_count);
                        ret = resolve_type(child_type, ctx);
-                       BT_PUT(child_type);
                        if (ret) {
                                goto end;
                        }
@@ -1218,7 +1218,7 @@ int resolve_root_type(enum bt_scope root_scope, struct resolve_context *ctx)
 {
        int ret;
 
-       assert(type_stack_size(ctx->type_stack) == 0);
+       BT_ASSERT(type_stack_size(ctx->type_stack) == 0);
        ctx->root_scope = root_scope;
        ret = resolve_type(get_type_from_ctx(ctx, root_scope), ctx);
        ctx->root_scope = BT_SCOPE_UNKNOWN;
This page took 0.027938 seconds and 4 git commands to generate.