From: Mathieu Desnoyers Date: Thu, 21 Sep 2023 06:39:56 +0000 (+0100) Subject: Use side_ptr_t for enum mappings pointers X-Git-Url: http://git.efficios.com/?p=libside.git;a=commitdiff_plain;h=64037418a6663112ff79692ff2dcf4e93c054f80 Use side_ptr_t for enum mappings pointers Signed-off-by: Mathieu Desnoyers --- diff --git a/include/side/trace.h b/include/side/trace.h index b3b8f6e..210cb3f 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -330,7 +330,7 @@ struct side_enum_mapping { } SIDE_PACKED; struct side_enum_mappings { - const struct side_enum_mapping *mappings; + side_ptr_t(const struct side_enum_mapping) mappings; side_ptr_t(const struct side_attr) attr; uint32_t nr_mappings; uint32_t nr_attr; @@ -343,7 +343,7 @@ struct side_enum_bitmap_mapping { } SIDE_PACKED; struct side_enum_bitmap_mappings { - const struct side_enum_bitmap_mapping *mappings; + side_ptr_t(const struct side_enum_bitmap_mapping) mappings; side_ptr_t(const struct side_attr) attr; uint32_t nr_mappings; uint32_t nr_attr; @@ -377,12 +377,12 @@ struct side_type_vla_visitor { } SIDE_PACKED; struct side_type_enum { - const struct side_enum_mappings *mappings; + side_ptr_t(const struct side_enum_mappings) mappings; const struct side_type *elem_type; } SIDE_PACKED; struct side_type_enum_bitmap { - const struct side_enum_bitmap_mappings *mappings; + side_ptr_t(const struct side_enum_bitmap_mappings) mappings; const struct side_type *elem_type; } SIDE_PACKED; @@ -419,7 +419,7 @@ struct side_type_gather_string { } SIDE_PACKED; struct side_type_gather_enum { - const struct side_enum_mappings *mappings; + side_ptr_t(const struct side_enum_mappings) mappings; const struct side_type *elem_type; } SIDE_PACKED; @@ -723,7 +723,7 @@ struct side_event_description { #define side_define_enum(_identifier, _mappings, _attr...) \ const struct side_enum_mappings _identifier = { \ - .mappings = _mappings, \ + .mappings = SIDE_PTR_INIT(_mappings), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ @@ -756,7 +756,7 @@ struct side_event_description { #define side_define_enum_bitmap(_identifier, _mappings, _attr...) \ const struct side_enum_bitmap_mappings _identifier = { \ - .mappings = _mappings, \ + .mappings = SIDE_PTR_INIT(_mappings), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ @@ -989,7 +989,7 @@ struct side_event_description { .type = SIDE_TYPE_ENUM, \ .u = { \ .side_enum = { \ - .mappings = _mappings, \ + .mappings = SIDE_PTR_INIT(_mappings), \ .elem_type = _elem_type, \ }, \ }, \ @@ -1002,7 +1002,7 @@ struct side_event_description { .type = SIDE_TYPE_ENUM_BITMAP, \ .u = { \ .side_enum_bitmap = { \ - .mappings = _mappings, \ + .mappings = SIDE_PTR_INIT(_mappings), \ .elem_type = _elem_type, \ }, \ }, \ @@ -1337,7 +1337,7 @@ struct side_event_description { .type = SIDE_TYPE_GATHER_ENUM, \ .u = { \ .side_enum = { \ - .mappings = _mappings, \ + .mappings = SIDE_PTR_INIT(_mappings), \ .elem_type = _elem_type, \ }, \ }, \ diff --git a/src/tracer.c b/src/tracer.c index 59f1b1a..170c611 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -451,7 +451,7 @@ void print_enum_labels(const struct side_enum_mappings *mappings, union int64_va printf(", labels: [ "); for (i = 0; i < mappings->nr_mappings; i++) { - const struct side_enum_mapping *mapping = &mappings->mappings[i]; + const struct side_enum_mapping *mapping = &side_ptr_get(mappings->mappings)[i]; if (mapping->range_end < mapping->range_begin) { fprintf(stderr, "ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n", @@ -471,7 +471,7 @@ void print_enum_labels(const struct side_enum_mappings *mappings, union int64_va static void tracer_print_enum(const struct side_type *type_desc, const struct side_arg *item) { - const struct side_enum_mappings *mappings = type_desc->u.side_enum.mappings; + const struct side_enum_mappings *mappings = side_ptr_get(type_desc->u.side_enum.mappings); const struct side_type *elem_type = type_desc->u.side_enum.elem_type; union int64_value v64; @@ -517,7 +517,7 @@ static void tracer_print_enum_bitmap(const struct side_type *type_desc, const struct side_arg *item) { - const struct side_enum_bitmap_mappings *side_enum_mappings = type_desc->u.side_enum_bitmap.mappings; + const struct side_enum_bitmap_mappings *side_enum_mappings = side_ptr_get(type_desc->u.side_enum_bitmap.mappings); const struct side_type *enum_elem_type = type_desc->u.side_enum_bitmap.elem_type, *elem_type; uint32_t i, print_count = 0, stride_bit, nr_items; const struct side_arg *array_item; @@ -556,7 +556,7 @@ void tracer_print_enum_bitmap(const struct side_type *type_desc, printf("%s", side_enum_mappings->nr_attr ? ", " : ""); printf("labels: [ "); for (i = 0; i < side_enum_mappings->nr_mappings; i++) { - const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i]; + const struct side_enum_bitmap_mapping *mapping = &side_ptr_get(side_enum_mappings->mappings)[i]; bool match = false; uint64_t bit; @@ -1353,7 +1353,7 @@ uint32_t tracer_print_gather_type(const struct side_type *type_desc, const void static uint32_t tracer_print_gather_enum_type(const struct side_type_gather *type_gather, const void *_ptr) { - const struct side_enum_mappings *mappings = type_gather->u.side_enum.mappings; + const struct side_enum_mappings *mappings = side_ptr_get(type_gather->u.side_enum.mappings); const struct side_type *enum_elem_type = type_gather->u.side_enum.elem_type; const struct side_type_gather_integer *side_integer = &enum_elem_type->u.side_gather.u.side_integer; enum side_type_gather_access_mode access_mode =