X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Ftrace-ir%2Fattributes.c;h=8e85af5cc44508b142a97ffe82a3b8c4b68cc77a;hb=3fadfbc0c91f82c46bd36e6e0657ea93570c9db1;hp=caabda3fafe39eca4da493ed7be4dcf926157040;hpb=07208d85d16704b304b371897bb7acc995fcc481;p=babeltrace.git diff --git a/lib/trace-ir/attributes.c b/lib/trace-ir/attributes.c index caabda3f..8e85af5c 100644 --- a/lib/trace-ir/attributes.c +++ b/lib/trace-ir/attributes.c @@ -1,8 +1,4 @@ /* - * attributes.c - * - * Babeltrace trace IR - Attributes - * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx * @@ -26,15 +22,18 @@ */ #define BT_LOG_TAG "ATTRS" -#include - -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include #define BT_ATTR_NAME_INDEX 0 #define BT_ATTR_VALUE_INDEX 1 @@ -74,23 +73,22 @@ BT_HIDDEN void bt_attributes_destroy(struct bt_value *attr_obj) { BT_LOGD("Destroying attributes object: addr=%p", attr_obj); - bt_put(attr_obj); + BT_OBJECT_PUT_REF_AND_RESET(attr_obj); } BT_HIDDEN -int64_t bt_attributes_get_count(struct bt_value *attr_obj) +int64_t bt_attributes_get_count(const struct bt_value *attr_obj) { return bt_value_array_get_size(attr_obj); } BT_HIDDEN -const char *bt_attributes_get_field_name(struct bt_value *attr_obj, +const char *bt_attributes_get_field_name(const struct bt_value *attr_obj, uint64_t index) { - int rc; const char *ret = NULL; - struct bt_value *attr_field_obj = NULL; - struct bt_value *attr_field_name_obj = NULL; + const struct bt_value *attr_field_obj = NULL; + const struct bt_value *attr_field_name_obj = NULL; if (!attr_obj) { BT_LOGW_STR("Invalid parameter: attributes object is NULL."); @@ -104,15 +102,17 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, goto end; } - attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); + attr_field_obj = bt_value_array_borrow_element_by_index_const( + attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - attr_field_name_obj = bt_value_array_borrow_element_by_index(attr_field_obj, - BT_ATTR_NAME_INDEX); + 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_LOGE("Cannot get attribute array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_field_obj, @@ -120,20 +120,15 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, goto end; } - rc = bt_value_string_get(attr_field_name_obj, &ret); - if (rc) { - BT_LOGE("Cannot get raw value from string value: value-addr=%p", - attr_field_name_obj); - ret = NULL; - } + ret = bt_value_string_get(attr_field_name_obj); end: return ret; } BT_HIDDEN -struct bt_value *bt_attributes_borrow_field_value(struct bt_value *attr_obj, - uint64_t index) +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; @@ -150,15 +145,16 @@ struct bt_value *bt_attributes_borrow_field_value(struct bt_value *attr_obj, goto end; } - attr_field_obj = bt_value_array_borrow_element_by_index(attr_obj, index); + attr_field_obj = + bt_value_array_borrow_element_by_index(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, - BT_ATTR_VALUE_INDEX); + value_obj = bt_value_array_borrow_element_by_index( + attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_field_obj, @@ -186,18 +182,19 @@ struct bt_value *bt_attributes_borrow_field_by_name( } for (i = 0; i < attr_size; ++i) { - int ret; const char *field_name; - value_obj = bt_value_array_borrow_element_by_index(attr_obj, i); + value_obj = bt_value_array_borrow_element_by_index( + attr_obj, i); if (!value_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, i); goto error; } - attr_field_name_obj = bt_value_array_borrow_element_by_index(value_obj, - BT_ATTR_NAME_INDEX); + attr_field_name_obj = + bt_value_array_borrow_element_by_index( + value_obj, BT_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " "value-addr=%p, index=%" PRIu64, @@ -205,12 +202,7 @@ struct bt_value *bt_attributes_borrow_field_by_name( goto error; } - ret = bt_value_string_get(attr_field_name_obj, &field_name); - if (ret) { - BT_LOGE("Cannot get raw value from string value: value-addr=%p", - attr_field_name_obj); - goto error; - } + field_name = bt_value_string_get(attr_field_name_obj); if (!strcmp(field_name, name)) { break; @@ -243,8 +235,9 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name); if (attr_field_obj) { - ret = bt_value_array_set_element_by_index(attr_field_obj, - BT_ATTR_VALUE_INDEX, value_obj); + ret = bt_value_array_set_element_by_index( + attr_field_obj, BT_ATTR_VALUE_INDEX, + value_obj); attr_field_obj = NULL; goto end; } @@ -256,15 +249,18 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, goto end; } - ret = bt_value_array_append_string_element(attr_field_obj, name); - ret |= bt_value_array_append_element(attr_field_obj, value_obj); + ret = bt_value_array_append_string_element(attr_field_obj, + name); + ret |= bt_value_array_append_element(attr_field_obj, + value_obj); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); goto end; } - ret = bt_value_array_append_element(attr_obj, attr_field_obj); + ret = bt_value_array_append_element(attr_obj, + attr_field_obj); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -272,7 +268,7 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, } end: - bt_put(attr_field_obj); + bt_object_put_ref(attr_field_obj); return ret; } @@ -296,8 +292,8 @@ struct bt_value *bt_attributes_borrow_field_value_by_name( goto end; } - value_obj = bt_value_array_borrow_element_by_index(attr_field_obj, - BT_ATTR_VALUE_INDEX); + value_obj = bt_value_array_borrow_element_by_index( + attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_field_obj, @@ -309,7 +305,7 @@ end: } BT_HIDDEN -int bt_attributes_freeze(struct bt_value *attr_obj) +int bt_attributes_freeze(const struct bt_value *attr_obj) { uint64_t i; int64_t count; @@ -333,7 +329,8 @@ int bt_attributes_freeze(struct bt_value *attr_obj) for (i = 0; i < count; ++i) { struct bt_value *obj = NULL; - obj = bt_attributes_borrow_field_value(attr_obj, i); + obj = bt_attributes_borrow_field_value( + (void *) attr_obj, i); if (!obj) { BT_LOGE("Cannot get attributes object's field value by index: " "value-addr=%p, index=%" PRIu64,