assert-pre-internal.h: add BT_ASSERT_PRE_VALID_INDEX()
[babeltrace.git] / lib / ctf-ir / resolve.c
index 049ddda73c391065c859b538c9d733c943d3a8e8..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>
@@ -89,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 */
@@ -290,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;
                }
 
@@ -298,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;
        }
 
@@ -451,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: "
@@ -462,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);
        }
 
@@ -496,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;
        }
@@ -594,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--;
@@ -661,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) {
@@ -679,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;
                }
        }
@@ -732,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;
        }
 
@@ -743,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: "
@@ -752,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);
        }
 
@@ -914,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;
        }
@@ -966,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;
                }
@@ -977,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;
                }
@@ -1169,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) {
@@ -1194,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;
                        }
This page took 0.026283 seconds and 4 git commands to generate.