ust-events.h API const-ness
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 19 Apr 2021 14:07:08 +0000 (10:07 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 19 Apr 2021 17:42:18 +0000 (13:42 -0400)
Ensure ust-events.h definitions, fields, and arguments referring to
const arrays of pointers are const.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I9b1173221c2cfd2d574c300233e15a3fc0e72bce

include/lttng/ust-events.h
include/lttng/ust-tracepoint-event.h
src/common/dynamic-type.h
src/common/ustcomm.c
src/common/ustcomm.h
src/lib/lttng-ust/lttng-bytecode.c
src/lib/lttng-ust/lttng-events.c
src/lib/lttng-ust/lttng-ust-dynamic-type.c

index 2b035d8fa457f2be335cdaa78b157184266070bf..cf1045bb589470d5a1f53f13369b14fb5c5e987c 100644 (file)
@@ -203,8 +203,8 @@ struct lttng_ust_type_struct {
        struct lttng_ust_type_common parent;
        uint32_t struct_size;
        unsigned int nr_fields;
-       const struct lttng_ust_event_field **fields;    /* Array of pointers to fields. */
-       unsigned int alignment;         /* Minimum alignment for this type. */
+       const struct lttng_ust_event_field * const *fields;     /* Array of pointers to fields. */
+       unsigned int alignment;                                 /* Minimum alignment for this type. */
 };
 
 /*
@@ -223,7 +223,7 @@ struct lttng_ust_enum_desc {
        uint32_t struct_size;
 
        const char *name;
-       const struct lttng_ust_enum_entry **entries;
+       const struct lttng_ust_enum_entry * const *entries;
        unsigned int nr_entries;
 
        /* End of base ABI. Fields below should be used after checking struct_size. */
@@ -268,7 +268,7 @@ struct lttng_ust_event_desc {
        const char *event_name;
        const struct lttng_ust_probe_desc *probe_desc;
        void (*probe_callback)(void);
-       const struct lttng_ust_event_field **fields;    /* event payload */
+       const struct lttng_ust_event_field * const *fields;     /* event payload */
        unsigned int nr_fields;
        const int **loglevel;
        const char *signature;                          /* Argument types/names received */
@@ -290,7 +290,7 @@ struct lttng_ust_probe_desc {
        uint32_t struct_size;                   /* Size of this structure. */
 
        const char *provider_name;
-       const struct lttng_ust_event_desc **event_desc;
+       const struct lttng_ust_event_desc * const *event_desc;
        unsigned int nr_events;
        uint32_t major;
        uint32_t minor;
index c50047d0baf4c6fc5a262b70b9f2ed72328e1e23..e663e839bc0e5426b643dfce5f4f93e17ca57b8b 100644 (file)
@@ -203,7 +203,7 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)
 
 #undef TRACEPOINT_ENUM
 #define TRACEPOINT_ENUM(_provider, _name, _values)                     \
-       const struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \
+       const struct lttng_ust_enum_entry * const __enum_values__##_provider##_##_name[] = { \
                _values                                                 \
                ctf_enum_value("", 0)   /* Dummy, 0-len array forbidden by C99. */ \
        };
@@ -362,7 +362,7 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)
 
 #undef _TRACEPOINT_EVENT_CLASS
 #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields)                           \
-       static const struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \
+       static const struct lttng_ust_event_field * const __event_fields___##_provider##___##_name[] = { \
                _fields                                                                      \
                ctf_integer(int, dummy, 0)      /* Dummy, C99 forbids 0-len array. */        \
        };
@@ -972,10 +972,10 @@ static const char __tp_event_signature___##_provider##___##_name[] =      \
 #endif
 
 #undef TRACEPOINT_LOGLEVEL
-#define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel)               \
-static const int _loglevel_value___##__provider##___##__name = __loglevel; \
-LTTNG_UST_TP_EXTERN_C const int *_loglevel___##__provider##___##__name    \
-               __attribute__((visibility("hidden"))) =                    \
+#define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel)                    \
+static const int _loglevel_value___##__provider##___##__name = __loglevel;     \
+LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name  \
+               __attribute__((visibility("hidden"))) =                         \
                &_loglevel_value___##__provider##___##__name;
 
 #include TRACEPOINT_INCLUDE
@@ -1005,7 +1005,7 @@ LTTNG_UST_TP_EXTERN_C const int *_loglevel___##__provider##___##__name       \
 
 #undef TRACEPOINT_MODEL_EMF_URI
 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri)               \
-LTTNG_UST_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name   \
+LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name   \
                __attribute__((visibility("hidden"))) = __uri;             \
 
 #include TRACEPOINT_INCLUDE
@@ -1029,8 +1029,14 @@ extern const struct lttng_ust_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRA
  * Stage 7.1 of tracepoint event generation.
  *
  * Create events description structures. We use a weakref because
- * loglevels are optional. If not declared, the event will point to the
+ * loglevels are optional. If not declared, the event will point to
  * a loglevel that contains NULL.
+ *
+ * C++ requires that const objects have a user-declared default
+ * constructor. However, in both C++ and C, weakref cannot be
+ * initialized because it causes the weakref attribute to be ignored.
+ * Therefore, the loglevel and model_emf_uri pointers are not const
+ * to ensure C++ compilers default-initialize them.
  */
 
 /* Reset all macros within TRACEPOINT_EVENT */
@@ -1071,7 +1077,7 @@ static const struct lttng_ust_event_desc __event_desc___##_provider##_##_name =
 #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args)        \
        &__event_desc___##_provider##_##_name,
 
-static const struct lttng_ust_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
+static const struct lttng_ust_event_desc * const _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
 #include TRACEPOINT_INCLUDE
        NULL,   /* Dummy, C99 forbids 0-len array. */
 };
index 84f55f9a97e177dd45fb6d43af32b911078e7cc9..f918921d4f0c1397944d5a002a1ed2500499c461 100644 (file)
@@ -26,7 +26,7 @@ enum lttng_ust_dynamic_type {
 };
 
 int lttng_ust_dynamic_type_choices(size_t *nr_choices,
-               const struct lttng_ust_event_field ***choices)
+               const struct lttng_ust_event_field * const **choices)
        __attribute__((visibility("hidden")));
 
 const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value)
index 80346ce1b39dbd31a74cab4e9d999d65ecadc170..ad6332fd0c190ef8c03f4a4a7c879cd69ff72301 100644 (file)
@@ -37,7 +37,7 @@
 
 static
 ssize_t count_fields_recursive(size_t nr_fields,
-               const struct lttng_ust_event_field **lttng_fields);
+               const struct lttng_ust_event_field * const *lttng_fields);
 static
 int serialize_one_field(struct lttng_ust_session *session,
                struct ustctl_field *fields, size_t *iter_output,
@@ -46,7 +46,7 @@ static
 int serialize_fields(struct lttng_ust_session *session,
                struct ustctl_field *ustctl_fields,
                size_t *iter_output, size_t nr_lttng_fields,
-               const struct lttng_ust_event_field **lttng_fields);
+               const struct lttng_ust_event_field * const *lttng_fields);
 
 /*
  * Human readable error message.
@@ -883,7 +883,7 @@ ssize_t count_one_type(const struct lttng_ust_type_common *lt)
 
        case lttng_ust_type_dynamic:
        {
-               const struct lttng_ust_event_field **choices;
+               const struct lttng_ust_event_field * const *choices;
                size_t nr_choices;
                int ret;
 
@@ -906,7 +906,7 @@ ssize_t count_one_type(const struct lttng_ust_type_common *lt)
 
 static
 ssize_t count_fields_recursive(size_t nr_fields,
-               const struct lttng_ust_event_field **lttng_fields)
+               const struct lttng_ust_event_field * const *lttng_fields)
 {
        int i;
        ssize_t ret, count = 0;
@@ -991,7 +991,7 @@ int serialize_dynamic_type(struct lttng_ust_session *session,
                struct ustctl_field *fields, size_t *iter_output,
                const char *field_name)
 {
-       const struct lttng_ust_event_field **choices;
+       const struct lttng_ust_event_field * const *choices;
        char tag_field_name[LTTNG_UST_ABI_SYM_NAME_LEN];
        const struct lttng_ust_type_common *tag_type;
        const struct lttng_ust_event_field *tag_field_generic;
@@ -1256,7 +1256,7 @@ static
 int serialize_fields(struct lttng_ust_session *session,
                struct ustctl_field *ustctl_fields,
                size_t *iter_output, size_t nr_lttng_fields,
-               const struct lttng_ust_event_field **lttng_fields)
+               const struct lttng_ust_event_field * const *lttng_fields)
 {
        int ret;
        size_t i;
@@ -1275,7 +1275,7 @@ int alloc_serialize_fields(struct lttng_ust_session *session,
                size_t *_nr_write_fields,
                struct ustctl_field **ustctl_fields,
                size_t nr_fields,
-               const struct lttng_ust_event_field **lttng_fields)
+               const struct lttng_ust_event_field * const *lttng_fields)
 {
        struct ustctl_field *fields;
        int ret;
@@ -1308,7 +1308,7 @@ error_type:
 static
 int serialize_entries(struct ustctl_enum_entry **_entries,
                size_t nr_entries,
-               const struct lttng_ust_enum_entry **lttng_entries)
+               const struct lttng_ust_enum_entry * const *lttng_entries)
 {
        struct ustctl_enum_entry *entries;
        int i;
@@ -1389,7 +1389,7 @@ int ustcomm_register_event(int sock,
        int loglevel,
        const char *signature,          /* event signature (input) */
        size_t nr_fields,               /* fields */
-       const struct lttng_ust_event_field **lttng_fields,
+       const struct lttng_ust_event_field * const *lttng_fields,
        const char *model_emf_uri,
        uint32_t *id)                   /* event id (output) */
 {
@@ -1528,7 +1528,7 @@ int ustcomm_register_enum(int sock,
        int session_objd,               /* session descriptor */
        const char *enum_name,          /* enum name (input) */
        size_t nr_entries,              /* entries */
-       const struct lttng_ust_enum_entry **lttng_entries,
+       const struct lttng_ust_enum_entry * const *lttng_entries,
        uint64_t *id)
 {
        ssize_t len;
index dac9aaed96159318bded85cc540d4aab28079bd2..b4b7fb2c8befdce531d156df911065572852e6b5 100644 (file)
@@ -287,7 +287,7 @@ int ustcomm_register_event(int sock,
        int loglevel,
        const char *signature,          /* event signature (input) */
        size_t nr_fields,               /* fields */
-       const struct lttng_ust_event_field **fields,
+       const struct lttng_ust_event_field * const *fields,
        const char *model_emf_uri,
        uint32_t *id)                   /* event id (output) */
        __attribute__((visibility("hidden")));
@@ -300,7 +300,7 @@ int ustcomm_register_enum(int sock,
        int session_objd,               /* session descriptor */
        const char *enum_name,          /* enum name (input) */
        size_t nr_entries,              /* entries */
-       const struct lttng_ust_enum_entry **entries,
+       const struct lttng_ust_enum_entry * const *entries,
        uint64_t *id)                   /* enum id (output) */
        __attribute__((visibility("hidden")));
 
index 8d3971bfe18917e910ac9a7ddd03c60cb607b30d..9222e1cc2d5091110a0d626e9368a2a1911cfe2f 100644 (file)
@@ -179,7 +179,7 @@ int apply_field_reloc(const struct lttng_ust_event_desc *event_desc,
                const char *field_name,
                enum bytecode_op bytecode_op)
 {
-       const struct lttng_ust_event_field **fields, *field = NULL;
+       const struct lttng_ust_event_field * const *fields, *field = NULL;
        unsigned int nr_fields, i;
        struct load_op *op;
        uint32_t field_offset = 0;
index e8f9fd9fa41808e3df7834288170ecc948ae466d..445a3c398b279c0271f25af7869b1acda7c2559a 100644 (file)
@@ -516,7 +516,7 @@ int lttng_create_enum_check(const struct lttng_ust_type_common *type,
 
 static
 int lttng_create_all_event_enums(size_t nr_fields,
-               const struct lttng_ust_event_field **event_fields,
+               const struct lttng_ust_event_field * const *event_fields,
                struct lttng_ust_session *session)
 {
        size_t i;
index f46c323143deba46ca438468f056d2656d675acc..06333906324040e30e18946106166097cf6abd71 100644 (file)
@@ -161,7 +161,7 @@ const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value)
        return dt_var_fields[value];
 }
 
-int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field ***choices)
+int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field * const **choices)
 {
        *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
        *choices = dt_var_fields;
This page took 0.032035 seconds and 4 git commands to generate.