X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Ftrace-ir%2Ffield.c;h=922b9abb8d4fac71329d2dd78e026874c891e262;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hp=0b8529b28be98afe61ea70c7e3fbe07c6a3c81a7;hpb=9c3869a9d005111c48715720e4c9a100cb2d5ec7;p=babeltrace.git diff --git a/src/lib/trace-ir/field.c b/src/lib/trace-ir/field.c index 0b8529b2..922b9abb 100644 --- a/src/lib/trace-ir/field.c +++ b/src/lib/trace-ir/field.c @@ -1,24 +1,8 @@ /* + * SPDX-License-Identifier: MIT + * * Copyright 2017-2018 Philippe Proulx * Copyright 2013, 2014 Jérémie Galarneau - * - * 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. */ #define BT_LOG_TAG "LIB/FIELD" @@ -26,13 +10,13 @@ #include "lib/assert-pre.h" #include -#include #include "lib/object.h" #include "compat/compiler.h" #include "compat/fcntl.h" #include "common/align.h" #include "common/assert.h" #include +#include #include "field.h" #include "field-class.h" @@ -271,7 +255,7 @@ struct bt_field *bt_field_create(struct bt_field_class *fc) field = create_variant_field(fc); break; default: - abort(); + bt_common_abort(); } if (!field) { @@ -796,6 +780,7 @@ bt_field_enumeration_unsigned_get_mapping_labels( { const struct bt_field_integer *int_field = (const void *) field; + BT_ASSERT_PRE_DEV_NO_ERROR(); BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)"); BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)"); @@ -815,6 +800,7 @@ bt_field_enumeration_signed_get_mapping_labels( { const struct bt_field_integer *int_field = (const void *) field; + BT_ASSERT_PRE_DEV_NO_ERROR(); BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)"); BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Count (output)"); @@ -853,7 +839,7 @@ void clear_string_field(struct bt_field *field) { struct bt_field_string *string_field = (void *) field; - BT_ASSERT(field); + BT_ASSERT_DBG(field); string_field->length = 0; bt_field_set_single(field, true); } @@ -861,6 +847,7 @@ void clear_string_field(struct bt_field *field) enum bt_field_string_set_value_status bt_field_string_set_value( struct bt_field *field, const char *value) { + BT_ASSERT_PRE_DEV_NO_ERROR(); BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); BT_ASSERT_PRE_DEV_NON_NULL(value, "Value"); BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field"); @@ -874,6 +861,8 @@ enum bt_field_string_set_value_status bt_field_string_set_value( enum bt_field_string_append_status bt_field_string_append( struct bt_field *field, const char *value) { + BT_ASSERT_PRE_DEV_NO_ERROR(); + return bt_field_string_append_with_length(field, value, (uint64_t) strlen(value)); } @@ -885,6 +874,7 @@ enum bt_field_string_append_status bt_field_string_append_with_length( char *data; uint64_t new_length; + BT_ASSERT_PRE_DEV_NO_ERROR(); BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); BT_ASSERT_PRE_DEV_NON_NULL(value, "Value"); BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field"); @@ -934,6 +924,7 @@ enum bt_field_array_dynamic_set_length_status bt_field_array_dynamic_set_length( int ret = BT_FUNC_STATUS_OK; struct bt_field_array *array_field = (void *) field; + BT_ASSERT_PRE_DEV_NO_ERROR(); BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); BT_ASSERT_PRE_DEV_FIELD_IS_DYNAMIC_ARRAY(field, "Field"); BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field"); @@ -961,7 +952,7 @@ enum bt_field_array_dynamic_set_length_status bt_field_array_dynamic_set_length( goto end; } - BT_ASSERT(!array_field->fields->pdata[i]); + BT_ASSERT_DBG(!array_field->fields->pdata[i]); array_field->fields->pdata[i] = elem_field; } } @@ -1047,7 +1038,7 @@ struct bt_field *borrow_structure_field_member_field_by_name( } ret_field = struct_field->fields->pdata[GPOINTER_TO_UINT(index)]; - BT_ASSERT(ret_field); + BT_ASSERT_DBG(ret_field); end: return ret_field; @@ -1128,7 +1119,7 @@ borrow_variant_field_selected_class_option(const struct bt_field *field) const struct bt_field_class_named_field_class_container *container_fc; const struct bt_field_variant *var_field = (const void *) field; - BT_ASSERT(field); + BT_ASSERT_DBG(field); BT_ASSERT_PRE_DEV(var_field->selected_field, "Variant field has no selected field: %!+f", field); container_fc = (const void *) field->class; @@ -1136,7 +1127,7 @@ borrow_variant_field_selected_class_option(const struct bt_field *field) } const struct bt_field_class_variant_option * -bt_field_variant_borrow_selected_class_option_const( +bt_field_variant_borrow_selected_option_class_const( const struct bt_field *field) { BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); @@ -1145,7 +1136,7 @@ bt_field_variant_borrow_selected_class_option_const( } const struct bt_field_class_variant_with_selector_field_integer_unsigned_option * -bt_field_variant_with_unsigned_integer_selector_borrow_selected_class_option_const( +bt_field_variant_with_selector_field_integer_unsigned_borrow_selected_option_class_const( const struct bt_field *field) { BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); @@ -1155,7 +1146,7 @@ bt_field_variant_with_unsigned_integer_selector_borrow_selected_class_option_con } const struct bt_field_class_variant_with_selector_field_integer_signed_option * -bt_field_variant_with_signed_integer_selector_borrow_selected_class_option_const( +bt_field_variant_with_selector_field_integer_signed_borrow_selected_option_class_const( const struct bt_field *field) { BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); @@ -1164,12 +1155,13 @@ bt_field_variant_with_signed_integer_selector_borrow_selected_class_option_const return (const void *) borrow_variant_field_selected_class_option(field); } -enum bt_field_variant_select_option_field_by_index_status -bt_field_variant_select_option_field_by_index( +enum bt_field_variant_select_option_by_index_status +bt_field_variant_select_option_by_index( struct bt_field *field, uint64_t index) { struct bt_field_variant *var_field = (void *) field; + BT_ASSERT_PRE_DEV_NO_ERROR(); BT_ASSERT_PRE_DEV_NON_NULL(field, "Field"); BT_ASSERT_PRE_DEV_FIELD_IS_VARIANT(field, "Field"); BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field"); @@ -1179,7 +1171,7 @@ bt_field_variant_select_option_field_by_index( return BT_FUNC_STATUS_OK; } -uint64_t bt_field_variant_get_selected_option_field_index( +uint64_t bt_field_variant_get_selected_option_index( const struct bt_field *field) { const struct bt_field_variant *var_field = (const void *) field; @@ -1364,14 +1356,14 @@ void bt_field_destroy(struct bt_field *field) destroy_variant_field(field); break; default: - abort(); + bt_common_abort(); } } static void reset_single_field(struct bt_field *field) { - BT_ASSERT(field); + BT_ASSERT_DBG(field); field->is_set = false; } @@ -1381,7 +1373,7 @@ void reset_structure_field(struct bt_field *field) uint64_t i; struct bt_field_structure *struct_field = (void *) field; - BT_ASSERT(field); + BT_ASSERT_DBG(field); for (i = 0; i < struct_field->fields->len; i++) { bt_field_reset(struct_field->fields->pdata[i]); @@ -1393,7 +1385,7 @@ void reset_option_field(struct bt_field *field) { struct bt_field_option *opt_field = (void *) field; - BT_ASSERT(opt_field); + BT_ASSERT_DBG(opt_field); bt_field_reset(opt_field->content_field); opt_field->selected_field = NULL; } @@ -1404,7 +1396,7 @@ void reset_variant_field(struct bt_field *field) uint64_t i; struct bt_field_variant *var_field = (void *) field; - BT_ASSERT(field); + BT_ASSERT_DBG(field); for (i = 0; i < var_field->fields->len; i++) { bt_field_reset(var_field->fields->pdata[i]); @@ -1417,7 +1409,7 @@ void reset_array_field(struct bt_field *field) uint64_t i; struct bt_field_array *array_field = (void *) field; - BT_ASSERT(field); + BT_ASSERT_DBG(field); for (i = 0; i < array_field->fields->len; i++) { bt_field_reset(array_field->fields->pdata[i]); @@ -1508,17 +1500,17 @@ BT_HIDDEN void _bt_field_set_is_frozen(const struct bt_field *field, bool is_frozen) { - BT_ASSERT(field); + BT_ASSERT_DBG(field); BT_LIB_LOGD("Setting field object's frozen state: %!+f, is-frozen=%d", field, is_frozen); - BT_ASSERT(field->methods->set_is_frozen); + BT_ASSERT_DBG(field->methods->set_is_frozen); field->methods->set_is_frozen((void *) field, is_frozen); } static bool single_field_is_set(const struct bt_field *field) { - BT_ASSERT(field); + BT_ASSERT_DBG(field); return field->is_set; } @@ -1529,7 +1521,7 @@ bool structure_field_is_set(const struct bt_field *field) uint64_t i; const struct bt_field_structure *struct_field = (const void *) field; - BT_ASSERT(field); + BT_ASSERT_DBG(field); for (i = 0; i < struct_field->fields->len; i++) { is_set = bt_field_is_set(struct_field->fields->pdata[i]); @@ -1548,7 +1540,7 @@ bool option_field_is_set(const struct bt_field *field) const struct bt_field_option *opt_field = (const void *) field; bool is_set = false; - BT_ASSERT(field); + BT_ASSERT_DBG(field); if (opt_field->selected_field) { is_set = bt_field_is_set(opt_field->selected_field); @@ -1563,7 +1555,7 @@ bool variant_field_is_set(const struct bt_field *field) const struct bt_field_variant *var_field = (const void *) field; bool is_set = false; - BT_ASSERT(field); + BT_ASSERT_DBG(field); if (var_field->selected_field) { is_set = bt_field_is_set(var_field->selected_field); @@ -1579,7 +1571,7 @@ bool array_field_is_set(const struct bt_field *field) uint64_t i; const struct bt_field_array *array_field = (const void *) field; - BT_ASSERT(field); + BT_ASSERT_DBG(field); for (i = 0; i < array_field->length; i++) { is_set = bt_field_is_set(array_field->fields->pdata[i]);