2 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "LIB/VALUE"
24 #include "lib/logging.h"
30 #include "compat/compiler.h"
31 #include "common/common.h"
32 #include <babeltrace2/value-const.h>
33 #include <babeltrace2/value.h>
34 #include "compat/glib.h"
35 #include <babeltrace2/types.h>
36 #include "lib/assert-pre.h"
37 #include "lib/value.h"
38 #include "common/assert.h"
39 #include "func-status.h"
41 #define BT_VALUE_TO_BOOL(_base) ((struct bt_value_bool *) (_base))
42 #define BT_VALUE_TO_INTEGER(_base) ((struct bt_value_integer *) (_base))
43 #define BT_VALUE_TO_REAL(_base) ((struct bt_value_real *) (_base))
44 #define BT_VALUE_TO_STRING(_base) ((struct bt_value_string *) (_base))
45 #define BT_VALUE_TO_ARRAY(_base) ((struct bt_value_array *) (_base))
46 #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base))
48 #define BT_ASSERT_PRE_VALUE_IS_TYPE(_value, _type) \
49 BT_ASSERT_PRE(((struct bt_value *) (_value))->type == (_type), \
50 "Value has the wrong type ID: expected-type=%s, " \
51 "%![value-]+v", bt_common_value_type_string(_type), \
54 #define BT_ASSERT_PRE_VALUE_HOT(_value, _name) \
55 BT_ASSERT_PRE_HOT(((struct bt_value *) (_value)), (_name), \
58 #define BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(_index, _count) \
59 BT_ASSERT_PRE((_index) < (_count), \
60 "Index is out of bound: " \
61 "index=%" PRIu64 ", count=%u", (_index), (_count));
64 void bt_value_null_instance_release_func(struct bt_object
*obj
)
66 BT_LOGW("Releasing the null value singleton: addr=%p", obj
);
70 struct bt_value bt_value_null_instance
= {
74 .release_func
= bt_value_null_instance_release_func
,
75 .spec_release_func
= NULL
,
76 .parent_is_owner_listener_func
= NULL
,
79 .type
= BT_VALUE_TYPE_NULL
,
83 struct bt_value
*const bt_value_null
= &bt_value_null_instance
;
86 void bt_value_destroy(struct bt_object
*obj
);
89 void bt_value_string_destroy(struct bt_value
*object
)
91 g_string_free(BT_VALUE_TO_STRING(object
)->gstr
, TRUE
);
92 BT_VALUE_TO_STRING(object
)->gstr
= NULL
;
96 void bt_value_array_destroy(struct bt_value
*object
)
99 * Pointer array's registered value destructor will take care
100 * of putting each contained object.
102 g_ptr_array_free(BT_VALUE_TO_ARRAY(object
)->garray
, TRUE
);
103 BT_VALUE_TO_ARRAY(object
)->garray
= NULL
;
107 void bt_value_map_destroy(struct bt_value
*object
)
110 * Hash table's registered value destructor will take care of
111 * putting each contained object. Keys are GQuarks and cannot
112 * be destroyed anyway.
114 g_hash_table_destroy(BT_VALUE_TO_MAP(object
)->ght
);
115 BT_VALUE_TO_MAP(object
)->ght
= NULL
;
119 void (* const destroy_funcs
[])(struct bt_value
*) = {
120 [BT_VALUE_TYPE_NULL
] = NULL
,
121 [BT_VALUE_TYPE_BOOL
] = NULL
,
122 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = NULL
,
123 [BT_VALUE_TYPE_SIGNED_INTEGER
] = NULL
,
124 [BT_VALUE_TYPE_REAL
] = NULL
,
125 [BT_VALUE_TYPE_STRING
] = bt_value_string_destroy
,
126 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_destroy
,
127 [BT_VALUE_TYPE_MAP
] = bt_value_map_destroy
,
131 struct bt_value
*bt_value_null_copy(const struct bt_value
*null_obj
)
133 return (void *) bt_value_null
;
137 struct bt_value
*bt_value_bool_copy(const struct bt_value
*bool_obj
)
139 return bt_value_bool_create_init(
140 BT_VALUE_TO_BOOL(bool_obj
)->value
);
144 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
148 struct bt_value
*bt_value_integer_copy(
149 const struct bt_value
*integer_obj
)
151 return bt_value_integer_create_init(integer_obj
->type
,
152 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
);
156 struct bt_value
*bt_value_real_copy(const struct bt_value
*real_obj
)
158 return bt_value_real_create_init(
159 BT_VALUE_TO_REAL(real_obj
)->value
);
163 struct bt_value
*bt_value_string_copy(const struct bt_value
*string_obj
)
165 return bt_value_string_create_init(
166 BT_VALUE_TO_STRING(string_obj
)->gstr
->str
);
170 struct bt_value
*bt_value_array_copy(const struct bt_value
*array_obj
)
174 struct bt_value
*copy_obj
;
175 struct bt_value_array
*typed_array_obj
;
177 BT_LOGD("Copying array value: addr=%p", array_obj
);
178 typed_array_obj
= BT_VALUE_TO_ARRAY(array_obj
);
179 copy_obj
= bt_value_array_create();
181 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty array value.");
185 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
186 struct bt_value
*element_obj_copy
= NULL
;
187 const struct bt_value
*element_obj
=
188 bt_value_array_borrow_element_by_index_const(
191 BT_ASSERT(element_obj
);
192 BT_LOGD("Copying array value's element: element-addr=%p, "
193 "index=%d", element_obj
, i
);
194 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
196 BT_LIB_LOGE_APPEND_CAUSE(
197 "Cannot copy array value's element: "
198 "array-addr=%p, index=%d",
200 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
204 BT_ASSERT(element_obj_copy
);
205 ret
= bt_value_array_append_element(copy_obj
,
206 (void *) element_obj_copy
);
207 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
209 BT_LIB_LOGE_APPEND_CAUSE(
210 "Cannot append to array value: addr=%p",
212 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
217 BT_LOGD("Copied array value: original-addr=%p, copy-addr=%p",
218 array_obj
, copy_obj
);
225 struct bt_value
*bt_value_map_copy(const struct bt_value
*map_obj
)
229 gpointer key
, element_obj
;
230 struct bt_value
*copy_obj
;
231 struct bt_value
*element_obj_copy
= NULL
;
232 struct bt_value_map
*typed_map_obj
;
234 BT_LOGD("Copying map value: addr=%p", map_obj
);
235 typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
236 copy_obj
= bt_value_map_create();
241 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
243 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
244 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
247 BT_LOGD("Copying map value's element: element-addr=%p, "
248 "key=\"%s\"", element_obj
, key_str
);
249 ret
= bt_value_copy(element_obj
, &element_obj_copy
);
251 BT_LIB_LOGE_APPEND_CAUSE(
252 "Cannot copy map value's element: "
253 "map-addr=%p, key=\"%s\"",
255 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
259 BT_ASSERT(element_obj_copy
);
260 ret
= bt_value_map_insert_entry(copy_obj
, key_str
,
261 (void *) element_obj_copy
);
262 BT_OBJECT_PUT_REF_AND_RESET(element_obj_copy
);
264 BT_LIB_LOGE_APPEND_CAUSE(
265 "Cannot insert into map value: addr=%p, key=\"%s\"",
267 BT_OBJECT_PUT_REF_AND_RESET(copy_obj
);
272 BT_LOGD("Copied map value: addr=%p", map_obj
);
279 struct bt_value
*(* const copy_funcs
[])(const struct bt_value
*) = {
280 [BT_VALUE_TYPE_NULL
] = bt_value_null_copy
,
281 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_copy
,
282 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_copy
,
283 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_copy
,
284 [BT_VALUE_TYPE_REAL
] = bt_value_real_copy
,
285 [BT_VALUE_TYPE_STRING
] = bt_value_string_copy
,
286 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_copy
,
287 [BT_VALUE_TYPE_MAP
] = bt_value_map_copy
,
291 bt_bool
bt_value_null_compare(const struct bt_value
*object_a
,
292 const struct bt_value
*object_b
)
295 * Always BT_TRUE since bt_value_compare() already checks if both
296 * object_a and object_b have the same type, and in the case of
297 * null value objects, they're always the same if it is so.
303 bt_bool
bt_value_bool_compare(const struct bt_value
*object_a
,
304 const struct bt_value
*object_b
)
306 if (BT_VALUE_TO_BOOL(object_a
)->value
!=
307 BT_VALUE_TO_BOOL(object_b
)->value
) {
308 BT_LOGT("Boolean value objects are different: "
309 "bool-a-val=%d, bool-b-val=%d",
310 BT_VALUE_TO_BOOL(object_a
)->value
,
311 BT_VALUE_TO_BOOL(object_b
)->value
);
319 bt_bool
bt_value_integer_compare(const struct bt_value
*object_a
,
320 const struct bt_value
*object_b
)
322 if (BT_VALUE_TO_INTEGER(object_a
)->value
.u
!=
323 BT_VALUE_TO_INTEGER(object_b
)->value
.u
) {
324 if (object_a
->type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
325 BT_LOGT("Unsigned integer value objects are different: "
326 "int-a-val=%" PRIu64
", int-b-val=%" PRIu64
,
327 BT_VALUE_TO_INTEGER(object_a
)->value
.u
,
328 BT_VALUE_TO_INTEGER(object_b
)->value
.u
);
330 BT_LOGT("Signed integer value objects are different: "
331 "int-a-val=%" PRId64
", int-b-val=%" PRId64
,
332 BT_VALUE_TO_INTEGER(object_a
)->value
.i
,
333 BT_VALUE_TO_INTEGER(object_b
)->value
.i
);
343 bt_bool
bt_value_real_compare(const struct bt_value
*object_a
,
344 const struct bt_value
*object_b
)
346 if (BT_VALUE_TO_REAL(object_a
)->value
!=
347 BT_VALUE_TO_REAL(object_b
)->value
) {
348 BT_LOGT("Real number value objects are different: "
349 "real-a-val=%f, real-b-val=%f",
350 BT_VALUE_TO_REAL(object_a
)->value
,
351 BT_VALUE_TO_REAL(object_b
)->value
);
359 bt_bool
bt_value_string_compare(const struct bt_value
*object_a
,
360 const struct bt_value
*object_b
)
362 if (strcmp(BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
363 BT_VALUE_TO_STRING(object_b
)->gstr
->str
) != 0) {
364 BT_LOGT("String value objects are different: "
365 "string-a-val=\"%s\", string-b-val=\"%s\"",
366 BT_VALUE_TO_STRING(object_a
)->gstr
->str
,
367 BT_VALUE_TO_STRING(object_b
)->gstr
->str
);
375 bt_bool
bt_value_array_compare(const struct bt_value
*object_a
,
376 const struct bt_value
*object_b
)
379 bt_bool ret
= BT_TRUE
;
380 const struct bt_value_array
*array_obj_a
=
381 BT_VALUE_TO_ARRAY(object_a
);
383 if (bt_value_array_get_size(object_a
) !=
384 bt_value_array_get_size(object_b
)) {
385 BT_LOGT("Array values are different: size mismatch "
386 "value-a-addr=%p, value-b-addr=%p, "
387 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
389 bt_value_array_get_size(object_a
),
390 bt_value_array_get_size(object_b
));
395 for (i
= 0; i
< array_obj_a
->garray
->len
; ++i
) {
396 const struct bt_value
*element_obj_a
;
397 const struct bt_value
*element_obj_b
;
399 element_obj_a
= bt_value_array_borrow_element_by_index_const(
401 element_obj_b
= bt_value_array_borrow_element_by_index_const(
404 if (!bt_value_compare(element_obj_a
, element_obj_b
)) {
405 BT_LOGT("Array values's elements are different: "
406 "value-a-addr=%p, value-b-addr=%p, index=%d",
407 element_obj_a
, element_obj_b
, i
);
418 bt_bool
bt_value_map_compare(const struct bt_value
*object_a
,
419 const struct bt_value
*object_b
)
421 bt_bool ret
= BT_TRUE
;
423 gpointer key
, element_obj_a
;
424 const struct bt_value_map
*map_obj_a
= BT_VALUE_TO_MAP(object_a
);
426 if (bt_value_map_get_size(object_a
) !=
427 bt_value_map_get_size(object_b
)) {
428 BT_LOGT("Map values are different: size mismatch "
429 "value-a-addr=%p, value-b-addr=%p, "
430 "value-a-size=%" PRId64
", value-b-size=%" PRId64
,
432 bt_value_map_get_size(object_a
),
433 bt_value_map_get_size(object_b
));
438 g_hash_table_iter_init(&iter
, map_obj_a
->ght
);
440 while (g_hash_table_iter_next(&iter
, &key
, &element_obj_a
)) {
441 const struct bt_value
*element_obj_b
;
442 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
444 element_obj_b
= bt_value_map_borrow_entry_value_const(object_b
,
447 if (!bt_value_compare(element_obj_a
, element_obj_b
)) {
448 BT_LOGT("Map values's elements are different: "
449 "value-a-addr=%p, value-b-addr=%p, key=\"%s\"",
450 element_obj_a
, element_obj_b
, key_str
);
461 bt_bool (* const compare_funcs
[])(const struct bt_value
*,
462 const struct bt_value
*) = {
463 [BT_VALUE_TYPE_NULL
] = bt_value_null_compare
,
464 [BT_VALUE_TYPE_BOOL
] = bt_value_bool_compare
,
465 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_integer_compare
,
466 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_integer_compare
,
467 [BT_VALUE_TYPE_REAL
] = bt_value_real_compare
,
468 [BT_VALUE_TYPE_STRING
] = bt_value_string_compare
,
469 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_compare
,
470 [BT_VALUE_TYPE_MAP
] = bt_value_map_compare
,
474 void bt_value_null_freeze(struct bt_value
*object
)
479 void bt_value_generic_freeze(struct bt_value
*object
)
481 object
->frozen
= BT_TRUE
;
485 void bt_value_array_freeze(struct bt_value
*object
)
488 struct bt_value_array
*typed_array_obj
=
489 BT_VALUE_TO_ARRAY(object
);
491 for (i
= 0; i
< typed_array_obj
->garray
->len
; ++i
) {
492 bt_value_freeze(g_ptr_array_index(typed_array_obj
->garray
, i
));
495 bt_value_generic_freeze(object
);
499 void bt_value_map_freeze(struct bt_value
*object
)
502 gpointer key
, element_obj
;
503 const struct bt_value_map
*map_obj
= BT_VALUE_TO_MAP(object
);
505 g_hash_table_iter_init(&iter
, map_obj
->ght
);
507 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
508 bt_value_freeze(element_obj
);
511 bt_value_generic_freeze(object
);
515 void (* const freeze_funcs
[])(struct bt_value
*) = {
516 [BT_VALUE_TYPE_NULL
] = bt_value_null_freeze
,
517 [BT_VALUE_TYPE_BOOL
] = bt_value_generic_freeze
,
518 [BT_VALUE_TYPE_UNSIGNED_INTEGER
] = bt_value_generic_freeze
,
519 [BT_VALUE_TYPE_SIGNED_INTEGER
] = bt_value_generic_freeze
,
520 [BT_VALUE_TYPE_REAL
] = bt_value_generic_freeze
,
521 [BT_VALUE_TYPE_STRING
] = bt_value_generic_freeze
,
522 [BT_VALUE_TYPE_ARRAY
] = bt_value_array_freeze
,
523 [BT_VALUE_TYPE_MAP
] = bt_value_map_freeze
,
527 void bt_value_destroy(struct bt_object
*obj
)
529 struct bt_value
*value
;
531 value
= container_of(obj
, struct bt_value
, base
);
532 BT_LOGD("Destroying value: addr=%p", value
);
534 if (bt_value_is_null(value
)) {
535 BT_LOGD_STR("Not destroying the null value singleton.");
539 if (destroy_funcs
[value
->type
]) {
540 destroy_funcs
[value
->type
](value
);
547 void _bt_value_freeze(const struct bt_value
*c_object
)
549 const struct bt_value
*object
= (void *) c_object
;
553 if (object
->frozen
) {
557 BT_LOGD("Freezing value: addr=%p", object
);
558 freeze_funcs
[object
->type
]((void *) object
);
564 enum bt_value_type
bt_value_get_type(const struct bt_value
*object
)
566 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
571 struct bt_value
bt_value_create_base(enum bt_value_type type
)
573 struct bt_value value
;
576 value
.frozen
= BT_FALSE
;
577 bt_object_init_shared(&value
.base
, bt_value_destroy
);
581 struct bt_value
*bt_value_bool_create_init(bt_bool val
)
583 struct bt_value_bool
*bool_obj
;
585 BT_LOGD("Creating boolean value object: val=%d", val
);
586 bool_obj
= g_new0(struct bt_value_bool
, 1);
588 BT_LIB_LOGE_APPEND_CAUSE(
589 "Failed to allocate one boolean value object.");
593 bool_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_BOOL
);
594 bool_obj
->value
= val
;
595 BT_LOGD("Created boolean value object: addr=%p", bool_obj
);
598 return (void *) bool_obj
;
601 struct bt_value
*bt_value_bool_create(void)
603 return bt_value_bool_create_init(BT_FALSE
);
607 struct bt_value
*bt_value_integer_create_init(enum bt_value_type type
,
610 struct bt_value_integer
*integer_obj
;
612 BT_ASSERT(type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
||
613 type
== BT_VALUE_TYPE_SIGNED_INTEGER
);
615 if (type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
) {
616 BT_LOGD("Creating unsigned integer value object: val=%" PRIu64
,
619 BT_LOGD("Creating signed integer value object: val=%" PRId64
,
623 integer_obj
= g_new0(struct bt_value_integer
, 1);
625 BT_LIB_LOGE_APPEND_CAUSE(
626 "Failed to allocate one integer value object.");
630 integer_obj
->base
= bt_value_create_base(type
);
631 integer_obj
->value
.u
= uval
;
632 BT_LOGD("Created %ssigned integer value object: addr=%p",
633 type
== BT_VALUE_TYPE_UNSIGNED_INTEGER
? "un" : "",
637 return (void *) integer_obj
;
640 struct bt_value
*bt_value_unsigned_integer_create_init(uint64_t val
)
642 return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER
,
646 struct bt_value
*bt_value_unsigned_integer_create(void)
648 return bt_value_unsigned_integer_create_init(0);
651 struct bt_value
*bt_value_signed_integer_create_init(int64_t val
)
653 return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER
,
657 struct bt_value
*bt_value_signed_integer_create(void)
659 return bt_value_signed_integer_create_init(0);
662 struct bt_value
*bt_value_real_create_init(double val
)
664 struct bt_value_real
*real_obj
;
666 BT_LOGD("Creating real number value object: val=%f", val
);
667 real_obj
= g_new0(struct bt_value_real
, 1);
669 BT_LIB_LOGE_APPEND_CAUSE(
670 "Failed to allocate one real number value object.");
674 real_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_REAL
);
675 real_obj
->value
= val
;
676 BT_LOGD("Created real number value object: addr=%p",
680 return (void *) real_obj
;
683 struct bt_value
*bt_value_real_create(void)
685 return bt_value_real_create_init(0.);
688 struct bt_value
*bt_value_string_create_init(const char *val
)
690 struct bt_value_string
*string_obj
= NULL
;
692 BT_ASSERT_PRE_NON_NULL(val
, "Value");
693 BT_LOGD("Creating string value object: val-len=%zu", strlen(val
));
694 string_obj
= g_new0(struct bt_value_string
, 1);
696 BT_LIB_LOGE_APPEND_CAUSE(
697 "Failed to allocate one string object.");
701 string_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_STRING
);
702 string_obj
->gstr
= g_string_new(val
);
703 if (!string_obj
->gstr
) {
704 BT_LIB_LOGE_APPEND_CAUSE(
705 "Failed to allocate a GString.");
711 BT_LOGD("Created string value object: addr=%p",
715 return (void *) string_obj
;
718 struct bt_value
*bt_value_string_create(void)
720 return bt_value_string_create_init("");
723 struct bt_value
*bt_value_array_create(void)
725 struct bt_value_array
*array_obj
;
727 BT_LOGD_STR("Creating empty array value object.");
728 array_obj
= g_new0(struct bt_value_array
, 1);
730 BT_LIB_LOGE_APPEND_CAUSE(
731 "Failed to allocate one array object.");
735 array_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_ARRAY
);
736 array_obj
->garray
= bt_g_ptr_array_new_full(0,
737 (GDestroyNotify
) bt_object_put_ref
);
738 if (!array_obj
->garray
) {
739 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
745 BT_LOGD("Created array value object: addr=%p",
749 return (void *) array_obj
;
752 struct bt_value
*bt_value_map_create(void)
754 struct bt_value_map
*map_obj
;
756 BT_LOGD_STR("Creating empty map value object.");
757 map_obj
= g_new0(struct bt_value_map
, 1);
759 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one map object.");
763 map_obj
->base
= bt_value_create_base(BT_VALUE_TYPE_MAP
);
764 map_obj
->ght
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
765 NULL
, (GDestroyNotify
) bt_object_put_ref
);
767 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
773 BT_LOGD("Created map value object: addr=%p",
777 return (void *) map_obj
;
780 bt_bool
bt_value_bool_get(const struct bt_value
*bool_obj
)
782 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
783 BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
784 return BT_VALUE_TO_BOOL(bool_obj
)->value
;
787 void bt_value_bool_set(struct bt_value
*bool_obj
, bt_bool val
)
789 BT_ASSERT_PRE_NON_NULL(bool_obj
, "Value object");
790 BT_ASSERT_PRE_VALUE_IS_TYPE(bool_obj
, BT_VALUE_TYPE_BOOL
);
791 BT_ASSERT_PRE_VALUE_HOT(bool_obj
, "Value object");
792 BT_VALUE_TO_BOOL(bool_obj
)->value
= val
;
793 BT_LOGT("Set boolean value's raw value: value-addr=%p, value=%d",
797 uint64_t bt_value_unsigned_integer_get(const struct bt_value
*integer_obj
)
799 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
800 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
,
801 BT_VALUE_TYPE_UNSIGNED_INTEGER
);
802 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
;
805 int64_t bt_value_signed_integer_get(const struct bt_value
*integer_obj
)
807 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
808 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
,
809 BT_VALUE_TYPE_SIGNED_INTEGER
);
810 return BT_VALUE_TO_INTEGER(integer_obj
)->value
.i
;
814 void bt_value_integer_set(struct bt_value
*integer_obj
,
815 enum bt_value_type expected_type
, uint64_t uval
)
817 BT_ASSERT_PRE_NON_NULL(integer_obj
, "Value object");
818 BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj
, expected_type
);
819 BT_ASSERT_PRE_VALUE_HOT(integer_obj
, "Value object");
820 BT_VALUE_TO_INTEGER(integer_obj
)->value
.u
= uval
;
823 void bt_value_unsigned_integer_set(struct bt_value
*integer_obj
,
826 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_UNSIGNED_INTEGER
, val
);
827 BT_LOGT("Set unsigned integer value's raw value: "
828 "value-addr=%p, value=%" PRIu64
, integer_obj
, val
);
831 void bt_value_signed_integer_set(struct bt_value
*integer_obj
,
834 bt_value_integer_set(integer_obj
, BT_VALUE_TYPE_SIGNED_INTEGER
,
836 BT_LOGT("Set signed integer value's raw value: "
837 "value-addr=%p, value=%" PRId64
, integer_obj
, val
);
840 double bt_value_real_get(const struct bt_value
*real_obj
)
842 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
843 BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
844 return BT_VALUE_TO_REAL(real_obj
)->value
;
847 void bt_value_real_set(struct bt_value
*real_obj
, double val
)
849 BT_ASSERT_PRE_NON_NULL(real_obj
, "Value object");
850 BT_ASSERT_PRE_VALUE_IS_TYPE(real_obj
, BT_VALUE_TYPE_REAL
);
851 BT_ASSERT_PRE_VALUE_HOT(real_obj
, "Value object");
852 BT_VALUE_TO_REAL(real_obj
)->value
= val
;
853 BT_LOGT("Set real number value's raw value: value-addr=%p, value=%f",
857 const char *bt_value_string_get(const struct bt_value
*string_obj
)
859 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
860 BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
861 return BT_VALUE_TO_STRING(string_obj
)->gstr
->str
;
864 enum bt_value_string_set_status
bt_value_string_set(
865 struct bt_value
*string_obj
, const char *val
)
867 BT_ASSERT_PRE_NON_NULL(string_obj
, "Value object");
868 BT_ASSERT_PRE_VALUE_IS_TYPE(string_obj
, BT_VALUE_TYPE_STRING
);
869 BT_ASSERT_PRE_VALUE_HOT(string_obj
, "Value object");
870 g_string_assign(BT_VALUE_TO_STRING(string_obj
)->gstr
, val
);
871 BT_LOGT("Set string value's raw value: value-addr=%p, raw-value-addr=%p",
873 return BT_FUNC_STATUS_OK
;
876 uint64_t bt_value_array_get_size(const struct bt_value
*array_obj
)
878 BT_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
879 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
880 return (uint64_t) BT_VALUE_TO_ARRAY(array_obj
)->garray
->len
;
883 struct bt_value
*bt_value_array_borrow_element_by_index(
884 struct bt_value
*array_obj
, uint64_t index
)
886 struct bt_value_array
*typed_array_obj
=
887 BT_VALUE_TO_ARRAY(array_obj
);
889 BT_ASSERT_PRE_NON_NULL(array_obj
, "Value object");
890 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
891 BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
892 typed_array_obj
->garray
->len
);
893 return g_ptr_array_index(typed_array_obj
->garray
, index
);
896 const struct bt_value
*bt_value_array_borrow_element_by_index_const(
897 const struct bt_value
*array_obj
,
900 return bt_value_array_borrow_element_by_index(
901 (void *) array_obj
, index
);
904 enum bt_value_array_append_element_status
bt_value_array_append_element(
905 struct bt_value
*array_obj
,
906 struct bt_value
*element_obj
)
908 struct bt_value_array
*typed_array_obj
=
909 BT_VALUE_TO_ARRAY(array_obj
);
911 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
912 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
913 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
914 BT_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
915 g_ptr_array_add(typed_array_obj
->garray
, element_obj
);
916 bt_object_get_ref(element_obj
);
917 BT_LOGT("Appended element to array value: array-value-addr=%p, "
918 "element-value-addr=%p, new-size=%u",
919 array_obj
, element_obj
, typed_array_obj
->garray
->len
);
920 return BT_FUNC_STATUS_OK
;
923 enum bt_value_array_append_element_status
924 bt_value_array_append_bool_element(struct bt_value
*array_obj
, bt_bool val
)
926 enum bt_value_array_append_element_status ret
;
927 struct bt_value
*bool_obj
= NULL
;
929 bool_obj
= bt_value_bool_create_init(val
);
930 ret
= bt_value_array_append_element(array_obj
,
932 bt_object_put_ref(bool_obj
);
936 enum bt_value_array_append_element_status
937 bt_value_array_append_unsigned_integer_element(struct bt_value
*array_obj
,
940 enum bt_value_array_append_element_status ret
;
941 struct bt_value
*integer_obj
= NULL
;
943 integer_obj
= bt_value_unsigned_integer_create_init(val
);
944 ret
= bt_value_array_append_element(array_obj
,
945 (void *) integer_obj
);
946 bt_object_put_ref(integer_obj
);
950 enum bt_value_array_append_element_status
951 bt_value_array_append_signed_integer_element(struct bt_value
*array_obj
,
954 enum bt_value_array_append_element_status ret
;
955 struct bt_value
*integer_obj
= NULL
;
957 integer_obj
= bt_value_signed_integer_create_init(val
);
958 ret
= bt_value_array_append_element(array_obj
,
959 (void *) integer_obj
);
960 bt_object_put_ref(integer_obj
);
964 enum bt_value_array_append_element_status
965 bt_value_array_append_real_element(struct bt_value
*array_obj
, double val
)
967 enum bt_value_array_append_element_status ret
;
968 struct bt_value
*real_obj
= NULL
;
970 real_obj
= bt_value_real_create_init(val
);
971 ret
= bt_value_array_append_element(array_obj
,
973 bt_object_put_ref(real_obj
);
977 enum bt_value_array_append_element_status
978 bt_value_array_append_string_element(struct bt_value
*array_obj
,
981 enum bt_value_array_append_element_status ret
;
982 struct bt_value
*string_obj
= NULL
;
984 string_obj
= bt_value_string_create_init(val
);
985 ret
= bt_value_array_append_element(array_obj
,
986 (void *) string_obj
);
987 bt_object_put_ref(string_obj
);
991 enum bt_value_array_append_element_status
992 bt_value_array_append_empty_array_element(struct bt_value
*array_obj
)
994 enum bt_value_array_append_element_status ret
;
995 struct bt_value
*empty_array_obj
= NULL
;
997 empty_array_obj
= bt_value_array_create();
998 ret
= bt_value_array_append_element(array_obj
,
999 (void *) empty_array_obj
);
1000 bt_object_put_ref(empty_array_obj
);
1004 enum bt_value_array_append_element_status
1005 bt_value_array_append_empty_map_element(struct bt_value
*array_obj
)
1007 enum bt_value_array_append_element_status ret
;
1008 struct bt_value
*map_obj
= NULL
;
1010 map_obj
= bt_value_map_create();
1011 ret
= bt_value_array_append_element(array_obj
,
1013 bt_object_put_ref(map_obj
);
1017 enum bt_value_array_set_element_by_index_status
1018 bt_value_array_set_element_by_index(struct bt_value
*array_obj
, uint64_t index
,
1019 struct bt_value
*element_obj
)
1021 struct bt_value_array
*typed_array_obj
=
1022 BT_VALUE_TO_ARRAY(array_obj
);
1024 BT_ASSERT_PRE_NON_NULL(array_obj
, "Array value object");
1025 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1026 BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj
, BT_VALUE_TYPE_ARRAY
);
1027 BT_ASSERT_PRE_VALUE_HOT(array_obj
, "Array value object");
1028 BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index
,
1029 typed_array_obj
->garray
->len
);
1030 bt_object_put_ref(g_ptr_array_index(typed_array_obj
->garray
, index
));
1031 g_ptr_array_index(typed_array_obj
->garray
, index
) = element_obj
;
1032 bt_object_get_ref(element_obj
);
1033 BT_LOGT("Set array value's element: array-value-addr=%p, "
1034 "index=%" PRIu64
", element-value-addr=%p",
1035 array_obj
, index
, element_obj
);
1036 return BT_FUNC_STATUS_OK
;
1039 uint64_t bt_value_map_get_size(const struct bt_value
*map_obj
)
1041 BT_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1042 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1043 return (uint64_t) g_hash_table_size(BT_VALUE_TO_MAP(map_obj
)->ght
);
1046 struct bt_value
*bt_value_map_borrow_entry_value(struct bt_value
*map_obj
,
1049 BT_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1050 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1051 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1052 return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj
)->ght
,
1053 GUINT_TO_POINTER(g_quark_from_string(key
)));
1056 const struct bt_value
*bt_value_map_borrow_entry_value_const(
1057 const struct bt_value
*map_obj
, const char *key
)
1059 return bt_value_map_borrow_entry_value((void *) map_obj
, key
);
1062 bt_bool
bt_value_map_has_entry(const struct bt_value
*map_obj
, const char *key
)
1064 BT_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1065 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1066 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1067 return bt_g_hash_table_contains(BT_VALUE_TO_MAP(map_obj
)->ght
,
1068 GUINT_TO_POINTER(g_quark_from_string(key
)));
1071 enum bt_value_map_insert_entry_status
bt_value_map_insert_entry(
1072 struct bt_value
*map_obj
, const char *key
,
1073 struct bt_value
*element_obj
)
1075 BT_ASSERT_PRE_NON_NULL(map_obj
, "Map value object");
1076 BT_ASSERT_PRE_NON_NULL(key
, "Key");
1077 BT_ASSERT_PRE_NON_NULL(element_obj
, "Element value object");
1078 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1079 BT_ASSERT_PRE_VALUE_HOT(map_obj
, "Map value object");
1080 g_hash_table_insert(BT_VALUE_TO_MAP(map_obj
)->ght
,
1081 GUINT_TO_POINTER(g_quark_from_string(key
)), element_obj
);
1082 bt_object_get_ref(element_obj
);
1083 BT_LOGT("Inserted value into map value: map-value-addr=%p, "
1084 "key=\"%s\", element-value-addr=%p",
1085 map_obj
, key
, element_obj
);
1086 return BT_FUNC_STATUS_OK
;
1089 enum bt_value_map_insert_entry_status
bt_value_map_insert_bool_entry(
1090 struct bt_value
*map_obj
, const char *key
, bt_bool val
)
1092 enum bt_value_map_insert_entry_status ret
;
1093 struct bt_value
*bool_obj
= NULL
;
1095 bool_obj
= bt_value_bool_create_init(val
);
1096 ret
= bt_value_map_insert_entry(map_obj
, key
,
1098 bt_object_put_ref(bool_obj
);
1102 enum bt_value_map_insert_entry_status
1103 bt_value_map_insert_unsigned_integer_entry(struct bt_value
*map_obj
,
1104 const char *key
, uint64_t val
)
1106 enum bt_value_map_insert_entry_status ret
;
1107 struct bt_value
*integer_obj
= NULL
;
1109 integer_obj
= bt_value_unsigned_integer_create_init(val
);
1110 ret
= bt_value_map_insert_entry(map_obj
, key
,
1111 (void *) integer_obj
);
1112 bt_object_put_ref(integer_obj
);
1116 enum bt_value_map_insert_entry_status
1117 bt_value_map_insert_signed_integer_entry(struct bt_value
*map_obj
,
1118 const char *key
, int64_t val
)
1120 enum bt_value_map_insert_entry_status ret
;
1121 struct bt_value
*integer_obj
= NULL
;
1123 integer_obj
= bt_value_signed_integer_create_init(val
);
1124 ret
= bt_value_map_insert_entry(map_obj
, key
,
1125 (void *) integer_obj
);
1126 bt_object_put_ref(integer_obj
);
1130 enum bt_value_map_insert_entry_status
bt_value_map_insert_real_entry(
1131 struct bt_value
*map_obj
, const char *key
, double val
)
1133 enum bt_value_map_insert_entry_status ret
;
1134 struct bt_value
*real_obj
= NULL
;
1136 real_obj
= bt_value_real_create_init(val
);
1137 ret
= bt_value_map_insert_entry(map_obj
, key
,
1139 bt_object_put_ref(real_obj
);
1143 enum bt_value_map_insert_entry_status
bt_value_map_insert_string_entry(
1144 struct bt_value
*map_obj
, const char *key
,
1147 enum bt_value_map_insert_entry_status ret
;
1148 struct bt_value
*string_obj
= NULL
;
1150 string_obj
= bt_value_string_create_init(val
);
1151 ret
= bt_value_map_insert_entry(map_obj
, key
,
1152 (void *) string_obj
);
1153 bt_object_put_ref(string_obj
);
1157 enum bt_value_map_insert_entry_status
1158 bt_value_map_insert_empty_array_entry(
1159 struct bt_value
*map_obj
, const char *key
)
1161 enum bt_value_map_insert_entry_status ret
;
1162 struct bt_value
*array_obj
= NULL
;
1164 array_obj
= bt_value_array_create();
1165 ret
= bt_value_map_insert_entry(map_obj
, key
,
1166 (void *) array_obj
);
1167 bt_object_put_ref(array_obj
);
1171 enum bt_value_map_insert_entry_status
1172 bt_value_map_insert_empty_map_entry(struct bt_value
*map_obj
, const char *key
)
1174 enum bt_value_map_insert_entry_status ret
;
1175 struct bt_value
*empty_map_obj
= NULL
;
1177 empty_map_obj
= bt_value_map_create();
1178 ret
= bt_value_map_insert_entry(map_obj
, key
,
1179 (void *) empty_map_obj
);
1180 bt_object_put_ref(empty_map_obj
);
1184 enum bt_value_map_foreach_entry_status
bt_value_map_foreach_entry(
1185 struct bt_value
*map_obj
, bt_value_map_foreach_entry_func func
,
1188 enum bt_value_map_foreach_entry_status ret
= BT_FUNC_STATUS_OK
;
1189 gpointer key
, element_obj
;
1190 GHashTableIter iter
;
1191 struct bt_value_map
*typed_map_obj
= BT_VALUE_TO_MAP(map_obj
);
1193 BT_ASSERT_PRE_NON_NULL(map_obj
, "Value object");
1194 BT_ASSERT_PRE_NON_NULL(func
, "Callback");
1195 BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj
, BT_VALUE_TYPE_MAP
);
1196 g_hash_table_iter_init(&iter
, typed_map_obj
->ght
);
1198 while (g_hash_table_iter_next(&iter
, &key
, &element_obj
)) {
1199 const char *key_str
= g_quark_to_string(GPOINTER_TO_UINT(key
));
1201 if (!func(key_str
, element_obj
, data
)) {
1202 BT_LOGT("User canceled the loop: key=\"%s\", "
1203 "value-addr=%p, data=%p",
1204 key_str
, element_obj
, data
);
1205 ret
= BT_FUNC_STATUS_CANCELED
;
1213 enum bt_value_map_foreach_entry_const_status
bt_value_map_foreach_entry_const(
1214 const struct bt_value
*map_obj
,
1215 bt_value_map_foreach_entry_const_func func
, void *data
)
1217 return (int) bt_value_map_foreach_entry((void *) map_obj
,
1218 (bt_value_map_foreach_entry_func
) func
, data
);
1221 struct extend_map_element_data
{
1222 struct bt_value
*extended_obj
;
1227 bt_bool
extend_map_element(const char *key
,
1228 const struct bt_value
*extension_obj_elem
, void *data
)
1230 bt_bool ret
= BT_TRUE
;
1231 struct extend_map_element_data
*extend_data
= data
;
1232 struct bt_value
*extension_obj_elem_copy
= NULL
;
1234 /* Copy object which is to replace the current one */
1235 extend_data
->status
= bt_value_copy(extension_obj_elem
,
1236 &extension_obj_elem_copy
);
1237 if (extend_data
->status
) {
1238 BT_LIB_LOGE_APPEND_CAUSE("Cannot copy map element: %!+v",
1239 extension_obj_elem
);
1243 BT_ASSERT(extension_obj_elem_copy
);
1245 /* Replace in extended object */
1246 extend_data
->status
= bt_value_map_insert_entry(
1247 extend_data
->extended_obj
, key
,
1248 (void *) extension_obj_elem_copy
);
1249 if (extend_data
->status
) {
1250 BT_LIB_LOGE_APPEND_CAUSE(
1251 "Cannot replace value in extended value: key=\"%s\", "
1252 "%![extended-value-]+v, %![element-value-]+v",
1253 key
, extend_data
->extended_obj
,
1254 extension_obj_elem_copy
);
1261 BT_ASSERT(extend_data
->status
!= BT_FUNC_STATUS_OK
);
1265 BT_OBJECT_PUT_REF_AND_RESET(extension_obj_elem_copy
);
1269 enum bt_value_map_extend_status
bt_value_map_extend(
1270 const struct bt_value
*base_map_obj
,
1271 const struct bt_value
*extension_obj
,
1272 struct bt_value
**extended_map_obj
)
1274 struct extend_map_element_data extend_data
= {
1275 .extended_obj
= NULL
,
1276 .status
= BT_FUNC_STATUS_OK
,
1279 BT_ASSERT_PRE_NON_NULL(base_map_obj
, "Base value object");
1280 BT_ASSERT_PRE_NON_NULL(extension_obj
, "Extension value object");
1281 BT_ASSERT_PRE_NON_NULL(extended_map_obj
,
1282 "Extended value object (output)");
1283 BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj
, BT_VALUE_TYPE_MAP
);
1284 BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj
, BT_VALUE_TYPE_MAP
);
1285 BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
1286 base_map_obj
, extension_obj
);
1287 *extended_map_obj
= NULL
;
1289 /* Create copy of base map object to start with */
1290 extend_data
.status
= bt_value_copy(base_map_obj
, extended_map_obj
);
1291 if (extend_data
.status
) {
1292 BT_LIB_LOGE_APPEND_CAUSE(
1293 "Cannot copy base value: %![base-value-]+v",
1298 BT_ASSERT(extended_map_obj
);
1301 * For each key in the extension map object, replace this key
1302 * in the copied map object.
1304 extend_data
.extended_obj
= *extended_map_obj
;
1306 if (bt_value_map_foreach_entry_const(extension_obj
, extend_map_element
,
1308 BT_LIB_LOGE_APPEND_CAUSE(
1309 "Cannot iterate on the extension object's elements: "
1310 "%![extension-value-]+v", extension_obj
);
1314 if (extend_data
.status
) {
1315 BT_LIB_LOGE_APPEND_CAUSE(
1316 "Failed to successfully iterate on the extension object's elements: "
1317 "%![extension-value-]+v", extension_obj
);
1321 BT_LOGD("Extended map value: extended-value-addr=%p",
1326 BT_OBJECT_PUT_REF_AND_RESET(*extended_map_obj
);
1327 *extended_map_obj
= NULL
;
1330 return extend_data
.status
;
1333 enum bt_value_copy_status
bt_value_copy(const struct bt_value
*object
,
1334 struct bt_value
**copy_obj
)
1336 enum bt_value_copy_status status
= BT_FUNC_STATUS_OK
;
1338 BT_ASSERT_PRE_NON_NULL(object
, "Value object");
1339 BT_ASSERT_PRE_NON_NULL(copy_obj
, "Value object copy (output)");
1340 BT_LOGD("Copying value object: addr=%p", object
);
1341 *copy_obj
= copy_funcs
[object
->type
](object
);
1343 BT_LOGD("Copied value object: copy-value-addr=%p",
1346 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1348 BT_LIB_LOGE_APPEND_CAUSE("Failed to copy value object.");
1354 bt_bool
bt_value_compare(const struct bt_value
*object_a
,
1355 const struct bt_value
*object_b
)
1357 bt_bool ret
= BT_FALSE
;
1359 BT_ASSERT_PRE_NON_NULL(object_a
, "Value object A");
1360 BT_ASSERT_PRE_NON_NULL(object_b
, "Value object B");
1362 if (object_a
->type
!= object_b
->type
) {
1363 BT_LOGT("Values are different: type mismatch: "
1364 "value-a-addr=%p, value-b-addr=%p, "
1365 "value-a-type=%s, value-b-type=%s",
1367 bt_common_value_type_string(object_a
->type
),
1368 bt_common_value_type_string(object_b
->type
));
1372 ret
= compare_funcs
[object_a
->type
](object_a
, object_b
);
1378 void bt_value_get_ref(const struct bt_value
*value
)
1380 bt_object_get_ref(value
);
1383 void bt_value_put_ref(const struct bt_value
*value
)
1385 bt_object_put_ref(value
);