From: Philippe Proulx Date: Wed, 14 Feb 2018 19:53:36 +0000 (-0500) Subject: lib: add internal bt_field_type_structure_replace_field() X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=79422a2b1a3d14e130fd0fc34280ed62546ffba3 lib: add internal bt_field_type_structure_replace_field() This new internal function replaces the field type of a field identified by name within a structure field type. Signed-off-by: Philippe Proulx --- diff --git a/include/babeltrace/ctf-ir/field-types-internal.h b/include/babeltrace/ctf-ir/field-types-internal.h index 3d478ae7..fbe0bb78 100644 --- a/include/babeltrace/ctf-ir/field-types-internal.h +++ b/include/babeltrace/ctf-ir/field-types-internal.h @@ -179,6 +179,10 @@ BT_HIDDEN int bt_field_type_structure_get_field_name_index( struct bt_field_type *structure, const char *name); +BT_HIDDEN +int bt_field_type_structure_replace_field(struct bt_field_type *type, + const char *field_name, struct bt_field_type *field_type); + BT_HIDDEN int bt_field_type_variant_get_field_name_index( struct bt_field_type *variant, const char *name); diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index 62f2412b..ba288b2e 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -2006,6 +2006,35 @@ error: return NULL; } +BT_HIDDEN +int bt_field_type_structure_replace_field(struct bt_field_type *type, + const char *field_name, struct bt_field_type *field_type) +{ + int ret = 0; + struct bt_field_type_structure *structure; + GQuark name_quark; + uint64_t i; + + assert(type); + assert(field_name); + assert(field_type); + assert(type->id == BT_FIELD_TYPE_ID_STRUCT); + structure = container_of(type, struct bt_field_type_structure, parent); + name_quark = g_quark_from_string(field_name); + + for (i = 0; i < structure->fields->len; i++) { + struct structure_field *field = g_ptr_array_index( + structure->fields, i); + + if (field->name == name_quark) { + bt_put(field->type); + field->type = bt_get(field_type); + } + } + + return ret; +} + int bt_field_type_structure_add_field(struct bt_field_type *type, struct bt_field_type *field_type, const char *field_name)