From 211779f05d90873cfcff6fb09a4233c92a8e6ef0 Mon Sep 17 00:00:00 2001 From: Olivier Dion Date: Thu, 24 Oct 2024 11:43:33 -0400 Subject: [PATCH] Fix double referencing of SIDE_TYPE_OPTIONAL An optional type was a pointer to a `struct side_type'. This results in having OPTIONAL -> OPTIONAL -> TYPE when defining an optional. Fix this by defining a `struct side_type_optional' that has a pointer to a `struct side_type', just like other containers. Change-Id: I4100fad7485d309e4f3ba798227eac0694fcc294 Signed-off-by: Olivier Dion Signed-off-by: Mathieu Desnoyers --- include/side/abi/type-description.h | 6 +++++- include/side/instrumentation-c-api.h | 13 +++++++++---- src/visit-arg-vec.c | 2 +- src/visit-description.c | 12 ++++++------ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/side/abi/type-description.h b/include/side/abi/type-description.h index d0d058e..431e0d2 100644 --- a/include/side/abi/type-description.h +++ b/include/side/abi/type-description.h @@ -383,7 +383,7 @@ struct side_type { 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; - side_ptr_t(const struct side_type) side_optional; + side_ptr_t(const struct side_type_optional) side_optional; /* Stack-copy enumeration types */ struct side_type_enum side_enum; @@ -412,6 +412,10 @@ struct side_type_variant { } SIDE_PACKED; side_check_size(struct side_type_variant, 40 + sizeof(const struct side_type)); +struct side_type_optional { + side_ptr_t(const struct side_type) elem_type; +}; + struct side_event_field { side_ptr_t(const char) field_name; struct side_type side_type; diff --git a/include/side/instrumentation-c-api.h b/include/side/instrumentation-c-api.h index 20344b0..33e1e98 100644 --- a/include/side/instrumentation-c-api.h +++ b/include/side/instrumentation-c-api.h @@ -639,17 +639,22 @@ enum { .type = SIDE_ENUM_INIT(SIDE_TYPE_OPTIONAL), \ .u = { \ .side_optional = SIDE_PTR_INIT(_optional), \ - }, \ + } \ + } + +#define _side_type_optional_define(_elem_type) \ + { \ + .elem_type = SIDE_PTR_INIT(_elem_type), \ } #define _side_define_optional(_identifier, _elem_type) \ - const struct side_type _identifier = _side_type_optional(SIDE_PARAM(_elem_type)) + const struct side_type_optional _identifier = _side_type_optional_define(SIDE_PARAM(_elem_type)) #define _side_field_optional(_name, _identifier) \ - _side_field(_name, _side_type_optional(&(_identifier))) + _side_field(_name, _side_type_optional(SIDE_PARAM(&(_identifier)))) #define _side_field_optional_literal(_name, _elem_type) \ - _side_field(_name, _side_type_optional(SIDE_PARAM(_elem_type))) + _side_field(_name, _side_type_optional(SIDE_COMPOUND_LITERAL(struct side_type_optional, _side_type_optional_define(SIDE_PARAM(_elem_type))))) #define _side_type_array(_array) \ { \ diff --git a/src/visit-arg-vec.c b/src/visit-arg-vec.c index aa3da94..5f5e668 100644 --- a/src/visit-arg-vec.c +++ b/src/visit-arg-vec.c @@ -352,7 +352,7 @@ void type_visitor_optional(const struct side_type_visitor *type_visitor, const s if (side_arg_optional->selector == SIDE_OPTIONAL_DISABLED) return; - type = side_ptr_get(type_desc->u.side_optional); + type = side_ptr_get(side_ptr_get(type_desc->u.side_optional)->elem_type); arg = &side_arg_optional->side_static; side_visit_type(type_visitor, &new_ctx, type, arg, priv); diff --git a/src/visit-description.c b/src/visit-description.c index 3c347f0..71c17c6 100644 --- a/src/visit-description.c +++ b/src/visit-description.c @@ -124,15 +124,15 @@ void description_visitor_variant(const struct side_description_visitor *descript static void description_visitor_optional(const struct side_description_visitor *description_visitor, - const struct side_type *type_desc, void *priv) + const struct side_type_optional *optional, void *priv) { - const struct side_type *optional = side_ptr_get(type_desc->u.side_optional); + const struct side_type *type_desc = side_ptr_get(optional->elem_type); if (description_visitor->before_optional_type_func) - description_visitor->before_optional_type_func(optional, priv); - side_visit_type(description_visitor, optional, priv); + description_visitor->before_optional_type_func(type_desc, priv); + side_visit_type(description_visitor, type_desc, priv); if (description_visitor->after_optional_type_func) - description_visitor->after_optional_type_func(optional, priv); + description_visitor->after_optional_type_func(type_desc, priv); } static @@ -482,7 +482,7 @@ void side_visit_type(const struct side_description_visitor *description_visitor, break; case SIDE_TYPE_OPTIONAL: - description_visitor_optional(description_visitor, type_desc, priv); + description_visitor_optional(description_visitor, side_ptr_get(type_desc->u.side_optional), priv); break; default: -- 2.34.1