/*
- * resolve.c
- *
- * Babeltrace - CTF writer: Type resolving internal
+ * SPDX-License-Identifier: MIT
*
* Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
* Copyright 2016 Philippe Proulx <pproulx@efficios.com>
*
- * Authors: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- * Philippe Proulx <pproulx@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:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Babeltrace - CTF writer: Type resolving internal
*/
#define BT_LOG_TAG "CTF-WRITER/RESOLVE"
#include <babeltrace2-ctf-writer/field-types.h>
#include <babeltrace2-ctf-writer/object.h>
#include <babeltrace2-ctf-writer/stream-class.h>
-#include <babeltrace2/types.h>
#include "common/macros.h"
#include "common/assert.h"
static
struct type_stack_frame *type_stack_peek(type_stack *stack)
{
- struct type_stack_frame *entry = NULL;
+ BT_ASSERT(stack);
+ BT_ASSERT(!type_stack_empty(stack));
- if (!stack || type_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);
}
/*
* Return value is owned by `stack`.
*/
static
-struct type_stack_frame *type_stack_at(type_stack *stack,
- size_t index)
+struct type_stack_frame *type_stack_at(type_stack *stack, size_t index)
{
- struct type_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);
}
/*
struct bt_ctf_field_type_common *get_type_from_ctx(struct resolve_context *ctx,
enum bt_ctf_scope scope)
{
- BT_ASSERT(scope >= BT_CTF_SCOPE_TRACE_PACKET_HEADER &&
+ BT_ASSERT_DBG(scope >= BT_CTF_SCOPE_TRACE_PACKET_HEADER &&
scope <= BT_CTF_SCOPE_EVENT_FIELDS);
return ctx->scopes[scope - BT_CTF_SCOPE_TRACE_PACKET_HEADER];
* Destroys a path token.
*/
static
-void ptokens_destroy_func(gpointer ptoken, gpointer data)
+void ptokens_destroy_func(gpointer ptoken,
+ gpointer data __attribute__((unused)))
{
g_string_free(ptoken, TRUE);
}
}
for (i = 0; i < tail_field_path_len; i++) {
- int index = g_array_index(
+ int index = bt_g_array_index(
tail_field_path->indexes,
int, i);
GString *field_path_pretty =
bt_ctf_field_path_string(field_path);
const char *field_path_pretty_str =
- field_path_pretty ? field_path_pretty->str : NULL;
+ field_path_pretty ? field_path_pretty->str : "(null)";
BT_LOGT("Found field path: path=\"%s\", field-path=\"%s\"",
pathstr, field_path_pretty_str);
for (i = 0; i < field_path->indexes->len; i++) {
struct bt_ctf_field_type_common *child_type;
int child_index =
- g_array_index(field_path->indexes, int, i);
+ bt_g_array_index(field_path->indexes, int, i);
/* Get child field type */
child_type = bt_ctf_field_type_common_borrow_field_at_index(type,
GString *field_path2_pretty =
bt_ctf_field_path_string(field_path2);
const char *field_path1_pretty_str =
- field_path1_pretty ? field_path1_pretty->str : NULL;
+ field_path1_pretty ? field_path1_pretty->str : "(null)";
const char *field_path2_pretty_str =
- field_path2_pretty ? field_path2_pretty->str : NULL;
+ field_path2_pretty ? field_path2_pretty->str : "(null)";
BT_LOGT("Finding lowest common ancestor (LCA) between two field paths: "
"field-path-1=\"%s\", field-path-2=\"%s\"",
/*
* Start from both roots and find the first mismatch.
*/
- BT_ASSERT(field_path1->root == field_path2->root);
+ BT_ASSERT_DBG(field_path1->root == field_path2->root);
field_path1_len = field_path1->indexes->len;
field_path2_len = field_path2->indexes->len;
break;
}
- target_index = g_array_index(field_path1->indexes, int,
+ target_index = bt_g_array_index(field_path1->indexes, int,
lca_index);
- ctx_index = g_array_index(field_path2->indexes, int,
+ ctx_index = bt_g_array_index(field_path2->indexes, int,
lca_index);
if (target_index != ctx_index) {
* Make sure the target field path is located before the
* context field path.
*/
- target_index = g_array_index(target_field_path->indexes,
+ target_index = bt_g_array_index(target_field_path->indexes,
int, lca_index);
- ctx_index = g_array_index(ctx_field_path->indexes,
+ ctx_index = bt_g_array_index(ctx_field_path->indexes,
int, lca_index);
if (target_index >= ctx_index) {
}
break;
default:
- abort();
+ bt_common_abort();
}
end:
bt_ctf_field_type_common_variant_get_tag_name(type);
break;
default:
- abort();
+ bt_common_abort();
}
if (!pathstr) {
ret = bt_ctf_field_type_common_variant_set_tag_field_path(
type, target_field_path);
if (ret) {
- BT_LOGW("Cannot set varaint field type's tag field path: "
+ BT_LOGW("Cannot set variant field type's tag field path: "
"ret=%d, ft-addr=%p, path=\"%s\", target-field-path=\"%s\"",
ret, type, pathstr,
target_field_path_pretty_str);
ret = bt_ctf_field_type_common_variant_set_tag_field_type(
type, target_type);
if (ret) {
- BT_LOGW("Cannot set varaint field type's tag field type: "
+ BT_LOGW("Cannot set variant field type's tag field type: "
"ret=%d, ft-addr=%p, path=\"%s\", target-field-path=\"%s\"",
ret, type, pathstr,
target_field_path_pretty_str);
}
break;
default:
- abort();
+ bt_common_abort();
}
end:
{
int ret;
- BT_ASSERT(type_stack_size(ctx->type_stack) == 0);
+ BT_ASSERT_DBG(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_CTF_SCOPE_UNKNOWN;
return ret;
}
-BT_HIDDEN
int bt_ctf_resolve_types(
struct bt_ctf_private_value *environment,
struct bt_ctf_field_type_common *packet_header_type,