From: Mathieu Desnoyers Date: Thu, 21 Sep 2023 09:54:09 +0000 (+0100) Subject: Use side_ptr_t for dynamic arguments X-Git-Url: http://git.efficios.com/?p=libside.git;a=commitdiff_plain;h=f13253cb3e501215142fcad9718c8ae037eb8794 Use side_ptr_t for dynamic arguments Signed-off-by: Mathieu Desnoyers --- diff --git a/include/side/trace.h b/include/side/trace.h index 883a311..b1394f0 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -553,14 +553,14 @@ union side_arg_static { } SIDE_PACKED; struct side_arg_dynamic_vla { - const struct side_arg *sav; + side_ptr_t(const struct side_arg) sav; side_ptr_t(const struct side_attr) attr; uint32_t len; uint32_t nr_attr; } SIDE_PACKED; struct side_arg_dynamic_struct { - const struct side_arg_dynamic_field *fields; + side_ptr_t(const struct side_arg_dynamic_field) fields; side_ptr_t(const struct side_attr) attr; uint32_t len; uint32_t nr_attr; @@ -605,8 +605,8 @@ union side_arg_dynamic { } SIDE_PACKED side_float; /* Dynamic compound types */ - const struct side_arg_dynamic_struct *side_dynamic_struct; - const struct side_arg_dynamic_vla *side_dynamic_vla; + side_ptr_t(const struct side_arg_dynamic_struct) side_dynamic_struct; + side_ptr_t(const struct side_arg_dynamic_vla) side_dynamic_vla; struct side_dynamic_struct_visitor side_dynamic_struct_visitor; struct side_dynamic_vla_visitor side_dynamic_vla_visitor; @@ -626,12 +626,12 @@ struct side_arg_variant { } SIDE_PACKED; struct side_arg_vec { - const struct side_arg *sav; + side_ptr_t(const struct side_arg) sav; uint32_t len; } SIDE_PACKED; struct side_arg_dynamic_field { - const char *field_name; + side_ptr_t(const char) field_name; const struct side_arg elem; } SIDE_PACKED; @@ -1680,7 +1680,7 @@ struct side_event_description { .type = SIDE_TYPE_DYNAMIC_VLA, \ .u = { \ .side_dynamic = { \ - .side_dynamic_vla = (_vla), \ + .side_dynamic_vla = SIDE_PTR_INIT(_vla), \ }, \ }, \ } @@ -1705,7 +1705,7 @@ struct side_event_description { .type = SIDE_TYPE_DYNAMIC_STRUCT, \ .u = { \ .side_dynamic = { \ - .side_dynamic_struct = (_struct), \ + .side_dynamic_struct = SIDE_PTR_INIT(_struct), \ }, \ }, \ } @@ -1728,7 +1728,7 @@ struct side_event_description { #define side_arg_dynamic_define_vec(_identifier, _sav, _attr...) \ const struct side_arg _identifier##_vec[] = { _sav }; \ const struct side_arg_dynamic_vla _identifier = { \ - .sav = _identifier##_vec, \ + .sav = SIDE_PTR_INIT(_identifier##_vec), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ @@ -1737,7 +1737,7 @@ struct side_event_description { #define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr...) \ const struct side_arg_dynamic_field _identifier##_fields[] = { _struct_fields }; \ const struct side_arg_dynamic_struct _identifier = { \ - .fields = _identifier##_fields, \ + .fields = SIDE_PTR_INIT(_identifier##_fields), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .len = SIDE_ARRAY_SIZE(_identifier##_fields), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ @@ -1746,13 +1746,13 @@ struct side_event_description { #define side_arg_define_vec(_identifier, _sav) \ const struct side_arg _identifier##_vec[] = { _sav }; \ const struct side_arg_vec _identifier = { \ - .sav = _identifier##_vec, \ + .sav = SIDE_PTR_INIT(_identifier##_vec), \ .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ } #define side_arg_dynamic_field(_name, _elem) \ { \ - .field_name = _name, \ + .field_name = SIDE_PTR_INIT(_name), \ .elem = _elem, \ } @@ -1771,7 +1771,7 @@ struct side_event_description { { \ const struct side_arg side_sav[] = { _sav }; \ const struct side_arg_vec side_arg_vec = { \ - .sav = side_sav, \ + .sav = SIDE_PTR_INIT(side_sav), \ .len = SIDE_ARRAY_SIZE(side_sav), \ }; \ side_call(&(_identifier), &side_arg_vec); \ @@ -1785,12 +1785,12 @@ struct side_event_description { { \ const struct side_arg side_sav[] = { _sav }; \ const struct side_arg_vec side_arg_vec = { \ - .sav = side_sav, \ + .sav = SIDE_PTR_INIT(side_sav), \ .len = SIDE_ARRAY_SIZE(side_sav), \ }; \ const struct side_arg_dynamic_field side_fields[] = { _var_fields }; \ const struct side_arg_dynamic_struct var_struct = { \ - .fields = side_fields, \ + .fields = SIDE_PTR_INIT(side_fields), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .len = SIDE_ARRAY_SIZE(side_fields), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ diff --git a/src/tracer.c b/src/tracer.c index f9e91e9..c668e4a 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -538,12 +538,12 @@ void tracer_print_enum_bitmap(const struct side_type *type_desc, break; case SIDE_TYPE_ARRAY: elem_type = side_ptr_get(enum_elem_type->u.side_array.elem_type); - array_item = side_ptr_get(item->u.side_static.side_array)->sav; + array_item = side_ptr_get(side_ptr_get(item->u.side_static.side_array)->sav); nr_items = type_desc->u.side_array.length; break; case SIDE_TYPE_VLA: elem_type = side_ptr_get(enum_elem_type->u.side_vla.elem_type); - array_item = side_ptr_get(item->u.side_static.side_vla)->sav; + 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; default: @@ -1047,7 +1047,7 @@ void tracer_print_field(const struct side_event_field *item_desc, const struct s static void tracer_print_struct(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec) { - const struct side_arg *sav = side_arg_vec->sav; + const struct side_arg *sav = side_ptr_get(side_arg_vec->sav); const struct side_type_struct *side_struct = side_ptr_get(type_desc->u.side_struct); uint32_t i, side_sav_len = side_arg_vec->len; @@ -1108,7 +1108,7 @@ void tracer_print_variant(const struct side_type *type_desc, const struct side_a static void tracer_print_array(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec) { - const struct side_arg *sav = side_arg_vec->sav; + 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) { @@ -1129,7 +1129,7 @@ void tracer_print_array(const struct side_type *type_desc, const struct side_arg static void tracer_print_vla(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec) { - const struct side_arg *sav = side_arg_vec->sav; + const struct side_arg *sav = side_ptr_get(side_arg_vec->sav); uint32_t i, side_sav_len = side_arg_vec->len; print_attributes("attr", ":", side_ptr_get(type_desc->u.side_vla.attr), type_desc->u.side_vla.nr_attr); @@ -1535,7 +1535,7 @@ void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx) static void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct *dynamic_struct) { - const struct side_arg_dynamic_field *fields = dynamic_struct->fields; + const struct side_arg_dynamic_field *fields = side_ptr_get(dynamic_struct->fields); uint32_t i, len = dynamic_struct->len; print_attributes("attr", "::", side_ptr_get(dynamic_struct->attr), dynamic_struct->nr_attr); @@ -1544,7 +1544,7 @@ void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct *dynamic_s printf("[ "); for (i = 0; i < len; i++) { printf("%s", i ? ", " : ""); - printf("%s:: ", fields[i].field_name); + printf("%s:: ", side_ptr_get(fields[i].field_name)); tracer_print_dynamic(&fields[i].elem); } printf(" ]"); @@ -1563,7 +1563,7 @@ enum side_visitor_status tracer_dynamic_struct_write_elem_cb( (struct tracer_dynamic_struct_visitor_priv *) tracer_ctx->priv; printf("%s", tracer_priv->i++ ? ", " : ""); - printf("%s:: ", dynamic_field->field_name); + printf("%s:: ", side_ptr_get(dynamic_field->field_name)); tracer_print_dynamic(&dynamic_field->elem); return SIDE_VISITOR_STATUS_OK; } @@ -1599,7 +1599,7 @@ void tracer_print_dynamic_struct_visitor(const struct side_arg *item) static void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla *vla) { - const struct side_arg *sav = vla->sav; + const struct side_arg *sav = side_ptr_get(vla->sav); uint32_t i, side_sav_len = vla->len; print_attributes("attr", "::", side_ptr_get(vla->attr), vla->nr_attr); @@ -1697,13 +1697,13 @@ void tracer_print_dynamic(const struct side_arg *item) /* Dynamic compound types */ case SIDE_TYPE_DYNAMIC_STRUCT: - tracer_print_dynamic_struct(item->u.side_dynamic.side_dynamic_struct); + tracer_print_dynamic_struct(side_ptr_get(item->u.side_dynamic.side_dynamic_struct)); break; case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR: tracer_print_dynamic_struct_visitor(item); break; case SIDE_TYPE_DYNAMIC_VLA: - tracer_print_dynamic_vla(item->u.side_dynamic.side_dynamic_vla); + tracer_print_dynamic_vla(side_ptr_get(item->u.side_dynamic.side_dynamic_vla)); break; case SIDE_TYPE_DYNAMIC_VLA_VISITOR: tracer_print_dynamic_vla_visitor(item); @@ -1720,7 +1720,7 @@ void tracer_print_static_fields(const struct side_event_description *desc, const struct side_arg_vec *side_arg_vec, uint32_t *nr_items) { - const struct side_arg *sav = side_arg_vec->sav; + const struct side_arg *sav = side_ptr_get(side_arg_vec->sav); uint32_t i, side_sav_len = side_arg_vec->len; printf("provider: %s, event: %s", desc->provider_name, desc->event_name); @@ -1769,8 +1769,8 @@ void tracer_call_variadic(const struct side_event_description *desc, printf("%s", var_struct_len ? ", fields:: [ " : ""); for (i = 0; i < var_struct_len; i++, nr_fields++) { printf("%s", i ? ", " : ""); - printf("%s:: ", var_struct->fields[i].field_name); - tracer_print_dynamic(&var_struct->fields[i].elem); + printf("%s:: ", side_ptr_get(side_ptr_get(var_struct->fields)[i].field_name)); + tracer_print_dynamic(&side_ptr_get(var_struct->fields)[i].elem); } if (i) printf(" ]"); diff --git a/tests/unit/test.c b/tests/unit/test.c index 53580a1..7c2e2f9 100644 --- a/tests/unit/test.c +++ b/tests/unit/test.c @@ -628,10 +628,9 @@ enum side_visitor_status test_dynamic_struct_visitor(const struct side_tracer_dy uint32_t length = ctx->length, i; for (i = 0; i < length; i++) { - struct side_arg_dynamic_field dynamic_field = { - .field_name = ctx->ptr[i].name, - .elem = side_arg_dynamic_u32(ctx->ptr[i].value), - }; + struct side_arg_dynamic_field dynamic_field = + side_arg_dynamic_field(ctx->ptr[i].name, + side_arg_dynamic_u32(ctx->ptr[i].value)); if (tracer_ctx->write_field(tracer_ctx, &dynamic_field) != SIDE_VISITOR_STATUS_OK) return SIDE_VISITOR_STATUS_ERROR; }