lib: rename `bt_*_compare()` to `bt_*_is_equal()`
[babeltrace.git] / src / lib / value.c
index 0fdb060da301d154c9135f21c52db83c8a43889a..91d109fc5d3dbf1d1ea6afc5f5cf0e2c47a58e98 100644 (file)
@@ -136,6 +136,9 @@ void (* const destroy_funcs[])(struct bt_value *) = {
 static
 struct bt_value *bt_value_null_copy(const struct bt_value *null_obj)
 {
+       BT_ASSERT(null_obj == bt_value_null);
+
+       bt_object_get_ref_no_null_check(bt_value_null);
        return (void *) bt_value_null;
 }
 
@@ -294,11 +297,11 @@ struct bt_value *(* const copy_funcs[])(const struct bt_value *) = {
 };
 
 static
-bt_bool bt_value_null_compare(const struct bt_value *object_a,
+bt_bool bt_value_null_is_equal(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
        /*
-        * Always BT_TRUE since bt_value_compare() already checks if both
+        * Always BT_TRUE since bt_value_is_equal() already checks if both
         * object_a and object_b have the same type, and in the case of
         * null value objects, they're always the same if it is so.
         */
@@ -306,7 +309,7 @@ bt_bool bt_value_null_compare(const struct bt_value *object_a,
 }
 
 static
-bt_bool bt_value_bool_compare(const struct bt_value *object_a,
+bt_bool bt_value_bool_is_equal(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
        if (BT_VALUE_TO_BOOL(object_a)->value !=
@@ -322,7 +325,7 @@ bt_bool bt_value_bool_compare(const struct bt_value *object_a,
 }
 
 static
-bt_bool bt_value_integer_compare(const struct bt_value *object_a,
+bt_bool bt_value_integer_is_equal(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
        if (BT_VALUE_TO_INTEGER(object_a)->value.u !=
@@ -346,7 +349,7 @@ bt_bool bt_value_integer_compare(const struct bt_value *object_a,
 }
 
 static
-bt_bool bt_value_real_compare(const struct bt_value *object_a,
+bt_bool bt_value_real_is_equal(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
        if (BT_VALUE_TO_REAL(object_a)->value !=
@@ -362,7 +365,7 @@ bt_bool bt_value_real_compare(const struct bt_value *object_a,
 }
 
 static
-bt_bool bt_value_string_compare(const struct bt_value *object_a,
+bt_bool bt_value_string_is_equal(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
        if (strcmp(BT_VALUE_TO_STRING(object_a)->gstr->str,
@@ -378,7 +381,7 @@ bt_bool bt_value_string_compare(const struct bt_value *object_a,
 }
 
 static
-bt_bool bt_value_array_compare(const struct bt_value *object_a,
+bt_bool bt_value_array_is_equal(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
        int i;
@@ -386,14 +389,14 @@ bt_bool bt_value_array_compare(const struct bt_value *object_a,
        const struct bt_value_array *array_obj_a =
                BT_VALUE_TO_ARRAY(object_a);
 
-       if (bt_value_array_get_size(object_a) !=
-                       bt_value_array_get_size(object_b)) {
+       if (bt_value_array_get_length(object_a) !=
+                       bt_value_array_get_length(object_b)) {
                BT_LOGT("Array values are different: size mismatch "
                        "value-a-addr=%p, value-b-addr=%p, "
                        "value-a-size=%" PRId64 ", value-b-size=%" PRId64,
                        object_a, object_b,
-                       bt_value_array_get_size(object_a),
-                       bt_value_array_get_size(object_b));
+                       bt_value_array_get_length(object_a),
+                       bt_value_array_get_length(object_b));
                ret = BT_FALSE;
                goto end;
        }
@@ -407,7 +410,7 @@ bt_bool bt_value_array_compare(const struct bt_value *object_a,
                element_obj_b = bt_value_array_borrow_element_by_index_const(
                        object_b, i);
 
-               if (!bt_value_compare(element_obj_a, element_obj_b)) {
+               if (!bt_value_is_equal(element_obj_a, element_obj_b)) {
                        BT_LOGT("Array values's elements are different: "
                                "value-a-addr=%p, value-b-addr=%p, index=%d",
                                element_obj_a, element_obj_b, i);
@@ -421,7 +424,7 @@ end:
 }
 
 static
-bt_bool bt_value_map_compare(const struct bt_value *object_a,
+bt_bool bt_value_map_is_equal(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
        bt_bool ret = BT_TRUE;
@@ -450,7 +453,7 @@ bt_bool bt_value_map_compare(const struct bt_value *object_a,
                element_obj_b = bt_value_map_borrow_entry_value_const(object_b,
                        key_str);
 
-               if (!bt_value_compare(element_obj_a, element_obj_b)) {
+               if (!bt_value_is_equal(element_obj_a, element_obj_b)) {
                        BT_LOGT("Map values's elements are different: "
                                "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
                                element_obj_a, element_obj_b, key_str);
@@ -464,16 +467,16 @@ end:
 }
 
 static
-bt_bool (* const compare_funcs[])(const struct bt_value *,
+bt_bool (* const is_equal_funcs[])(const struct bt_value *,
                const struct bt_value *) = {
-       [BT_VALUE_TYPE_NULL] =                  bt_value_null_compare,
-       [BT_VALUE_TYPE_BOOL] =                  bt_value_bool_compare,
-       [BT_VALUE_TYPE_UNSIGNED_INTEGER] =      bt_value_integer_compare,
-       [BT_VALUE_TYPE_SIGNED_INTEGER] =        bt_value_integer_compare,
-       [BT_VALUE_TYPE_REAL] =                  bt_value_real_compare,
-       [BT_VALUE_TYPE_STRING] =                bt_value_string_compare,
-       [BT_VALUE_TYPE_ARRAY] =                 bt_value_array_compare,
-       [BT_VALUE_TYPE_MAP] =                   bt_value_map_compare,
+       [BT_VALUE_TYPE_NULL] =                  bt_value_null_is_equal,
+       [BT_VALUE_TYPE_BOOL] =                  bt_value_bool_is_equal,
+       [BT_VALUE_TYPE_UNSIGNED_INTEGER] =      bt_value_integer_is_equal,
+       [BT_VALUE_TYPE_SIGNED_INTEGER] =        bt_value_integer_is_equal,
+       [BT_VALUE_TYPE_REAL] =                  bt_value_real_is_equal,
+       [BT_VALUE_TYPE_STRING] =                bt_value_string_is_equal,
+       [BT_VALUE_TYPE_ARRAY] =                 bt_value_array_is_equal,
+       [BT_VALUE_TYPE_MAP] =                   bt_value_map_is_equal,
 };
 
 static
@@ -643,26 +646,26 @@ end:
        return (void *) integer_obj;
 }
 
-struct bt_value *bt_value_unsigned_integer_create_init(uint64_t val)
+struct bt_value *bt_value_integer_unsigned_create_init(uint64_t val)
 {
        return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER,
                val);
 }
 
-struct bt_value *bt_value_unsigned_integer_create(void)
+struct bt_value *bt_value_integer_unsigned_create(void)
 {
-       return bt_value_unsigned_integer_create_init(0);
+       return bt_value_integer_unsigned_create_init(0);
 }
 
-struct bt_value *bt_value_signed_integer_create_init(int64_t val)
+struct bt_value *bt_value_integer_signed_create_init(int64_t val)
 {
        return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER,
                (uint64_t) val);
 }
 
-struct bt_value *bt_value_signed_integer_create(void)
+struct bt_value *bt_value_integer_signed_create(void)
 {
-       return bt_value_signed_integer_create_init(0);
+       return bt_value_integer_signed_create_init(0);
 }
 
 struct bt_value *bt_value_real_create_init(double val)
@@ -800,7 +803,7 @@ void bt_value_bool_set(struct bt_value *bool_obj, bt_bool val)
                bool_obj, val);
 }
 
-uint64_t bt_value_unsigned_integer_get(const struct bt_value *integer_obj)
+uint64_t bt_value_integer_unsigned_get(const struct bt_value *integer_obj)
 {
        BT_ASSERT_PRE_DEV_NON_NULL(integer_obj, "Value object");
        BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj,
@@ -808,7 +811,7 @@ uint64_t bt_value_unsigned_integer_get(const struct bt_value *integer_obj)
        return BT_VALUE_TO_INTEGER(integer_obj)->value.u;
 }
 
-int64_t bt_value_signed_integer_get(const struct bt_value *integer_obj)
+int64_t bt_value_integer_signed_get(const struct bt_value *integer_obj)
 {
        BT_ASSERT_PRE_DEV_NON_NULL(integer_obj, "Value object");
        BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(integer_obj,
@@ -826,7 +829,7 @@ void bt_value_integer_set(struct bt_value *integer_obj,
        BT_VALUE_TO_INTEGER(integer_obj)->value.u = uval;
 }
 
-void bt_value_unsigned_integer_set(struct bt_value *integer_obj,
+void bt_value_integer_unsigned_set(struct bt_value *integer_obj,
                uint64_t val)
 {
        bt_value_integer_set(integer_obj, BT_VALUE_TYPE_UNSIGNED_INTEGER, val);
@@ -834,7 +837,7 @@ void bt_value_unsigned_integer_set(struct bt_value *integer_obj,
                "value-addr=%p, value=%" PRIu64, integer_obj, val);
 }
 
-void bt_value_signed_integer_set(struct bt_value *integer_obj,
+void bt_value_integer_signed_set(struct bt_value *integer_obj,
                int64_t val)
 {
        bt_value_integer_set(integer_obj, BT_VALUE_TYPE_SIGNED_INTEGER,
@@ -879,7 +882,7 @@ enum bt_value_string_set_status bt_value_string_set(
        return BT_FUNC_STATUS_OK;
 }
 
-uint64_t bt_value_array_get_size(const struct bt_value *array_obj)
+uint64_t bt_value_array_get_length(const struct bt_value *array_obj)
 {
        BT_ASSERT_PRE_DEV_NON_NULL(array_obj, "Value object");
        BT_ASSERT_PRE_DEV_VALUE_IS_TYPE(array_obj, BT_VALUE_TYPE_ARRAY);
@@ -945,7 +948,7 @@ bt_value_array_append_unsigned_integer_element(struct bt_value *array_obj,
        enum bt_value_array_append_element_status ret;
        struct bt_value *integer_obj = NULL;
 
-       integer_obj = bt_value_unsigned_integer_create_init(val);
+       integer_obj = bt_value_integer_unsigned_create_init(val);
        ret = bt_value_array_append_element(array_obj,
                (void *) integer_obj);
        bt_object_put_ref(integer_obj);
@@ -959,7 +962,7 @@ bt_value_array_append_signed_integer_element(struct bt_value *array_obj,
        enum bt_value_array_append_element_status ret;
        struct bt_value *integer_obj = NULL;
 
-       integer_obj = bt_value_signed_integer_create_init(val);
+       integer_obj = bt_value_integer_signed_create_init(val);
        ret = bt_value_array_append_element(array_obj,
                (void *) integer_obj);
        bt_object_put_ref(integer_obj);
@@ -994,7 +997,8 @@ bt_value_array_append_string_element(struct bt_value *array_obj,
 }
 
 enum bt_value_array_append_element_status
-bt_value_array_append_empty_array_element(struct bt_value *array_obj)
+bt_value_array_append_empty_array_element(struct bt_value *array_obj,
+               struct bt_value **element_obj)
 {
        enum bt_value_array_append_element_status ret;
        struct bt_value *empty_array_obj = NULL;
@@ -1002,12 +1006,18 @@ bt_value_array_append_empty_array_element(struct bt_value *array_obj)
        empty_array_obj = bt_value_array_create();
        ret = bt_value_array_append_element(array_obj,
                (void *) empty_array_obj);
+
+       if (element_obj) {
+               *element_obj = empty_array_obj;
+       }
+
        bt_object_put_ref(empty_array_obj);
        return ret;
 }
 
 enum bt_value_array_append_element_status
-bt_value_array_append_empty_map_element(struct bt_value *array_obj)
+bt_value_array_append_empty_map_element(struct bt_value *array_obj,
+               struct bt_value **element_obj)
 {
        enum bt_value_array_append_element_status ret;
        struct bt_value *map_obj = NULL;
@@ -1015,6 +1025,11 @@ bt_value_array_append_empty_map_element(struct bt_value *array_obj)
        map_obj = bt_value_map_create();
        ret = bt_value_array_append_element(array_obj,
                (void *) map_obj);
+
+       if (element_obj) {
+               *element_obj = map_obj;
+       }
+
        bt_object_put_ref(map_obj);
        return ret;
 }
@@ -1110,7 +1125,7 @@ bt_value_map_insert_unsigned_integer_entry(struct bt_value *map_obj,
        enum bt_value_map_insert_entry_status ret;
        struct bt_value *integer_obj = NULL;
 
-       integer_obj = bt_value_unsigned_integer_create_init(val);
+       integer_obj = bt_value_integer_unsigned_create_init(val);
        ret = bt_value_map_insert_entry(map_obj, key,
                (void *) integer_obj);
        bt_object_put_ref(integer_obj);
@@ -1124,7 +1139,7 @@ bt_value_map_insert_signed_integer_entry(struct bt_value *map_obj,
        enum bt_value_map_insert_entry_status ret;
        struct bt_value *integer_obj = NULL;
 
-       integer_obj = bt_value_signed_integer_create_init(val);
+       integer_obj = bt_value_integer_signed_create_init(val);
        ret = bt_value_map_insert_entry(map_obj, key,
                (void *) integer_obj);
        bt_object_put_ref(integer_obj);
@@ -1160,7 +1175,8 @@ enum bt_value_map_insert_entry_status bt_value_map_insert_string_entry(
 
 enum bt_value_map_insert_entry_status
 bt_value_map_insert_empty_array_entry(
-               struct bt_value *map_obj, const char *key)
+               struct bt_value *map_obj, const char *key,
+               bt_value **entry_obj)
 {
        enum bt_value_map_insert_entry_status ret;
        struct bt_value *array_obj = NULL;
@@ -1168,12 +1184,18 @@ bt_value_map_insert_empty_array_entry(
        array_obj = bt_value_array_create();
        ret = bt_value_map_insert_entry(map_obj, key,
                (void *) array_obj);
+
+       if (entry_obj) {
+               *entry_obj = array_obj;
+       }
+
        bt_object_put_ref(array_obj);
        return ret;
 }
 
 enum bt_value_map_insert_entry_status
-bt_value_map_insert_empty_map_entry(struct bt_value *map_obj, const char *key)
+bt_value_map_insert_empty_map_entry(struct bt_value *map_obj, const char *key,
+               bt_value **entry_obj)
 {
        enum bt_value_map_insert_entry_status ret;
        struct bt_value *empty_map_obj = NULL;
@@ -1181,6 +1203,11 @@ bt_value_map_insert_empty_map_entry(struct bt_value *map_obj, const char *key)
        empty_map_obj = bt_value_map_create();
        ret = bt_value_map_insert_entry(map_obj, key,
                (void *) empty_map_obj);
+
+       if (entry_obj) {
+               *entry_obj = empty_map_obj;
+       }
+
        bt_object_put_ref(empty_map_obj);
        return ret;
 }
@@ -1203,10 +1230,10 @@ enum bt_value_map_foreach_entry_status bt_value_map_foreach_entry(
                const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
 
                if (!func(key_str, element_obj, data)) {
-                       BT_LOGT("User canceled the loop: key=\"%s\", "
+                       BT_LOGT("User interrupted the loop: key=\"%s\", "
                                "value-addr=%p, data=%p",
                                key_str, element_obj, data);
-                       ret = BT_FUNC_STATUS_CANCELED;
+                       ret = BT_FUNC_STATUS_INTERRUPTED;
                        break;
                }
        }
@@ -1355,7 +1382,7 @@ enum bt_value_copy_status bt_value_copy(const struct bt_value *object,
        return status;
 }
 
-bt_bool bt_value_compare(const struct bt_value *object_a,
+bt_bool bt_value_is_equal(const struct bt_value *object_a,
        const struct bt_value *object_b)
 {
        bt_bool ret = BT_FALSE;
@@ -1373,7 +1400,7 @@ bt_bool bt_value_compare(const struct bt_value *object_a,
                goto end;
        }
 
-       ret = compare_funcs[object_a->type](object_a, object_b);
+       ret = is_equal_funcs[object_a->type](object_a, object_b);
 
 end:
        return ret;
This page took 0.029113 seconds and 4 git commands to generate.