lib: bt_field_class_dynamic_array_create(): accept length FC parameter
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 17 Jul 2019 22:12:39 +0000 (18:12 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 18 Jul 2019 15:53:36 +0000 (11:53 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: Ib94adcc32128154b5979120ef0623be912f28734
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1718
Tested-by: jenkins <jenkins@lttng.org>
include/babeltrace2/trace-ir/field-class.h
src/bindings/python/bt2/bt2/field_class.py
src/bindings/python/bt2/bt2/trace_class.py
src/lib/trace-ir/field-class.c
src/plugins/ctf/common/metadata/ctf-meta-translate.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c

index a8c3feafe4f4a4e4cda2ce5937ca4f9c6c279472..ec4456f662bf7b7cf7feec4180f3eb2dd5cbdd31 100644 (file)
@@ -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);
index 0ccea041ebab21fb136066bbdc796721fd38a7d1..80936539379c02cc00c9d640a553c9d73277dfba 100644 (file)
@@ -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,
index d5f63712199dff1dc8e1bc62cbe97a8301b003c7..fb0eb543f10793b425b94dbb5d9d58350e06009d 100644 (file)
@@ -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
index fb2e99ec75b095556f6035ae543755e72cdef229..98b7a6d798f0e6f0a6b5650c121c122d502fb96d 100644 (file)
@@ -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)
index b8372f245bf12e97964567cd95b20ea54585b215..c53fc17a597717d56795ce781275f3cba18465a5 100644 (file)
@@ -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;
 }
index 30c87014febaa8d36b1351790fda7241845eef53..0cba13cb56065671c3831f7ce20b86190a629eee 100644 (file)
@@ -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:
This page took 0.031969 seconds and 4 git commands to generate.