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);
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,
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
}
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;
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;
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)
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);
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;
}
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
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: