X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fvalues.c;h=ea69643e4dff8d5dde51687e7d7885051957cec2;hb=872eeccbe6bb5201177a77f5bedc216750abd293;hp=f4810da944399f1b5360525f96e5c38dac4b30ce;hpb=a704fb0b42676c59bf4b7d7a40530883282ed685;p=babeltrace.git diff --git a/lib/values.c b/lib/values.c index f4810da9..ea69643e 100644 --- a/lib/values.c +++ b/lib/values.c @@ -196,17 +196,11 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) struct bt_value *element_obj_copy; struct bt_value *element_obj = bt_value_array_get(array_obj, i); - if (!element_obj) { - BT_LOGE("Cannot get array value's element: " - "addr=%p, index=%d", - array_obj, i); - BT_PUT(copy_obj); - goto end; - } - + assert(element_obj); + BT_LOGD("Copying array value's element: element-addr=%p, " + "index=%d", element_obj, i); element_obj_copy = bt_value_copy(element_obj); BT_PUT(element_obj); - if (!element_obj_copy) { BT_LOGE("Cannot copy array value's element: " "array-addr=%p, index=%d", @@ -217,7 +211,6 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) ret = bt_value_array_append(copy_obj, element_obj_copy); BT_PUT(element_obj_copy); - if (ret) { BT_LOGE("Cannot append to array value: addr=%p", array_obj); @@ -256,8 +249,10 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) while (g_hash_table_iter_next(&iter, &key, &element_obj)) { const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key)); + assert(key_str); + BT_LOGD("Copying map value's element: element-addr=%p, " + "key=\"%s\"", element_obj, key_str); element_obj_copy = bt_value_copy(element_obj); - if (!element_obj_copy) { BT_LOGE("Cannot copy map value's element: " "map-addr=%p, key=\"%s\"", @@ -268,7 +263,6 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) ret = bt_value_map_insert(copy_obj, key_str, element_obj_copy); BT_PUT(element_obj_copy); - if (ret) { BT_LOGE("Cannot insert into map value: addr=%p, key=\"%s\"", map_obj, key_str); @@ -310,32 +304,64 @@ static bt_bool bt_value_bool_compare(const struct bt_value *object_a, const struct bt_value *object_b) { - return BT_VALUE_TO_BOOL(object_a)->value == - BT_VALUE_TO_BOOL(object_b)->value; + if (BT_VALUE_TO_BOOL(object_a)->value != + BT_VALUE_TO_BOOL(object_b)->value) { + BT_LOGV("Boolean value objects are different: " + "bool-a-val=%d, bool-b-val=%d", + BT_VALUE_TO_BOOL(object_a)->value, + BT_VALUE_TO_BOOL(object_b)->value); + return BT_FALSE; + } + + return BT_TRUE; } static bt_bool bt_value_integer_compare(const struct bt_value *object_a, const struct bt_value *object_b) { - return BT_VALUE_TO_INTEGER(object_a)->value == - BT_VALUE_TO_INTEGER(object_b)->value; + if (BT_VALUE_TO_INTEGER(object_a)->value != + BT_VALUE_TO_INTEGER(object_b)->value) { + BT_LOGV("Integer value objects are different: " + "int-a-val=%" PRId64 ", int-b-val=%" PRId64, + BT_VALUE_TO_INTEGER(object_a)->value, + BT_VALUE_TO_INTEGER(object_b)->value); + return BT_FALSE; + } + + return BT_TRUE; } static bt_bool bt_value_float_compare(const struct bt_value *object_a, const struct bt_value *object_b) { - return BT_VALUE_TO_FLOAT(object_a)->value == - BT_VALUE_TO_FLOAT(object_b)->value; + if (BT_VALUE_TO_FLOAT(object_a)->value != + BT_VALUE_TO_FLOAT(object_b)->value) { + BT_LOGV("Floating point number value objects are different: " + "float-a-val=%f, float-b-val=%f", + BT_VALUE_TO_FLOAT(object_a)->value, + BT_VALUE_TO_FLOAT(object_b)->value); + return BT_FALSE; + } + + return BT_TRUE; } static bt_bool bt_value_string_compare(const struct bt_value *object_a, const struct bt_value *object_b) { - return !strcmp(BT_VALUE_TO_STRING(object_a)->gstr->str, - BT_VALUE_TO_STRING(object_b)->gstr->str); + if (strcmp(BT_VALUE_TO_STRING(object_a)->gstr->str, + BT_VALUE_TO_STRING(object_b)->gstr->str) != 0) { + BT_LOGV("String value objects are different: " + "string-a-val=\"%s\", string-b-val=\"%s\"", + BT_VALUE_TO_STRING(object_a)->gstr->str, + BT_VALUE_TO_STRING(object_b)->gstr->str); + return BT_FALSE; + } + + return BT_TRUE; } static @@ -368,7 +394,7 @@ bt_bool bt_value_array_compare(const struct bt_value *object_a, if (!bt_value_compare(element_obj_a, element_obj_b)) { BT_LOGV("Array values's elements are different: " "value-a-addr=%p, value-b-addr=%p, index=%d", - element_obj_a, element_obj_b, index); + element_obj_a, element_obj_b, i); BT_PUT(element_obj_a); BT_PUT(element_obj_b); ret = BT_FALSE; @@ -433,9 +459,9 @@ bt_bool (* const compare_funcs[])(const struct bt_value *, [BT_VALUE_TYPE_NULL] = bt_value_null_compare, [BT_VALUE_TYPE_BOOL] = bt_value_bool_compare, [BT_VALUE_TYPE_INTEGER] = bt_value_integer_compare, - [BT_VALUE_TYPE_FLOAT] = bt_value_float_compare, + [BT_VALUE_TYPE_FLOAT] = bt_value_float_compare, [BT_VALUE_TYPE_STRING] = bt_value_string_compare, - [BT_VALUE_TYPE_ARRAY] = bt_value_array_compare, + [BT_VALUE_TYPE_ARRAY] = bt_value_array_compare, [BT_VALUE_TYPE_MAP] = bt_value_map_compare, }; @@ -540,7 +566,11 @@ bt_bool bt_value_is_frozen(const struct bt_value *object) enum bt_value_type bt_value_get_type(const struct bt_value *object) { if (!object) { - BT_LOGW_STR("Invalid parameter: value object is NULL."); + /* + * Not an error: user can test NULL value object with + * this function. + */ + BT_LOGV_STR("Value object is NULL."); return BT_VALUE_TYPE_UNKNOWN; } @@ -644,7 +674,7 @@ struct bt_value *bt_value_string_create_init(const char *val) goto end; } - BT_LOGD("Creating string value object: val-len=%u", strlen(val)); + BT_LOGD("Creating string value object: val-len=%zu", strlen(val)); string_obj = g_new0(struct bt_value_string, 1); if (!string_obj) { @@ -750,7 +780,7 @@ enum bt_value_status bt_value_bool_get(const struct bt_value *bool_obj, if (!bt_value_is_bool(bool_obj)) { BT_LOGW("Invalid parameter: value is not a boolean value: addr=%p, " - "type=%s", bool_obj, bool_obj->type, + "type=%s", bool_obj, bt_value_type_string(bool_obj->type)); ret = BT_VALUE_STATUS_INVAL; goto end; @@ -1551,13 +1581,13 @@ struct bt_value *bt_value_map_extend(struct bt_value *base_map_obj, if (bt_value_map_foreach(extension_obj, extend_map_element, &extend_data)) { - BT_LOGE("Cannot iterate on the extension object's elements: ", + BT_LOGE("Cannot iterate on the extension object's elements: " "extension-value-addr=%p", extension_obj); goto error; } if (extend_data.got_error) { - BT_LOGE("Failed to successfully iterate on the extension object's elements: ", + BT_LOGE("Failed to successfully iterate on the extension object's elements: " "extension-value-addr=%p", extension_obj); goto error; }