X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Ftrace-ir%2Fattributes.c;h=68f54b8627bf54da58cf008c62ee99b532c869cf;hb=d98421f2abfc5adab28ab7ee9b63537a6c7261cc;hp=488dd86feab50bb4449d400797c7c255ef9d5555;hpb=2242b43d4f50ebdeabb124154fb8ac602c563536;p=babeltrace.git diff --git a/src/lib/trace-ir/attributes.c b/src/lib/trace-ir/attributes.c index 488dd86f..68f54b86 100644 --- a/src/lib/trace-ir/attributes.c +++ b/src/lib/trace-ir/attributes.c @@ -1,24 +1,8 @@ /* + * SPDX-License-Identifier: MIT + * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx - * - * 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/ATTRS" @@ -26,9 +10,9 @@ #include "common/macros.h" #include -#include "lib/assert-pre.h" +#include "lib/assert-cond.h" #include "lib/object.h" -#include +#include #include "lib/value.h" #include "attributes.h" #include @@ -77,117 +61,64 @@ void bt_attributes_destroy(struct bt_value *attr_obj) } BT_HIDDEN -int64_t bt_attributes_get_count(const struct bt_value *attr_obj) +uint64_t bt_attributes_get_count(const struct bt_value *attr_obj) { - return bt_value_array_get_size(attr_obj); + return bt_value_array_get_length(attr_obj); } BT_HIDDEN const char *bt_attributes_get_field_name(const struct bt_value *attr_obj, uint64_t index) { - const char *ret = NULL; const struct bt_value *attr_field_obj = NULL; const struct bt_value *attr_field_name_obj = NULL; - BT_ASSERT(attr_obj); - BT_ASSERT(index < bt_value_array_get_size(attr_obj)); + BT_ASSERT_DBG(attr_obj); + BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj)); attr_field_obj = bt_value_array_borrow_element_by_index_const( attr_obj, index); - if (!attr_field_obj) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot borrow attributes object's array value's element by index: " - "%![value-]+v, index=%" PRIu64, attr_obj, index); - goto end; - } attr_field_name_obj = bt_value_array_borrow_element_by_index_const(attr_field_obj, BT_ATTR_NAME_INDEX); - if (!attr_field_name_obj) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot get attribute array value's element by index: " - "%![value-]+v, index=%" PRIu64, attr_field_obj, - (uint64_t) BT_ATTR_NAME_INDEX); - goto end; - } - - ret = bt_value_string_get(attr_field_name_obj); -end: - return ret; + return bt_value_string_get(attr_field_name_obj); } BT_HIDDEN struct bt_value *bt_attributes_borrow_field_value( struct bt_value *attr_obj, uint64_t index) { - struct bt_value *value_obj = NULL; struct bt_value *attr_field_obj = NULL; - BT_ASSERT(attr_obj); - BT_ASSERT(index < bt_value_array_get_size(attr_obj)); + BT_ASSERT_DBG(attr_obj); + BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj)); + attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); - if (!attr_field_obj) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot get attributes object's array value's element by index: " - "%![value-]+v, index=%" PRIu64, attr_obj, index); - goto end; - } - value_obj = bt_value_array_borrow_element_by_index( - attr_field_obj, BT_ATTR_VALUE_INDEX); - if (!value_obj) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot get attribute array value's element by index: " - "%![value-]+v, index=%" PRIu64, attr_field_obj, - (uint64_t) BT_ATTR_VALUE_INDEX); - } - -end: - return value_obj; + return bt_value_array_borrow_element_by_index( attr_field_obj, + BT_ATTR_VALUE_INDEX); } static struct bt_value *bt_attributes_borrow_field_by_name( struct bt_value *attr_obj, const char *name) { - uint64_t i; - int64_t attr_size; + uint64_t i, attr_size; struct bt_value *value_obj = NULL; struct bt_value *attr_field_name_obj = NULL; - attr_size = bt_value_array_get_size(attr_obj); - if (attr_size < 0) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot get array value's size: %![value-]+v", - attr_obj); - goto error; - } - + attr_size = bt_value_array_get_length(attr_obj); for (i = 0; i < attr_size; ++i) { const char *field_name; value_obj = bt_value_array_borrow_element_by_index( attr_obj, i); - if (!value_obj) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot get attributes object's array value's element by index: " - "%![value-]+v, index=%" PRIu64, attr_obj, i); - goto error; - } attr_field_name_obj = bt_value_array_borrow_element_by_index( value_obj, BT_ATTR_NAME_INDEX); - if (!attr_field_name_obj) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot get attribute array value's element by index: " - "%![value-]+v, index=%" PRIu64, - value_obj, (int64_t) BT_ATTR_NAME_INDEX); - goto error; - } field_name = bt_value_string_get(attr_field_name_obj); @@ -199,10 +130,6 @@ struct bt_value *bt_attributes_borrow_field_by_name( } return value_obj; - -error: - value_obj = NULL; - return value_obj; } BT_HIDDEN @@ -263,8 +190,8 @@ struct bt_value *bt_attributes_borrow_field_value_by_name( struct bt_value *value_obj = NULL; struct bt_value *attr_field_obj = NULL; - BT_ASSERT(attr_obj); - BT_ASSERT(name); + BT_ASSERT_DBG(attr_obj); + BT_ASSERT_DBG(name); attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name); if (!attr_field_obj) { BT_LOGD("Cannot find attributes object's field by name: " @@ -274,12 +201,6 @@ struct bt_value *bt_attributes_borrow_field_value_by_name( value_obj = bt_value_array_borrow_element_by_index( attr_field_obj, BT_ATTR_VALUE_INDEX); - if (!value_obj) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot get attribute array value's element by index: " - "%![value-]+v, index=%" PRIu64, attr_field_obj, - (uint64_t) BT_ATTR_VALUE_INDEX); - } end: return value_obj; @@ -288,14 +209,13 @@ end: BT_HIDDEN int bt_attributes_freeze(const struct bt_value *attr_obj) { - uint64_t i; - int64_t count; + uint64_t i, count; int ret = 0; BT_ASSERT(attr_obj); BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); - count = bt_value_array_get_size(attr_obj); - BT_ASSERT(count >= 0); + + count = bt_value_array_get_length(attr_obj); /* * We do not freeze the array value object itself here, since