From 3d33ca1d93088e049c36fc0f417d130bc66b2231 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 19 Apr 2021 10:07:08 -0400 Subject: [PATCH] ust-events.h API const-ness Ensure ust-events.h definitions, fields, and arguments referring to const arrays of pointers are const. Signed-off-by: Mathieu Desnoyers Change-Id: I9b1173221c2cfd2d574c300233e15a3fc0e72bce --- include/lttng/ust-events.h | 10 ++++----- include/lttng/ust-tracepoint-event.h | 24 ++++++++++++++-------- src/common/dynamic-type.h | 2 +- src/common/ustcomm.c | 20 +++++++++--------- src/common/ustcomm.h | 4 ++-- src/lib/lttng-ust/lttng-bytecode.c | 2 +- src/lib/lttng-ust/lttng-events.c | 2 +- src/lib/lttng-ust/lttng-ust-dynamic-type.c | 2 +- 8 files changed, 36 insertions(+), 30 deletions(-) diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 2b035d8f..cf1045bb 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -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; diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index c50047d0..e663e839 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -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. */ }; diff --git a/src/common/dynamic-type.h b/src/common/dynamic-type.h index 84f55f9a..f918921d 100644 --- a/src/common/dynamic-type.h +++ b/src/common/dynamic-type.h @@ -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) diff --git a/src/common/ustcomm.c b/src/common/ustcomm.c index 80346ce1..ad6332fd 100644 --- a/src/common/ustcomm.c +++ b/src/common/ustcomm.c @@ -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; diff --git a/src/common/ustcomm.h b/src/common/ustcomm.h index dac9aaed..b4b7fb2c 100644 --- a/src/common/ustcomm.h +++ b/src/common/ustcomm.h @@ -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"))); diff --git a/src/lib/lttng-ust/lttng-bytecode.c b/src/lib/lttng-ust/lttng-bytecode.c index 8d3971bf..9222e1cc 100644 --- a/src/lib/lttng-ust/lttng-bytecode.c +++ b/src/lib/lttng-ust/lttng-bytecode.c @@ -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; diff --git a/src/lib/lttng-ust/lttng-events.c b/src/lib/lttng-ust/lttng-events.c index e8f9fd9f..445a3c39 100644 --- a/src/lib/lttng-ust/lttng-events.c +++ b/src/lib/lttng-ust/lttng-events.c @@ -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; diff --git a/src/lib/lttng-ust/lttng-ust-dynamic-type.c b/src/lib/lttng-ust/lttng-ust-dynamic-type.c index f46c3231..06333906 100644 --- a/src/lib/lttng-ust/lttng-ust-dynamic-type.c +++ b/src/lib/lttng-ust/lttng-ust-dynamic-type.c @@ -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; -- 2.34.1