From: Philippe Proulx Date: Wed, 17 Jul 2019 22:12:39 +0000 (-0400) Subject: lib: bt_field_class_dynamic_array_create(): accept length FC parameter X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=1367bc7ce5e43057c3a2c00a8f4fa2130259ea76 lib: bt_field_class_dynamic_array_create(): accept length FC parameter This patch makes bt_field_class_dynamic_array_create() similar to bt_field_class_variant_with_selector_create() for consistency: it accepts the length field class on creation instead of setting it afterwards. You can pass `NULL` to create a dynamic array field class without a length field class. Signed-off-by: Philippe Proulx Change-Id: Ib94adcc32128154b5979120ef0623be912f28734 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1718 Tested-by: jenkins --- diff --git a/include/babeltrace2/trace-ir/field-class.h b/include/babeltrace2/trace-ir/field-class.h index a8c3feaf..ec4456f6 100644 --- a/include/babeltrace2/trace-ir/field-class.h +++ b/include/babeltrace2/trace-ir/field-class.h @@ -107,21 +107,12 @@ extern bt_field_class *bt_field_class_static_array_create( extern bt_field_class *bt_field_class_dynamic_array_create( bt_trace_class *trace_class, - bt_field_class *elem_field_class); + bt_field_class *elem_field_class, + bt_field_class *length_field_class); extern bt_field_class *bt_field_class_array_borrow_element_field_class( bt_field_class *field_class); -typedef enum bt_field_class_dynamic_array_set_length_field_class_status { - BT_FIELD_CLASS_DYNAMIC_ARRAY_SET_LENGTH_FIELD_CLASS_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR, - BT_FIELD_CLASS_DYNAMIC_ARRAY_SET_LENGTH_FIELD_CLASS_STATUS_OK = __BT_FUNC_STATUS_OK, -} bt_field_class_dynamic_array_set_length_field_class_status; - -extern bt_field_class_dynamic_array_set_length_field_class_status -bt_field_class_dynamic_array_set_length_field_class( - bt_field_class *field_class, - bt_field_class *length_field_class); - extern bt_field_class *bt_field_class_variant_create( bt_trace_class *trace_class, bt_field_class *selector_field_class); diff --git a/src/bindings/python/bt2/bt2/field_class.py b/src/bindings/python/bt2/bt2/field_class.py index 0ccea041..80936539 100644 --- a/src/bindings/python/bt2/bt2/field_class.py +++ b/src/bindings/python/bt2/bt2/field_class.py @@ -501,14 +501,6 @@ class _DynamicArrayFieldClass(_ArrayFieldClass): return bt2.field_path._FieldPath._create_from_ptr_and_get_ref(ptr) - def _set_length_field_class(self, length_fc): - utils._check_type(length_fc, _UnsignedIntegerFieldClass) - status = native_bt.field_class_dynamic_array_set_length_field_class(self._ptr, length_fc._ptr) - utils._handle_func_status(status, - "cannot set dynamic array length field type") - - _length_field_class = property(fset=_set_length_field_class) - _FIELD_CLASS_TYPE_TO_OBJ = { native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClass, diff --git a/src/bindings/python/bt2/bt2/trace_class.py b/src/bindings/python/bt2/bt2/trace_class.py index d5f63712..fb0eb543 100644 --- a/src/bindings/python/bt2/bt2/trace_class.py +++ b/src/bindings/python/bt2/bt2/trace_class.py @@ -252,14 +252,15 @@ class _TraceClass(object._SharedObject, collections.abc.Mapping): def create_dynamic_array_field_class(self, elem_fc, length_fc=None): utils._check_type(elem_fc, bt2.field_class._FieldClass) - ptr = native_bt.field_class_dynamic_array_create(self._ptr, elem_fc._ptr) - self._check_create_status(ptr, 'dynamic array') - obj = bt2.field_class._DynamicArrayFieldClass._create_from_ptr(ptr) + length_fc_ptr = None if length_fc is not None: - obj._length_field_class = length_fc + utils._check_type(length_fc, bt2.field_class._UnsignedIntegerFieldClass) + length_fc_ptr = length_fc._ptr - return obj + ptr = native_bt.field_class_dynamic_array_create(self._ptr, elem_fc._ptr, length_fc_ptr) + self._check_create_status(ptr, 'dynamic array') + return bt2.field_class._DynamicArrayFieldClass._create_from_ptr(ptr) def create_variant_field_class(self, selector_fc=None): selector_fc_ptr = None diff --git a/src/lib/trace-ir/field-class.c b/src/lib/trace-ir/field-class.c index fb2e99ec..98b7a6d7 100644 --- a/src/lib/trace-ir/field-class.c +++ b/src/lib/trace-ir/field-class.c @@ -1527,8 +1527,9 @@ void destroy_dynamic_array_field_class(struct bt_object *obj) } struct bt_field_class *bt_field_class_dynamic_array_create( - bt_trace_class *trace_class, - struct bt_field_class *element_fc) + struct bt_trace_class *trace_class, + struct bt_field_class *element_fc, + struct bt_field_class *length_fc) { struct bt_field_class_dynamic_array *array_fc = NULL; @@ -1545,6 +1546,15 @@ struct bt_field_class *bt_field_class_dynamic_array_create( init_array_field_class((void *) array_fc, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, destroy_dynamic_array_field_class, element_fc); + + if (length_fc) { + BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc, + "Length field class"); + array_fc->length_fc = length_fc; + bt_object_get_no_null_check(array_fc->length_fc); + bt_field_class_freeze(length_fc); + } + BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc); goto end; @@ -1555,25 +1565,6 @@ end: return (void *) array_fc; } -enum bt_field_class_dynamic_array_set_length_field_class_status -bt_field_class_dynamic_array_set_length_field_class( - struct bt_field_class *fc, - struct bt_field_class *length_fc) -{ - struct bt_field_class_dynamic_array *array_fc = (void *) fc; - - BT_ASSERT_PRE_NON_NULL(fc, "Dynamic array field class"); - BT_ASSERT_PRE_NON_NULL(length_fc, "Length field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, - "Field class"); - BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc, "Length field class"); - BT_ASSERT_PRE_DEV_FC_HOT(fc, "Dynamic array field class"); - array_fc->length_fc = length_fc; - bt_object_get_no_null_check(array_fc->length_fc); - bt_field_class_freeze(length_fc); - return BT_FUNC_STATUS_OK; -} - const struct bt_field_path * bt_field_class_dynamic_array_borrow_length_field_path_const( const struct bt_field_class *fc) diff --git a/src/plugins/ctf/common/metadata/ctf-meta-translate.c b/src/plugins/ctf/common/metadata/ctf-meta-translate.c index b8372f24..c53fc17a 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta-translate.c +++ b/src/plugins/ctf/common/metadata/ctf-meta-translate.c @@ -363,9 +363,9 @@ static inline bt_field_class *ctf_field_class_sequence_to_ir(struct ctx *ctx, struct ctf_field_class_sequence *fc) { - int ret; bt_field_class *ir_fc; bt_field_class *elem_ir_fc; + bt_field_class *length_fc = NULL; if (fc->base.is_text) { ir_fc = bt_field_class_string_create(ctx->ir_tc); @@ -375,18 +375,19 @@ bt_field_class *ctf_field_class_sequence_to_ir(struct ctx *ctx, elem_ir_fc = ctf_field_class_to_ir(ctx, fc->base.elem_fc); BT_ASSERT(elem_ir_fc); - ir_fc = bt_field_class_dynamic_array_create(ctx->ir_tc, elem_ir_fc); - BT_ASSERT(ir_fc); - bt_field_class_put_ref(elem_ir_fc); - BT_ASSERT(ir_fc); if (fc->length_path.root != CTF_SCOPE_PACKET_HEADER && fc->length_path.root != CTF_SCOPE_EVENT_HEADER) { - ret = bt_field_class_dynamic_array_set_length_field_class( - ir_fc, borrow_ir_fc_from_field_path(ctx, &fc->length_path)); - BT_ASSERT(ret == 0); + length_fc = borrow_ir_fc_from_field_path(ctx, &fc->length_path); + BT_ASSERT(length_fc); } + ir_fc = bt_field_class_dynamic_array_create(ctx->ir_tc, elem_ir_fc, + length_fc); + BT_ASSERT(ir_fc); + bt_field_class_put_ref(elem_ir_fc); + BT_ASSERT(ir_fc); + end: return ir_fc; } diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c index 30c87014..0cba13cb 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c +++ b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c @@ -492,48 +492,18 @@ int field_class_dynamic_array_copy( const bt_field_class *in_field_class, bt_field_class *out_field_class) { - const bt_field_class *len_fc; - const bt_field_path *len_fp; - bt_field_class *out_len_field_class; - int ret = 0; - BT_COMP_LOGD("Copying content of dynamic array field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - len_fp = bt_field_class_dynamic_array_borrow_length_field_path_const( - in_field_class); - - if (len_fp) { - BT_COMP_LOGD("Copying dynamic array length field class using " - "field path: in-len-fp=%p", len_fp); - len_fc = resolve_field_path_to_field_class( - len_fp, md_maps); - out_len_field_class = g_hash_table_lookup( - md_maps->field_class_map, len_fc); - if (!out_len_field_class) { - BT_COMP_LOGE_STR("Cannot find the output matching length" - "field class."); - ret = -1; - goto error; - } - - if (bt_field_class_dynamic_array_set_length_field_class( - out_field_class, out_len_field_class) != - BT_FIELD_CLASS_DYNAMIC_ARRAY_SET_LENGTH_FIELD_CLASS_STATUS_OK) { - BT_COMP_LOGE_STR("Cannot set dynamic array field class' " - "length field class."); - BT_FIELD_CLASS_PUT_REF_AND_RESET(out_len_field_class); - ret = -1; - goto error; - } - } - + /* + * There is no content to copy. Keep this function call anyway for + * logging purposes. + */ BT_COMP_LOGD("Copied dynamic array field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); -error: - return ret; + return 0; } static inline @@ -644,17 +614,32 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * const bt_field_class *in_elem_fc = bt_field_class_array_borrow_element_field_class_const( in_field_class); + const bt_field_path *length_fp = + bt_field_class_dynamic_array_borrow_length_field_path_const( + in_field_class); + bt_field_class *out_length_fc = NULL; bt_field_class *out_elem_fc = copy_field_class_array_element( - md_maps, in_elem_fc); + md_maps, in_elem_fc); if (!out_elem_fc) { out_field_class = NULL; goto error; } + if (length_fp) { + const bt_field_class *in_length_fc = + resolve_field_path_to_field_class(length_fp, + md_maps); + + BT_ASSERT(in_length_fc); + out_length_fc = g_hash_table_lookup(md_maps->field_class_map, + in_length_fc); + BT_ASSERT(out_length_fc); + } + out_field_class = bt_field_class_dynamic_array_create( md_maps->output_trace_class, - out_elem_fc); + out_elem_fc, out_length_fc); break; } case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: