Fix double referencing of SIDE_TYPE_OPTIONAL
authorOlivier Dion <odion@efficios.com>
Thu, 24 Oct 2024 15:43:33 +0000 (11:43 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 24 Oct 2024 20:31:57 +0000 (16:31 -0400)
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 <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/visit-arg-vec.c
src/visit-description.c

index d0d058e9e3d3b703bb0daa9352f47ee142a0a093..431e0d23fdb60cc1c4f7080b23572513ff413683 100644 (file)
@@ -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;
index 20344b0d29576f96ae3f58cbb7d11d49b0434b61..33e1e98084d23d177b78139b27fc07261c8ca8eb 100644 (file)
@@ -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)                               \
        {                                                       \
index aa3da945b524e5d195bcc181273754675c285688..5f5e6685c48ed3293d38ac9385327990c3d5b93d 100644 (file)
@@ -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);
index 3c347f0f733110987e9feccade0b62fbe773d4bc..71c17c6eeb7232c9912bfb21aeaa3279e9ad2d90 100644 (file)
@@ -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:
This page took 0.027039 seconds and 4 git commands to generate.