#include <stdbool.h>
#include <stdlib.h>
#include <ctype.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
#include <glib.h>
#include <inttypes.h>
#include <errno.h>
+#include <babeltrace/common-internal.h>
#include <babeltrace/compat/uuid-internal.h>
#include <babeltrace/endian-internal.h>
#include <babeltrace/babeltrace.h>
-#include <babeltrace/ctf-ir/field-types-internal.h>
#include "scanner.h"
#include "parser.h"
{
GQuark qname = 0;
- assert(name);
+ BT_ASSERT(name);
/* Prefix character + original string + '\0' */
char *prname = g_new(char, strlen(name) + 2);
_BT_FIELD_TYPE_INIT(decl);
struct ctx_decl_scope *cur_scope = scope;
- assert(scope);
- assert(name);
+ BT_ASSERT(scope);
+ BT_ASSERT(name);
qname = get_prefixed_named_quark(prefix, name);
if (!qname) {
goto error;
GQuark qname = 0;
_BT_FIELD_TYPE_INIT(edecl);
- assert(scope);
- assert(name);
- assert(decl);
+ BT_ASSERT(scope);
+ BT_ASSERT(name);
+ BT_ASSERT(decl);
qname = get_prefixed_named_quark(prefix, name);
if (!qname) {
ret = -ENOMEM;
struct ctx *ctx = NULL;
struct ctx_decl_scope *scope = NULL;
- assert(decoder_config);
+ BT_ASSERT(decoder_config);
ctx = g_new0(struct ctx, 1);
if (!ctx) {
int ret = 0;
struct ctx_decl_scope *new_scope;
- assert(ctx);
+ BT_ASSERT(ctx);
new_scope = ctx_decl_scope_create(ctx->current_scope);
if (!new_scope) {
BT_LOGE_STR("Cannot create declaration scope.");
{
struct ctx_decl_scope *parent_scope = NULL;
- assert(ctx);
+ BT_ASSERT(ctx);
if (!ctx->current_scope) {
goto end;
UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE,
} state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE;
- assert(field_ref);
+ BT_ASSERT(field_ref);
ret = calloc(strlen(field_ref) + 1, 1);
if (!ret) {
BT_LOGE("Failed to allocate a string: size=%zu",
struct ctf_node *node;
str = g_string_new(NULL);
- assert(str);
+ BT_ASSERT(str);
bt_list_for_each_entry(node, head, siblings) {
char *src_string;
ret = bt_field_type_integer_set_base(
nested_decl,
BT_INTEGER_BASE_HEXADECIMAL);
- assert(ret == 0);
+ BT_ASSERT(ret == 0);
}
} else {
ret = visit_type_specifier_list(ctx,
type_specifier_list, &nested_decl);
if (ret) {
- assert(!nested_decl);
+ BT_ASSERT(!nested_decl);
goto error;
}
}
}
- assert(nested_decl);
+ BT_ASSERT(nested_decl);
if (!node_type_declarator) {
BT_MOVE(*field_decl, nested_decl);
goto error;
}
- assert(!nested_decl);
- assert(decl);
- assert(!*field_decl);
+ BT_ASSERT(!nested_decl);
+ BT_ASSERT(decl);
+ BT_ASSERT(!*field_decl);
/*
* At this point, we found the next nested declaration.
&outer_field_decl, decl);
decl = NULL;
if (ret) {
- assert(!outer_field_decl);
+ BT_ASSERT(!outer_field_decl);
ret = -EINVAL;
goto error;
}
- assert(outer_field_decl);
+ BT_ASSERT(outer_field_decl);
BT_MOVE(*field_decl, outer_field_decl);
}
end:
BT_PUT(nested_decl);
- assert(*field_decl);
+ BT_ASSERT(*field_decl);
return 0;
ret = visit_type_declarator(ctx, type_specifier_list,
&qfield_name, iter, &field_decl, NULL);
if (ret) {
- assert(!field_decl);
+ BT_ASSERT(!field_decl);
_BT_LOGE_NODE(type_specifier_list,
"Cannot visit type declarator: ret=%d", ret);
goto error;
}
- assert(field_decl);
+ BT_ASSERT(field_decl);
field_name = g_quark_to_string(qfield_name);
/* Check if field with same name already exists */
ret = visit_type_declarator(ctx, type_specifier_list,
&qfield_name, iter, &field_decl, NULL);
if (ret) {
- assert(!field_decl);
+ BT_ASSERT(!field_decl);
_BT_LOGE_NODE(type_specifier_list,
"Cannot visit type declarator: ret=%d", ret);
goto error;
}
- assert(field_decl);
+ BT_ASSERT(field_decl);
field_name = g_quark_to_string(qfield_name);
/* Check if field with same name already exists */
target->u.typealias_target.type_specifier_list,
&qdummy_field_name, node, &type_decl, NULL);
if (ret) {
- assert(!type_decl);
+ BT_ASSERT(!type_decl);
_BT_LOGE_NODE(node,
"Cannot visit type declarator: ret=%d", ret);
goto end;
BT_MOVE(*variant_decl, untagged_variant_decl);
}
- assert(!untagged_variant_decl);
- assert(*variant_decl);
+ BT_ASSERT(!untagged_variant_decl);
+ BT_ASSERT(*variant_decl);
return 0;
struct ctf_node *iter;
int64_t start = 0, end = 0;
const char *label = enumerator->u.enumerator.id;
+ const char *effective_label = label;
struct bt_list_head *values = &enumerator->u.enumerator.values;
bt_list_for_each_entry(iter, values, siblings) {
*last = end + 1;
+ if (label[0] == '_') {
+ /*
+ * Strip the first underscore of any enumeration field
+ * type's label in case this enumeration FT is used as
+ * a variant FT tag later. The variant FT choice names
+ * could also start with `_`, in which case the prefix
+ * is removed, and it the resulting choice name needs to
+ * match tag labels.
+ */
+ effective_label = &label[1];
+ }
+
if (is_signed) {
- ret = bt_ctf_field_type_enumeration_add_mapping(enum_decl, label,
- start, end);
+ ret = bt_field_type_enumeration_signed_add_mapping(enum_decl,
+ effective_label, start, end);
} else {
- ret = bt_field_type_enumeration_add_mapping_unsigned(enum_decl,
- label, (uint64_t) start, (uint64_t) end);
+ ret = bt_field_type_enumeration_unsigned_add_mapping(enum_decl,
+ effective_label, (uint64_t) start, (uint64_t) end);
}
if (ret) {
_BT_LOGE_NODE(enumerator,
ret = visit_type_declarator(ctx, container_type,
&qdummy_id, NULL, &integer_decl, NULL);
if (ret) {
- assert(!integer_decl);
+ BT_ASSERT(!integer_decl);
ret = -EINVAL;
goto error;
}
}
- assert(integer_decl);
+ BT_ASSERT(integer_decl);
if (!bt_field_type_is_integer(integer_decl)) {
BT_LOGE("Container field type for enumeration field type is not an integer field type: "
"ft-id=%s",
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(integer_decl)));
ret = -EINVAL;
goto error;
ret = visit_integer_decl(ctx, &node->u.integer.expressions,
decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
ret = visit_floating_point_number_decl(ctx,
&node->u.floating_point.expressions, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
ret = visit_string_decl(ctx,
&node->u.string.expressions, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
node->u._struct.has_body,
&node->u._struct.min_align, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
&node->u.variant.declaration_list,
node->u.variant.has_body, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
&node->u._enum.enumerator_list,
node->u._enum.has_body, decl);
if (ret) {
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
_BT_LOGE_NODE(first,
"Cannot visit type specifier: ret=%d",
ret);
- assert(!*decl);
+ BT_ASSERT(!*decl);
goto error;
}
break;
goto error;
}
- assert(*decl);
+ BT_ASSERT(*decl);
return 0;
_SET(set, _EVENT_NAME_SET);
} else if (!strcmp(left, "id")) {
- int64_t id;
+ int64_t id = -1;
if (_IS_SET(set, _EVENT_ID_SET)) {
_BT_LOGE_DUP_ATTR(node, "id",
goto error;
}
- assert(decl);
- ret = bt_event_class_set_context_type(
+ BT_ASSERT(decl);
+ ret = bt_event_class_set_context_field_type(
event_class, decl);
BT_PUT(decl);
if (ret) {
goto error;
}
- assert(decl);
- ret = bt_event_class_set_payload_type(
+ BT_ASSERT(decl);
+ ret = bt_event_class_set_payload_field_type(
event_class, decl);
BT_PUT(decl);
if (ret) {
int ret = 0;
/* Context type. */
- ret = bt_event_class_set_context_type(event_class, NULL);
+ ret = bt_event_class_set_context_field_type(event_class, NULL);
if (ret) {
BT_LOGE("Cannot reset initial event class's context field type: "
"event-name=\"%s\"",
}
/* Event payload. */
- ret = bt_event_class_set_payload_type(event_class, NULL);
+ ret = bt_event_class_set_payload_field_type(event_class, NULL);
if (ret) {
BT_LOGE("Cannot reset initial event class's payload field type: "
"event-name=\"%s\"",
int ret = 0;
/* Packet context. */
- ret = bt_stream_class_set_packet_context_type(stream_class, NULL);
+ ret = bt_stream_class_set_packet_context_field_type(stream_class, NULL);
if (ret) {
BT_LOGE_STR("Cannot reset initial stream class's packet context field type.");
goto end;
}
/* Event header. */
- ret = bt_stream_class_set_event_header_type(stream_class, NULL);
+ ret = bt_stream_class_set_event_header_field_type(stream_class, NULL);
if (ret) {
BT_LOGE_STR("Cannot reset initial stream class's event header field type.");
goto end;
}
/* Event context. */
- ret = bt_stream_class_set_event_context_type(stream_class, NULL);
+ ret = bt_stream_class_set_event_context_field_type(stream_class, NULL);
if (ret) {
BT_LOGE_STR("Cannot reset initial stream class's event context field type.");
goto end;
int ret;
struct bt_stream_class *stream_class;
- stream_class = bt_stream_class_create_empty(NULL);
+ stream_class = bt_stream_class_create(NULL);
if (!stream_class) {
BT_LOGE_STR("Cannot create empty stream class.");
goto error;
stream_id = *((int64_t *) keys->data);
g_list_free(keys);
} else {
- assert(bt_trace_get_stream_class_count(
+ BT_ASSERT(bt_trace_get_stream_class_count(
ctx->trace) == 1);
stream_class =
bt_trace_get_stream_class_by_index(
ctx->trace, 0);
- assert(stream_class);
+ BT_ASSERT(stream_class);
stream_id = bt_stream_class_get_id(
stream_class);
BT_PUT(stream_class);
}
}
- assert(stream_id >= 0);
+ BT_ASSERT(stream_id >= 0);
/* We have the stream ID now; get the stream class if found */
stream_class = g_hash_table_lookup(ctx->stream_classes, &stream_id);
}
}
- assert(stream_class);
+ BT_ASSERT(stream_class);
if (!_IS_SET(&set, _EVENT_ID_SET)) {
/* Allow only one event without ID per stream */
}
clock_class_count = bt_trace_get_clock_class_count(ctx->trace);
- assert(clock_class_count >= 0);
+ BT_ASSERT(clock_class_count >= 0);
switch (clock_class_count) {
case 0:
*/
clock_class_to_map_to =
bt_trace_get_clock_class_by_index(ctx->trace, 0);
- assert(clock_class_to_map_to);
+ BT_ASSERT(clock_class_to_map_to);
break;
default:
/*
goto end;
}
- assert(clock_class_to_map_to);
+ BT_ASSERT(clock_class_to_map_to);
ret = bt_field_type_integer_set_mapped_clock_class(ft,
clock_class_to_map_to);
if (ret) {
count = bt_field_type_variant_get_field_count(root_ft);
}
- assert(count >= 0);
+ BT_ASSERT(count >= 0);
for (i = 0; i < count; i++) {
_BT_FIELD_TYPE_INIT(ft);
root_ft, &name, &ft, i);
}
- assert(ret == 0);
+ BT_ASSERT(ret == 0);
if (strcmp(name, field_name) == 0) {
ret = auto_map_field_to_trace_clock_class(ctx, ft);
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
ret = auto_map_fields_to_trace_clock_class(ctx,
decl, "timestamp");
if (ret) {
goto error;
}
- ret = bt_stream_class_set_event_header_type(
+ ret = bt_stream_class_set_event_header_field_type(
stream_class, decl);
BT_PUT(decl);
if (ret) {
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
- ret = bt_stream_class_set_event_context_type(
+ ret = bt_stream_class_set_event_context_field_type(
stream_class, decl);
BT_PUT(decl);
if (ret) {
goto error;
}
- assert(decl);
+ BT_ASSERT(decl);
ret = auto_map_fields_to_trace_clock_class(ctx,
decl, "timestamp_begin");
if (ret) {
goto error;
}
- ret = bt_stream_class_set_packet_context_type(
+ ret = bt_stream_class_set_packet_context_field_type(
stream_class, decl);
BT_PUT(decl);
if (ret) {
_BT_FIELD_TYPE_INIT(packet_header_decl);
packet_header_decl =
- bt_trace_get_packet_header_type(ctx->trace);
+ bt_trace_get_packet_header_field_type(ctx->trace);
if (!packet_header_decl) {
_BT_LOGE_NODE(node,
"Stream class has a `id` attribute, "
/* Automatic ID: 0 */
ret = bt_stream_class_set_id(stream_class, 0);
- assert(ret == 0);
+ BT_ASSERT(ret == 0);
}
id = bt_stream_class_get_id(stream_class);
goto error;
}
- assert(packet_header_decl);
- ret = bt_trace_set_packet_header_type(ctx->trace,
+ BT_ASSERT(packet_header_decl);
+ ret = bt_trace_set_packet_header_field_type(ctx->trace,
packet_header_decl);
BT_PUT(packet_header_decl);
if (ret) {
g_free(right);
_SET(set, _CLOCK_DESCRIPTION_SET);
} else if (!strcmp(left, "freq")) {
- uint64_t freq;
+ uint64_t freq = -1ULL;
if (_IS_SET(set, _CLOCK_FREQ_SET)) {
_BT_LOGE_DUP_ATTR(entry_node, "freq", "clock class");
}
clock_class_name = bt_clock_class_get_name(clock);
- assert(clock_class_name);
+ BT_ASSERT(clock_class_name);
if (ctx->is_lttng && strcmp(clock_class_name, "monotonic") == 0) {
/*
* Old versions of LTTng forgot to set its clock class
_BT_LOGE_NODE(root_decl_node,
"Cannot visit root scope's field type: "
"ret=%d", ret);
- assert(!decl);
+ BT_ASSERT(!decl);
goto end;
}
int ret = 0;
struct bt_value *value = NULL;
- assert(bt_trace_get_stream_class_count(ctx->trace) == 0);
+ BT_ASSERT(bt_trace_get_stream_class_count(ctx->trace) == 0);
name = g_string_new(NULL);
if (!name) {
BT_LOGE_STR("Failed to allocate a GString.");
*/
value = bt_trace_get_environment_field_value_by_name(ctx->trace,
"hostname");
- if (bt_value_is_string(value)) {
+ if (value && bt_value_is_string(value)) {
const char *hostname;
ret = bt_value_string_get(value, &hostname);
- assert(ret == 0);
+ BT_ASSERT(ret == 0);
g_string_append(name, hostname);
if (ctx->trace_name_suffix) {
}
/* Set packet header to NULL to override the default one */
- ret = bt_trace_set_packet_header_type(trace, NULL);
+ ret = bt_trace_set_packet_header_field_type(trace, NULL);
if (ret) {
BT_LOGE_STR("Cannot reset initial trace's packet header field type.");
goto error;
{
struct ctx *ctx = (void *) visitor;
- assert(ctx);
- assert(ctx->trace);
+ BT_ASSERT(ctx);
+ BT_ASSERT(ctx->trace);
return bt_get(ctx->trace);
}
}
}
- assert(ctx->trace_bo == BT_BYTE_ORDER_LITTLE_ENDIAN ||
+ BT_ASSERT(ctx->trace_bo == BT_BYTE_ORDER_LITTLE_ENDIAN ||
ctx->trace_bo == BT_BYTE_ORDER_BIG_ENDIAN);
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Environment */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/*
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/*
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Callsite blocks are not supported */
"\"callsite\" blocks are not supported as of this version.");
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Trace */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Streams */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
/* Events */
}
}
- assert(ctx->current_scope &&
+ BT_ASSERT(ctx->current_scope &&
ctx->current_scope->parent_scope == NULL);
break;
}