const bt_value *object, void *data);
typedef enum bt_value_map_foreach_entry_const_status {
- BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_OK = __BT_FUNC_STATUS_OK,
BT_VALUE_MAP_FOREACH_ENTRY_CONST_STATUS_INTERRUPTED = __BT_FUNC_STATUS_INTERRUPTED,
} bt_value_map_foreach_entry_const_status;
extern bt_bool bt_value_map_has_entry(const bt_value *map_obj,
const char *key);
-typedef enum bt_value_map_extend_status {
- BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
- BT_VALUE_MAP_EXTEND_STATUS_OK = __BT_FUNC_STATUS_OK,
-} bt_value_map_extend_status;
-
-extern bt_value_map_extend_status bt_value_map_extend(
- const bt_value *base_map_obj,
- const bt_value *extension_map_obj,
- bt_value **extended_map_obj);
-
extern void bt_value_get_ref(const bt_value *value);
extern void bt_value_put_ref(const bt_value *value);
bt_value *object, void *data);
typedef enum bt_value_map_foreach_entry_status {
- BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK = __BT_FUNC_STATUS_OK,
BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED = __BT_FUNC_STATUS_INTERRUPTED,
} bt_value_map_foreach_entry_status;
bt_value_map_insert_empty_map_entry(bt_value *map_obj, const char *key,
bt_value **entry_obj);
+typedef enum bt_value_map_extend_status {
+ BT_VALUE_MAP_EXTEND_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
+ BT_VALUE_MAP_EXTEND_STATUS_OK = __BT_FUNC_STATUS_OK,
+} bt_value_map_extend_status;
+
+extern bt_value_map_extend_status bt_value_map_extend(
+ bt_value *base_map_obj,
+ const bt_value *extension_map_obj);
+
#ifdef __cplusplus
}
#endif
}
struct extend_map_element_data {
- struct bt_value *extended_obj;
+ struct bt_value *base_obj;
int status;
};
BT_ASSERT(extension_obj_elem_copy);
- /* Replace in extended object */
+ /* Replace in base map value. */
extend_data->status = bt_value_map_insert_entry(
- extend_data->extended_obj, key,
+ extend_data->base_obj, key,
(void *) extension_obj_elem_copy);
if (extend_data->status) {
BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot replace value in extended value: key=\"%s\", "
- "%![extended-value-]+v, %![element-value-]+v",
- key, extend_data->extended_obj,
+ "Cannot replace value in base map value: key=\"%s\", "
+ "%![base-map-value-]+v, %![element-value-]+v",
+ key, extend_data->base_obj,
extension_obj_elem_copy);
goto error;
}
}
enum bt_value_map_extend_status bt_value_map_extend(
- const struct bt_value *base_map_obj,
- const struct bt_value *extension_obj,
- struct bt_value **extended_map_obj)
+ struct bt_value *base_map_obj,
+ const struct bt_value *extension_obj)
{
struct extend_map_element_data extend_data = {
- .extended_obj = NULL,
+ .base_obj = NULL,
.status = BT_FUNC_STATUS_OK,
};
BT_ASSERT_PRE_NON_NULL(base_map_obj, "Base value object");
+ BT_ASSERT_PRE_DEV_VALUE_HOT(base_map_obj, "Base value object");
BT_ASSERT_PRE_NON_NULL(extension_obj, "Extension value object");
- BT_ASSERT_PRE_NON_NULL(extended_map_obj,
- "Extended value object (output)");
BT_ASSERT_PRE_VALUE_IS_TYPE(base_map_obj, BT_VALUE_TYPE_MAP);
BT_ASSERT_PRE_VALUE_IS_TYPE(extension_obj, BT_VALUE_TYPE_MAP);
BT_LOGD("Extending map value: base-value-addr=%p, extension-value-addr=%p",
base_map_obj, extension_obj);
- *extended_map_obj = NULL;
-
- /* Create copy of base map object to start with */
- extend_data.status = bt_value_copy(base_map_obj, extended_map_obj);
- if (extend_data.status) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Cannot copy base value: %![base-value-]+v",
- base_map_obj);
- goto error;
- }
-
- BT_ASSERT(extended_map_obj);
/*
* For each key in the extension map object, replace this key
- * in the copied map object.
+ * in the base map object.
*/
- extend_data.extended_obj = *extended_map_obj;
+ extend_data.base_obj = base_map_obj;
if (bt_value_map_foreach_entry_const(extension_obj, extend_map_element,
&extend_data)) {
BT_LIB_LOGE_APPEND_CAUSE(
"Cannot iterate on the extension object's elements: "
"%![extension-value-]+v", extension_obj);
- goto error;
- }
-
- if (extend_data.status) {
- BT_LIB_LOGE_APPEND_CAUSE(
- "Failed to successfully iterate on the extension object's elements: "
- "%![extension-value-]+v", extension_obj);
- goto error;
}
- BT_LOGD("Extended map value: extended-value-addr=%p",
- *extended_map_obj);
- goto end;
-
-error:
- BT_OBJECT_PUT_REF_AND_RESET(*extended_map_obj);
- *extended_map_obj = NULL;
-
-end:
return extend_data.status;
}
bt_value *extended_map = NULL;
bt_value *array = bt_value_array_create();
bt_value_map_insert_entry_status insert_status;
+ bt_value_copy_status copy_status;
bt_value_map_extend_status extend_status;
BT_ASSERT(base_map);
insert_status = bt_value_map_insert_real_entry(extension_map,
"project", -404);
BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
- extend_status = bt_value_map_extend(base_map, extension_map, &extended_map);
+ copy_status = bt_value_copy(base_map, &extended_map);
+ BT_ASSERT(copy_status == BT_VALUE_COPY_STATUS_OK);
+ extend_status = bt_value_map_extend(extended_map, extension_map);
ok(extend_status == BT_VALUE_MAP_EXTEND_STATUS_OK &&
extended_map, "bt_value_map_extend() succeeds");
ok(bt_value_map_get_size(extended_map) == 5,