Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-resolve.c
index 184805d9eb5c5d491fd63aae6a5f526d5d7238fd..1fd9d399ac71112d902f532820b94ad435fed200 100644 (file)
@@ -1,28 +1,21 @@
 /*
- * Copyright 2016-2018 - Philippe Proulx <pproulx@efficios.com>
- * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * SPDX-License-Identifier: MIT
  *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  */
 
 #define BT_COMP_LOG_SELF_COMP (ctx->self_comp)
 #define BT_LOG_OUTPUT_LEVEL (ctx->log_level)
 #define BT_LOG_TAG "PLUGIN/CTF/META/RESOLVE"
-#include "plugins/comp-logging.h"
+#include "logging/comp-logging.h"
 
 #include <babeltrace2/babeltrace.h>
 #include "common/macros.h"
 #include "common/assert.h"
 #include "common/common.h"
 #include <glib.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <string.h>
 #include <inttypes.h>
@@ -181,15 +174,10 @@ size_t field_class_stack_size(field_class_stack *stack)
 static
 struct field_class_stack_frame *field_class_stack_peek(field_class_stack *stack)
 {
-       struct field_class_stack_frame *entry = NULL;
+       BT_ASSERT(stack);
+       BT_ASSERT(!field_class_stack_empty(stack));
 
-       if (!stack || field_class_stack_empty(stack)) {
-               goto end;
-       }
-
-       entry = g_ptr_array_index(stack, stack->len - 1);
-end:
-       return entry;
+       return g_ptr_array_index(stack, stack->len - 1);
 }
 
 /*
@@ -199,16 +187,10 @@ static
 struct field_class_stack_frame *field_class_stack_at(field_class_stack *stack,
                size_t index)
 {
-       struct field_class_stack_frame *entry = NULL;
+       BT_ASSERT(stack);
+       BT_ASSERT(index < stack->len);
 
-       if (!stack || index >= stack->len) {
-               goto end;
-       }
-
-       entry = g_ptr_array_index(stack, index);
-
-end:
-       return entry;
+       return g_ptr_array_index(stack, index);
 }
 
 /*
@@ -250,7 +232,7 @@ struct ctf_field_class *borrow_class_from_ctx(struct resolve_context *ctx,
        case CTF_SCOPE_EVENT_PAYLOAD:
                return ctx->scopes.event_payload;
        default:
-               abort();
+               bt_common_abort();
        }
 
        return NULL;
@@ -265,14 +247,14 @@ enum ctf_scope get_root_scope_from_absolute_pathstr(const char *pathstr,
                struct resolve_context *ctx)
 {
        enum ctf_scope scope;
-       enum ctf_scope ret = -1;
+       enum ctf_scope ret = CTF_SCOPE_PACKET_UNKNOWN;
        const size_t prefixes_count = sizeof(absolute_path_prefixes) /
                sizeof(*absolute_path_prefixes);
 
        for (scope = CTF_SCOPE_PACKET_HEADER; scope < CTF_SCOPE_PACKET_HEADER +
                        prefixes_count; scope++) {
                /*
-                * Chech if path string starts with a known absolute
+                * Check if path string starts with a known absolute
                 * path prefix.
                 *
                 * Refer to CTF 7.3.2 STATIC AND DYNAMIC SCOPES.
@@ -379,8 +361,8 @@ error:
 /*
  * Converts a path token list to a field path object. The path token
  * list is relative from `fc`. The index of the source looking for its
- * target within `fc` is indicated by `src_index`. This can be `INT64_MAX`
- * if the source is contained in `fc`.
+ * target within `fc` is indicated by `src_index`. This can be
+ * `INT64_MAX` if the source is contained in `fc`.
  *
  * `field_path` is an output parameter owned by the caller that must be
  * filled here.
@@ -408,7 +390,7 @@ int ptokens_to_field_path(GList *ptokens, struct ctf_field_path *field_path,
                        child_index = -1;
                } else {
                        child_index =
-                               ctf_field_class_compound_get_field_class_index_from_name(
+                               ctf_field_class_compound_get_field_class_index_from_orig_name(
                                        fc, ft_name);
                        if (child_index < 0) {
                                /*
@@ -530,7 +512,7 @@ int absolute_ptokens_to_field_path(GList *ptokens,
                break;
 
        default:
-               abort();
+               bt_common_abort();
        }
 
        /* Skip absolute path tokens */
@@ -661,7 +643,7 @@ int pathstr_to_field_path(const char *pathstr,
        /* Absolute or relative path? */
        root_scope = get_root_scope_from_absolute_pathstr(pathstr, ctx);
 
-       if (root_scope == -1) {
+       if (root_scope == CTF_SCOPE_PACKET_UNKNOWN) {
                /* Relative path: start with current root scope */
                field_path->root = ctx->root_scope;
                BT_COMP_LOGD("Detected relative path: starting with current root scope: "
@@ -688,7 +670,7 @@ int pathstr_to_field_path(const char *pathstr,
                }
        }
 
-       if (BT_LOG_ON_VERBOSE && ret == 0) {
+       if (BT_LOG_ON_TRACE && ret == 0) {
                GString *field_path_pretty = ctf_field_path_string(field_path);
                const char *field_path_pretty_str =
                        field_path_pretty ? field_path_pretty->str : NULL;
@@ -770,6 +752,7 @@ void get_ctx_stack_field_path(struct resolve_context *ctx,
  * Returns the index of the lowest common ancestor of two field path
  * objects having the same root scope.
  */
+static
 int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1,
                struct ctf_field_path *field_path2,
                struct resolve_context *ctx)
@@ -777,7 +760,7 @@ int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1,
        int64_t lca_index = 0;
        uint64_t field_path1_len, field_path2_len;
 
-       if (BT_LOG_ON_VERBOSE) {
+       if (BT_LOG_ON_TRACE) {
                GString *field_path1_pretty =
                        ctf_field_path_string(field_path1);
                GString *field_path2_pretty =
@@ -953,7 +936,7 @@ int validate_target_field_path(struct ctf_field_path *target_field_path,
                break;
        }
        default:
-               abort();
+               bt_common_abort();
        }
 
 end:
@@ -992,7 +975,7 @@ int resolve_sequence_or_variant_field_class(struct ctf_field_class *fc,
                break;
        }
        default:
-               abort();
+               bt_common_abort();
        }
 
        if (!pathstr) {
@@ -1055,7 +1038,7 @@ int resolve_sequence_or_variant_field_class(struct ctf_field_class *fc,
                break;
        }
        default:
-               abort();
+               bt_common_abort();
        }
 
 end:
This page took 0.026684 seconds and 4 git commands to generate.