Make all container types pointers
authorOlivier Dion <odion@efficios.com>
Wed, 23 Oct 2024 13:16:50 +0000 (09:16 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 23 Oct 2024 17:20:49 +0000 (13:20 -0400)
Array and VLA were not pointers in `struct side_type' like other
container types such as struct and variant. Make those pointers to
ensure container types are all similar.

API change (user-visible): This prevents defining array and VLA fields
inline. That is, it is now necessary to define the array/VLA type
before referencing it in a field.

Change-Id: Ia3634a40514d827cb23ce242fb6bd05c7c583e34
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/abi/type-description.h
include/side/instrumentation-c-api.h
src/tracer.c
src/visit-arg-vec.c
src/visit-description.c
tests/unit/test.c

index aa30485350dc8d445d78737b9ecf40212094a6e4..d0d058e9e3d3b703bb0daa9352f47ee142a0a093 100644 (file)
@@ -378,8 +378,8 @@ struct side_type {
                struct side_type_float side_float;
 
                /* Stack-copy compound types */
-               struct side_type_array side_array;
-               struct side_type_vla side_vla;
+               side_ptr_t(const struct side_type_array) side_array;
+               side_ptr_t(const struct side_type_vla) side_vla;
                side_ptr_t(const struct side_type_vla_visitor) side_vla_visitor;
                side_ptr_t(const struct side_type_struct) side_struct;
                side_ptr_t(const struct side_type_variant) side_variant;
index 57f22eae322d8cf5843c06d2e711f933f4899b06..df332084ac8cb2198a3f7c5e2af2b45e9bfdeb55 100644 (file)
                        .side_struct = SIDE_PTR_INIT(_struct), \
                }, \
        }
+
 #define side_field_struct(_name, _struct) \
        _side_field(_name, side_type_struct(SIDE_PARAM(_struct)))
 
@@ -653,35 +654,43 @@ enum {
 #define side_field_optional_literal(_name, _type)                      \
        _side_field(_name, side_type_optional(SIDE_PARAM(_type)))
 
-#define side_type_array(_elem_type, _length, _attr...) \
-       { \
-               .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \
-               .u = { \
-                       .side_array = { \
-                               .elem_type = SIDE_PTR_INIT(_elem_type), \
-                               .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
-                               .length = _length, \
-                               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
-                       }, \
-               }, \
+#define side_type_array(_array)                                        \
+       {                                                       \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY),        \
+               .u = {                                          \
+                       .side_array = SIDE_PTR_INIT(_array)     \
+               }                                               \
        }
-#define side_field_array(_name, _elem_type, _length, _attr...) \
-       _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
 
-#define side_type_vla(_elem_type, _length_type, _attr...) \
-       { \
-               .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \
-               .u = { \
-                       .side_vla = { \
-                               .elem_type = SIDE_PTR_INIT(_elem_type), \
-                               .length_type = SIDE_PTR_INIT(_length_type), \
-                               .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
-                               .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
-                       }, \
-               }, \
+#define side_field_array(_name, _array) \
+       _side_field(_name, side_type_array(_array))
+
+#define side_define_array(_identifier, _elem_type, _length, _attr...)  \
+       const struct side_type_array _identifier = {                    \
+               .elem_type = SIDE_PTR_INIT(SIDE_PARAM(_elem_type)),     \
+               .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
+               .length = _length,                                      \
+               .nr_attr  = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
+       }
+
+#define side_type_vla(_vla)                                    \
+       {                                                       \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA),          \
+               .u = {                                          \
+                       .side_vla = SIDE_PTR_INIT(_vla),        \
+               },                                              \
+       }
+
+#define side_field_vla(_name, _vla) \
+       _side_field(_name, side_type_vla(_vla))
+
+#define side_define_vla(_identifier, _elem_type, _length_type, _attr...) \
+       const struct side_type_vla _identifier = {                      \
+               .elem_type = SIDE_PTR_INIT(SIDE_PARAM(_elem_type)),     \
+               .length_type = SIDE_PTR_INIT(SIDE_PARAM(_length_type)), \
+               .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
+               .nr_attr  = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
        }
-#define side_field_vla(_name, _elem_type, _length_type, _attr...) \
-       _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_length_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())))
 
 #define _side_type_vla_visitor_define(_elem_type, _length_type, _visitor, _attr...) \
        { \
index ff24388b3dd405d9604ee64f72d129b634b3c382..66ef574a7593f9c950fb9e5cade19434046352c5 100644 (file)
@@ -1355,12 +1355,12 @@ static void tracer_print_enum_bitmap(const struct side_type *type_desc,
                nr_items = 1;
                break;
        case SIDE_TYPE_ARRAY:
-               elem_type = side_ptr_get(enum_elem_type->u.side_array.elem_type);
+               elem_type = side_ptr_get(side_ptr_get(enum_elem_type->u.side_array)->elem_type);
                array_item = side_ptr_get(side_ptr_get(item->u.side_static.side_array)->sav);
-               nr_items = type_desc->u.side_array.length;
+               nr_items = side_ptr_get(type_desc->u.side_array)->length;
                break;
        case SIDE_TYPE_VLA:
-               elem_type = side_ptr_get(enum_elem_type->u.side_vla.elem_type);
+               elem_type = side_ptr_get(side_ptr_get(enum_elem_type->u.side_vla)->elem_type);
                array_item = side_ptr_get(side_ptr_get(item->u.side_static.side_vla)->sav);
                nr_items = side_ptr_get(item->u.side_static.side_vla)->len;
                break;
index bda94cc0daec8fee51ab9a03e9e217ebc2cbf671..7b54d9adb6a7d6eaaa3af6c2f5f1a6c3e08b0b9a 100644 (file)
@@ -365,22 +365,22 @@ void type_visitor_array(const struct side_type_visitor *type_visitor, const stru
        const struct side_arg *sav = side_ptr_get(side_arg_vec->sav);
        uint32_t i, side_sav_len = side_arg_vec->len;
 
-       if (type_desc->u.side_array.length != side_sav_len) {
+       if (side_ptr_get(type_desc->u.side_array)->length != side_sav_len) {
                fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n");
                abort();
        }
        if (type_visitor->before_array_type_func)
-               type_visitor->before_array_type_func(&type_desc->u.side_array, side_arg_vec, priv);
+               type_visitor->before_array_type_func(side_ptr_get(type_desc->u.side_array), side_arg_vec, priv);
        for (i = 0; i < side_sav_len; i++) {
                struct visit_context new_ctx = {
                        .type = CONTEXT_ARRAY,
                        .array_index = i,
                        .parent = ctx
                };
-               side_visit_elem(type_visitor, &new_ctx, side_ptr_get(type_desc->u.side_array.elem_type), &sav[i], priv);
+               side_visit_elem(type_visitor, &new_ctx, side_ptr_get(side_ptr_get(type_desc->u.side_array)->elem_type), &sav[i], priv);
        }
        if (type_visitor->after_array_type_func)
-               type_visitor->after_array_type_func(&type_desc->u.side_array, side_arg_vec, priv);
+               type_visitor->after_array_type_func(side_ptr_get(type_desc->u.side_array), side_arg_vec, priv);
 }
 
 static
@@ -391,17 +391,17 @@ void type_visitor_vla(const struct side_type_visitor *type_visitor, const struct
        uint32_t i, side_sav_len = side_arg_vec->len;
 
        if (type_visitor->before_vla_type_func)
-               type_visitor->before_vla_type_func(&type_desc->u.side_vla, side_arg_vec, priv);
+               type_visitor->before_vla_type_func(side_ptr_get(type_desc->u.side_vla), side_arg_vec, priv);
        for (i = 0; i < side_sav_len; i++) {
                struct visit_context new_ctx = {
                        .type = CONTEXT_ARRAY,
                        .array_index = i,
                        .parent = ctx
                };
-               side_visit_elem(type_visitor, &new_ctx, side_ptr_get(type_desc->u.side_vla.elem_type), &sav[i], priv);
+               side_visit_elem(type_visitor, &new_ctx, side_ptr_get(side_ptr_get(type_desc->u.side_vla)->elem_type), &sav[i], priv);
        }
        if (type_visitor->after_vla_type_func)
-               type_visitor->after_vla_type_func(&type_desc->u.side_vla, side_arg_vec, priv);
+               type_visitor->after_vla_type_func(side_ptr_get(type_desc->u.side_vla), side_arg_vec, priv);
 }
 
 struct tracer_visitor_priv {
index bbb69993ee3767107de30fab40259d6e913b59a2..3c347f0f733110987e9feccade0b62fbe773d4bc 100644 (file)
@@ -139,23 +139,23 @@ static
 void description_visitor_array(const struct side_description_visitor *description_visitor, const struct side_type *type_desc, void *priv)
 {
        if (description_visitor->before_array_type_func)
-               description_visitor->before_array_type_func(&type_desc->u.side_array, priv);
-       side_visit_elem(description_visitor, side_ptr_get(type_desc->u.side_array.elem_type), priv);
+               description_visitor->before_array_type_func(side_ptr_get(type_desc->u.side_array), priv);
+       side_visit_elem(description_visitor, side_ptr_get(side_ptr_get(type_desc->u.side_array)->elem_type), priv);
        if (description_visitor->after_array_type_func)
-               description_visitor->after_array_type_func(&type_desc->u.side_array, priv);
+               description_visitor->after_array_type_func(side_ptr_get(type_desc->u.side_array), priv);
 }
 
 static
 void description_visitor_vla(const struct side_description_visitor *description_visitor, const struct side_type *type_desc, void *priv)
 {
        if (description_visitor->before_vla_type_func)
-               description_visitor->before_vla_type_func(&type_desc->u.side_vla, priv);
-       side_visit_elem(description_visitor, side_ptr_get(type_desc->u.side_vla.length_type), priv);
+               description_visitor->before_vla_type_func(side_ptr_get(type_desc->u.side_vla), priv);
+       side_visit_elem(description_visitor, side_ptr_get(side_ptr_get(type_desc->u.side_vla)->length_type), priv);
        if (description_visitor->after_length_vla_type_func)
-               description_visitor->after_length_vla_type_func(&type_desc->u.side_vla, priv);
-       side_visit_elem(description_visitor, side_ptr_get(type_desc->u.side_vla.elem_type), priv);
+               description_visitor->after_length_vla_type_func(side_ptr_get(type_desc->u.side_vla), priv);
+       side_visit_elem(description_visitor, side_ptr_get(side_ptr_get(type_desc->u.side_vla)->elem_type), priv);
        if (description_visitor->after_element_vla_type_func)
-               description_visitor->after_element_vla_type_func(&type_desc->u.side_vla, priv);
+               description_visitor->after_element_vla_type_func(side_ptr_get(type_desc->u.side_vla), priv);
 }
 
 static
index 90de62de29dd38bc02c83c09162b72736477d28a..e93f7e6e8d23a505156883b4d132a34b3580d277 100644 (file)
@@ -115,9 +115,14 @@ void test_struct(void)
        }
 }
 
+static side_define_array(my_array_u32_3,
+       side_elem(side_type_u32()),
+       3
+);
+
 side_static_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_array("arr", side_elem(side_type_u32()), 3),
+               side_field_array("arr", &my_array_u32_3),
                side_field_s64("v"),
        )
 );
@@ -131,9 +136,14 @@ void test_array(void)
        }
 }
 
+static side_define_vla(my_vla_u32,
+       side_elem(side_type_u32()),
+       side_elem(side_type_u32())
+);
+
 side_static_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_vla("vla", side_elem(side_type_u32()), side_elem(side_type_u32())),
+               side_field_vla("vla", &my_vla_u32),
                side_field_s64("v"),
        )
 );
@@ -1094,6 +1104,16 @@ static side_define_enum_bitmap(myenum_bitmap,
        )
 );
 
+static side_define_array(my_array_u32_5,
+       side_elem(side_type_u32()),
+       5
+);
+
+static side_define_vla(my_vla_u32_for_bitmap,
+       side_elem(side_type_u32()),
+       side_elem(side_type_u32())
+);
+
 side_static_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitmap", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
                side_field_enum_bitmap("bit_0", &myenum_bitmap, side_elem(side_type_u32())),
@@ -1106,9 +1126,9 @@ side_static_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitma
                side_field_enum_bitmap("bits_1+63", &myenum_bitmap, side_elem(side_type_u64())),
                side_field_enum_bitmap("byte_bit_2", &myenum_bitmap, side_elem(side_type_byte())),
                side_field_enum_bitmap("bit_159", &myenum_bitmap,
-                       side_elem(side_type_array(side_elem(side_type_u32()), 5))),
+                       side_elem(side_type_array(&my_array_u32_5))),
                side_field_enum_bitmap("bit_159", &myenum_bitmap,
-                       side_elem(side_type_vla(side_elem(side_type_u32()), side_elem(side_type_u32())))),
+                       side_elem(side_type_vla(&my_vla_u32_for_bitmap))),
                side_field_enum_bitmap("bit_2_be", &myenum_bitmap, side_elem(side_type_u32_be())),
                side_field_enum_bitmap("bit_2_le", &myenum_bitmap, side_elem(side_type_u32_le())),
        )
@@ -1152,10 +1172,15 @@ void test_enum_bitmap(void)
        }
 }
 
+static side_define_array(my_array_byte,
+       side_elem(side_type_byte()),
+       3
+);
+
 side_static_event_variadic(my_provider_event_blob, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
                side_field_byte("blobfield"),
-               side_field_array("arrayblob", side_elem(side_type_byte()), 3),
+               side_field_array("arrayblob", &my_array_byte),
        )
 );
 
This page took 0.029615 seconds and 4 git commands to generate.