From 074ee56d5037489d6e10c49d3e7d2cfdf94857bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 20 Oct 2014 16:03:31 -0400 Subject: [PATCH] Ensure types used for index and count in CTF IR API match MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This makes it easier for users to write code not producing warnings. Signed-off-by: Jérémie Galarneau --- bindings/python/babeltrace.i.in | 60 ++++++++++----------- formats/ctf/ir/event-fields.c | 2 +- formats/ctf/ir/event-types.c | 66 +++++++++++------------- formats/ctf/ir/event.c | 12 ++--- formats/ctf/ir/stream-class.c | 11 ++-- include/babeltrace/ctf-ir/event-fields.h | 2 +- include/babeltrace/ctf-ir/event-types.h | 30 +++++------ include/babeltrace/ctf-ir/event.h | 6 +-- include/babeltrace/ctf-ir/stream-class.h | 4 +- tests/lib/test_ctf_writer.c | 39 +++++--------- 10 files changed, 103 insertions(+), 129 deletions(-) diff --git a/bindings/python/babeltrace.i.in b/bindings/python/babeltrace.i.in index cba70e8f..2dd77a54 100644 --- a/bindings/python/babeltrace.i.in +++ b/bindings/python/babeltrace.i.in @@ -1383,11 +1383,11 @@ void bt_ctf_clock_put(struct bt_ctf_clock *clock); %rename("_bt_ctf_field_type_enumeration_add_mapping") bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end); %rename("_bt_ctf_field_type_enumeration_add_mapping_unsigned") bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end); %rename("_bt_ctf_field_type_enumeration_get_mapping_count") bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration); -%rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **name, int64_t *range_start, int64_t *range_end); -%rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **name, uint64_t *range_start, uint64_t *range_end); -%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_name") bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *index); -%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_value") bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *index); -%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value") bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *index); +%rename("_bt_ctf_field_type_enumeration_get_mapping") bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **name, int64_t *range_start, int64_t *range_end); +%rename("_bt_ctf_field_type_enumeration_get_mapping_unsigned") bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **name, uint64_t *range_start, uint64_t *range_end); +%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_name") bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name); +%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_value") bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value); +%rename("_bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value") bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value); %rename("_bt_ctf_field_type_floating_point_create") bt_ctf_field_type_floating_point_create(void); %rename("_bt_ctf_field_type_floating_point_get_exponent_digits") bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point); %rename("_bt_ctf_field_type_floating_point_set_exponent_digits") bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits); @@ -1396,7 +1396,7 @@ void bt_ctf_clock_put(struct bt_ctf_clock *clock); %rename("_bt_ctf_field_type_structure_create") bt_ctf_field_type_structure_create(void); %rename("_bt_ctf_field_type_structure_add_field") bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name); %rename("_bt_ctf_field_type_structure_get_field_count") bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure); -%rename("_bt_ctf_field_type_structure_get_field") bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **field_name, struct bt_ctf_field_type **field_type, size_t index); +%rename("_bt_ctf_field_type_structure_get_field") bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **field_name, struct bt_ctf_field_type **field_type, int index); %rename("_bt_ctf_field_type_structure_get_field_type_by_name") bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name); %rename("_bt_ctf_field_type_variant_create") bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name); %rename("_bt_ctf_field_type_variant_get_tag_type") bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant); @@ -1405,7 +1405,7 @@ void bt_ctf_clock_put(struct bt_ctf_clock *clock); %rename("_bt_ctf_field_type_variant_get_field_type_by_name") bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name); %rename("_bt_ctf_field_type_variant_get_field_type_from_tag") bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag); %rename("_bt_ctf_field_type_variant_get_field_count") bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant); -%rename("_bt_ctf_field_type_variant_get_field") bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **field_name, struct bt_ctf_field_type **field_type, size_t index); +%rename("_bt_ctf_field_type_variant_get_field") bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **field_name, struct bt_ctf_field_type **field_type, int index); %rename("_bt_ctf_field_type_array_create") bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length); %rename("_bt_ctf_field_type_array_get_element_type") bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array); %rename("_bt_ctf_field_type_array_get_length") bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array); @@ -1435,12 +1435,12 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create(struct bt_ctf_fie struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type(struct bt_ctf_field_type *enumeration); int bt_ctf_field_type_enumeration_add_mapping(struct bt_ctf_field_type *enumeration, const char *name, int64_t range_start, int64_t range_end); int bt_ctf_field_type_enumeration_add_mapping_unsigned(struct bt_ctf_field_type *enumeration, const char *name, uint64_t range_start, uint64_t range_end); -int64_t bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration); -int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT); -int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, size_t index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT); -int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name, size_t *OUTPUT); -int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value, size_t *OUTPUT); -int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value, size_t *OUTPUT); +int bt_ctf_field_type_enumeration_get_mapping_count(struct bt_ctf_field_type *enumeration); +int bt_ctf_field_type_enumeration_get_mapping(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, int64_t *OUTPUT, int64_t *OUTPUT); +int bt_ctf_field_type_enumeration_get_mapping_unsigned(struct bt_ctf_field_type *enumeration, int index, const char **OUTPUT, uint64_t *OUTPUT, uint64_t *OUTPUT); +int bt_ctf_field_type_enumeration_get_mapping_index_by_name(struct bt_ctf_field_type *enumeration, const char *name); +int bt_ctf_field_type_enumeration_get_mapping_index_by_value(struct bt_ctf_field_type *enumeration, int64_t value); +int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(struct bt_ctf_field_type *enumeration, uint64_t value); struct bt_ctf_field_type *bt_ctf_field_type_floating_point_create(void); int bt_ctf_field_type_floating_point_get_exponent_digits(struct bt_ctf_field_type *floating_point); int bt_ctf_field_type_floating_point_set_exponent_digits(struct bt_ctf_field_type *floating_point, unsigned int exponent_digits); @@ -1448,8 +1448,8 @@ int bt_ctf_field_type_floating_point_get_mantissa_digits(struct bt_ctf_field_typ int bt_ctf_field_type_floating_point_set_mantissa_digits(struct bt_ctf_field_type *floating_point, unsigned int mantissa_digits); struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *structure, struct bt_ctf_field_type *field_type, const char *field_name); -int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure); -int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index); +int bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type *structure); +int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *structure, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index); struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name(struct bt_ctf_field_type *structure, const char *field_name); struct bt_ctf_field_type *bt_ctf_field_type_variant_create(struct bt_ctf_field_type *enum_tag, const char *tag_name); struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type(struct bt_ctf_field_type *variant); @@ -1457,8 +1457,8 @@ const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *var int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *variant, struct bt_ctf_field_type *field_type, const char *field_name); struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name(struct bt_ctf_field_type *variant, const char *field_name); struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag(struct bt_ctf_field_type *variant, struct bt_ctf_field *tag); -int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant); -int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, size_t index); +int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *variant); +int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *variant, const char **OUTPUT, struct bt_ctf_field_type **OUTPUT, int index); struct bt_ctf_field_type *bt_ctf_field_type_array_create(struct bt_ctf_field_type *element_type, unsigned int length); struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type(struct bt_ctf_field_type *array); int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *array); @@ -1527,7 +1527,7 @@ void bt_ctf_field_put(struct bt_ctf_field *field); %rename("_bt_ctf_event_class_get_stream_class") bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class); %rename("_bt_ctf_event_class_add_field") bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name); %rename("_bt_ctf_event_class_get_field_count") bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class); -%rename("_bt_ctf_event_class_get_field") bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index); +%rename("_bt_ctf_event_class_get_field") bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, int index); %rename("_bt_ctf_event_class_get_field_by_name") bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name); %rename("_bt_ctf_event_class_get") bt_ctf_event_class_get(struct bt_ctf_event_class *event_class); %rename("_bt_ctf_event_class_put") bt_ctf_event_class_put(struct bt_ctf_event_class *event_class); @@ -1538,8 +1538,8 @@ int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class); int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint32_t id); struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(struct bt_ctf_event_class *event_class); int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name); -int64_t bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class); -int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, size_t index); +int bt_ctf_event_class_get_field_count(struct bt_ctf_event_class *event_class); +int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, int index); struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(struct bt_ctf_event_class *event_class, const char *name); void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class); void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class); @@ -1550,7 +1550,7 @@ void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class); %rename("_bt_ctf_event_get_clock") bt_ctf_event_get_clock(struct bt_ctf_event *event); %rename("_bt_ctf_event_get_payload") bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name); %rename("_bt_ctf_event_set_payload") bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value); -%rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index); +%rename("_bt_ctf_event_get_payload_by_index") bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index); %rename("_bt_ctf_event_get") bt_ctf_event_get(struct bt_ctf_event *event); %rename("_bt_ctf_event_put") bt_ctf_event_put(struct bt_ctf_event *event); @@ -1559,7 +1559,7 @@ struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event); struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event); struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, const char *name); int bt_ctf_event_set_payload(struct bt_ctf_event *event, const char *name, struct bt_ctf_field *value); -struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, size_t index); +struct bt_ctf_field *bt_ctf_event_get_payload_by_index(struct bt_ctf_event *event, int index); void bt_ctf_event_get(struct bt_ctf_event *event); void bt_ctf_event_put(struct bt_ctf_event *event); @@ -1572,7 +1572,7 @@ void bt_ctf_event_put(struct bt_ctf_event *event); %rename("_bt_ctf_stream_class_set_id") bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id); %rename("_bt_ctf_stream_class_add_event_class") bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class); %rename("_bt_ctf_stream_class_get_event_class_count") bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class); -%rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index); +%rename("_bt_ctf_stream_class_get_event_class") bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index); %rename("_bt_ctf_stream_class_get_event_class_by_name") bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name); %rename("_bt_ctf_stream_class_get_packet_context_type") bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class); %rename("_bt_ctf_stream_class_set_packet_context_type") bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type); @@ -1586,8 +1586,8 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, stru int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class); int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, uint32_t id); int bt_ctf_stream_class_add_event_class(struct bt_ctf_stream_class *stream_class, struct bt_ctf_event_class *event_class); -int64_t bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class); -struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, size_t index); +int bt_ctf_stream_class_get_event_class_count(struct bt_ctf_stream_class *stream_class); +struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class(struct bt_ctf_stream_class *stream_class, int index); struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name(struct bt_ctf_stream_class *stream_class, const char *name); struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(struct bt_ctf_stream_class *stream_class); int bt_ctf_stream_class_set_packet_context_type(struct bt_ctf_stream_class *stream_class, struct bt_ctf_field_type *packet_context_type); @@ -2076,9 +2076,9 @@ class CTFWriter: """ def get_mapping_by_name(self, name): - ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name( + index = _bt_ctf_field_type_enumeration_get_mapping_index_by_name( self._ft, name) - if ret < 0: + if index < 0: return None if self.container.signed: @@ -2102,13 +2102,13 @@ class CTFWriter: def get_mapping_by_value(self, value): if value < 0: - ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value( + index = _bt_ctf_field_type_enumeration_get_mapping_index_by_value( self._ft, value) else: - ret, index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( + index = _bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( self._ft, value) - if ret < 0: + if index < 0: return None if self.container.signed: diff --git a/formats/ctf/ir/event-fields.c b/formats/ctf/ir/event-fields.c index 809ffc33..52682b65 100644 --- a/formats/ctf/ir/event-fields.c +++ b/formats/ctf/ir/event-fields.c @@ -372,7 +372,7 @@ error: } struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( - struct bt_ctf_field *field, size_t index) + struct bt_ctf_field *field, int index) { int ret; const char *field_name; diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 5e9b31fe..1d5f0909 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -703,10 +703,10 @@ end: return name; } -int64_t bt_ctf_field_type_enumeration_get_mapping_count( +int bt_ctf_field_type_enumeration_get_mapping_count( struct bt_ctf_field_type *type) { - int64_t ret = 0; + int ret = 0; struct bt_ctf_field_type_enumeration *enumeration; if (!type || (type->declaration->id != CTF_TYPE_ENUM)) { @@ -716,14 +716,14 @@ int64_t bt_ctf_field_type_enumeration_get_mapping_count( enumeration = container_of(type, struct bt_ctf_field_type_enumeration, parent); - ret = enumeration->entries->len; + ret = (int) enumeration->entries->len; end: return ret; } static inline struct enumeration_mapping *get_enumeration_mapping( - struct bt_ctf_field_type *type, size_t index) + struct bt_ctf_field_type *type, int index) { struct enumeration_mapping *mapping = NULL; struct bt_ctf_field_type_enumeration *enumeration; @@ -740,13 +740,13 @@ end: } int bt_ctf_field_type_enumeration_get_mapping( - struct bt_ctf_field_type *type, size_t index, + struct bt_ctf_field_type *type, int index, const char **string, int64_t *range_start, int64_t *range_end) { struct enumeration_mapping *mapping; int ret = 0; - if (!type || !string || !range_start || !range_end || + if (!type || index < 0 || !string || !range_start || !range_end || (type->declaration->id != CTF_TYPE_ENUM)) { ret = -1; goto end; @@ -766,13 +766,13 @@ end: } int bt_ctf_field_type_enumeration_get_mapping_unsigned( - struct bt_ctf_field_type *type, size_t index, + struct bt_ctf_field_type *type, int index, const char **string, uint64_t *range_start, uint64_t *range_end) { struct enumeration_mapping *mapping; int ret = 0; - if (!type || !string || !range_start || !range_end || + if (!type || index < 0 || !string || !range_start || !range_end || (type->declaration->id != CTF_TYPE_ENUM)) { ret = -1; goto end; @@ -792,15 +792,13 @@ end: } int bt_ctf_field_type_enumeration_get_mapping_index_by_name( - struct bt_ctf_field_type *type, const char *name, - size_t *index) + struct bt_ctf_field_type *type, const char *name) { - size_t i; GQuark name_quark; struct bt_ctf_field_type_enumeration *enumeration; - int ret = 0; + int i, ret = 0; - if (!type || !name || !index || + if (!type || !name || (type->declaration->id != CTF_TYPE_ENUM)) { ret = -1; goto end; @@ -819,7 +817,7 @@ int bt_ctf_field_type_enumeration_get_mapping_index_by_name( get_enumeration_mapping(type, i); if (mapping->string == name_quark) { - *index = i; + ret = i; goto end; } } @@ -830,14 +828,12 @@ end: } int bt_ctf_field_type_enumeration_get_mapping_index_by_value( - struct bt_ctf_field_type *type, int64_t value, - size_t *index) + struct bt_ctf_field_type *type, int64_t value) { struct bt_ctf_field_type_enumeration *enumeration; - size_t i; - int ret = 0; + int i, ret = 0; - if (!type || !index || (type->declaration->id != CTF_TYPE_ENUM)) { + if (!type || (type->declaration->id != CTF_TYPE_ENUM)) { ret = -1; goto end; } @@ -850,7 +846,7 @@ int bt_ctf_field_type_enumeration_get_mapping_index_by_value( if (value >= mapping->range_start._signed && value <= mapping->range_end._signed) { - *index = i; + ret = i; goto end; } } @@ -861,14 +857,12 @@ end: } int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( - struct bt_ctf_field_type *type, uint64_t value, - size_t *index) + struct bt_ctf_field_type *type, uint64_t value) { struct bt_ctf_field_type_enumeration *enumeration; - size_t i; - int ret = 0; + int i, ret = 0; - if (!type || !index || (type->declaration->id != CTF_TYPE_ENUM)) { + if (!type || (type->declaration->id != CTF_TYPE_ENUM)) { ret = -1; goto end; } @@ -881,7 +875,7 @@ int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( if (value >= mapping->range_start._unsigned && value <= mapping->range_end._unsigned) { - *index = i; + ret = i; goto end; } } @@ -1061,10 +1055,10 @@ end: return ret; } -int64_t bt_ctf_field_type_structure_get_field_count( +int bt_ctf_field_type_structure_get_field_count( struct bt_ctf_field_type *type) { - int64_t ret = 0; + int ret = 0; struct bt_ctf_field_type_structure *structure; if (!type || (type->declaration->id != CTF_TYPE_STRUCT)) { @@ -1074,20 +1068,20 @@ int64_t bt_ctf_field_type_structure_get_field_count( structure = container_of(type, struct bt_ctf_field_type_structure, parent); - ret = structure->fields->len; + ret = (int) structure->fields->len; end: return ret; } int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *type, const char **field_name, struct bt_ctf_field_type **field_type, - size_t index) + int index) { struct bt_ctf_field_type_structure *structure; struct structure_field *field; int ret = 0; - if (!type || !field_name || !field_type || + if (!type || index < 0 || !field_name || !field_type || (type->declaration->id != CTF_TYPE_STRUCT)) { ret = -1; goto end; @@ -1298,9 +1292,9 @@ end: return field_type; } -int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *type) +int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *type) { - int64_t ret = 0; + int ret = 0; struct bt_ctf_field_type_variant *variant; if (!type || (type->declaration->id != CTF_TYPE_VARIANT)) { @@ -1310,7 +1304,7 @@ int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *type variant = container_of(type, struct bt_ctf_field_type_variant, parent); - ret = variant->fields->len; + ret = (int) variant->fields->len; end: return ret; @@ -1318,13 +1312,13 @@ end: int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *type, const char **field_name, struct bt_ctf_field_type **field_type, - size_t index) + int index) { struct bt_ctf_field_type_variant *variant; struct structure_field *field; int ret = 0; - if (!type || !field_name || !field_type || + if (!type || index < 0 || !field_name || !field_type || (type->declaration->id != CTF_TYPE_VARIANT)) { ret = -1; goto end; diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index 99294979..58c9c494 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -153,10 +153,10 @@ end: return ret; } -int64_t bt_ctf_event_class_get_field_count( +int bt_ctf_event_class_get_field_count( struct bt_ctf_event_class *event_class) { - int64_t ret; + int ret; if (!event_class) { ret = -1; @@ -170,11 +170,11 @@ end: int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, - size_t index) + int index) { int ret; - if (!event_class) { + if (!event_class || index < 0) { ret = -1; goto end; } @@ -331,11 +331,11 @@ end: } struct bt_ctf_field *bt_ctf_event_get_payload_by_index( - struct bt_ctf_event *event, size_t index) + struct bt_ctf_event *event, int index) { struct bt_ctf_field *field = NULL; - if (!event) { + if (!event || index < 0) { goto end; } diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 48c3d4c5..aab7f29a 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -203,27 +203,28 @@ end: return ret; } -int64_t bt_ctf_stream_class_get_event_class_count( +int bt_ctf_stream_class_get_event_class_count( struct bt_ctf_stream_class *stream_class) { - int64_t ret; + int ret; if (!stream_class) { ret = -1; goto end; } - ret = (int64_t) stream_class->event_classes->len; + ret = (int) stream_class->event_classes->len; end: return ret; } struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( - struct bt_ctf_stream_class *stream_class, size_t index) + struct bt_ctf_stream_class *stream_class, int index) { struct bt_ctf_event_class *event_class = NULL; - if (!stream_class || index >= stream_class->event_classes->len) { + if (!stream_class || index < 0 || + index >= stream_class->event_classes->len) { goto end; } diff --git a/include/babeltrace/ctf-ir/event-fields.h b/include/babeltrace/ctf-ir/event-fields.h index e08e36b9..f0dd825c 100644 --- a/include/babeltrace/ctf-ir/event-fields.h +++ b/include/babeltrace/ctf-ir/event-fields.h @@ -82,7 +82,7 @@ extern struct bt_ctf_field *bt_ctf_field_structure_get_field( * Returns a field instance on success, NULL on error. */ extern struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( - struct bt_ctf_field *structure, size_t index); + struct bt_ctf_field *structure, int index); /* * bt_ctf_field_array_get_field: get an array's field at position "index". diff --git a/include/babeltrace/ctf-ir/event-types.h b/include/babeltrace/ctf-ir/event-types.h index 18929eaa..69f4df7a 100644 --- a/include/babeltrace/ctf-ir/event-types.h +++ b/include/babeltrace/ctf-ir/event-types.h @@ -229,7 +229,7 @@ extern int bt_ctf_field_type_enumeration_add_mapping_unsigned( * * Returns the mapping count on success, a negative value on error. */ -extern int64_t bt_ctf_field_type_enumeration_get_mapping_count( +extern int bt_ctf_field_type_enumeration_get_mapping_count( struct bt_ctf_field_type *enumeration); /* @@ -247,7 +247,7 @@ extern int64_t bt_ctf_field_type_enumeration_get_mapping_count( * Returns 0 on success, a negative value on error. */ extern int bt_ctf_field_type_enumeration_get_mapping( - struct bt_ctf_field_type *enumeration, size_t index, + struct bt_ctf_field_type *enumeration, int index, const char **name, int64_t *range_start, int64_t *range_end); /* @@ -265,7 +265,7 @@ extern int bt_ctf_field_type_enumeration_get_mapping( * Returns 0 on success, a negative value on error. */ extern int bt_ctf_field_type_enumeration_get_mapping_unsigned( - struct bt_ctf_field_type *enumeration, size_t index, + struct bt_ctf_field_type *enumeration, int index, const char **name, uint64_t *range_start, uint64_t *range_end); @@ -275,13 +275,11 @@ extern int bt_ctf_field_type_enumeration_get_mapping_unsigned( * * @param enumeration Enumeration type. * @param name Mapping name. - * @param index Pointer where the enumeration's mapping index will be returned. * - * Returns 0 on success, a negative value on error. + * Returns mapping index on success, a negative value on error. */ extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name( - struct bt_ctf_field_type *enumeration, const char *name, - size_t *index); + struct bt_ctf_field_type *enumeration, const char *name); /* * bt_ctf_field_type_enumeration_get_mapping_index_by_value: get an @@ -289,13 +287,11 @@ extern int bt_ctf_field_type_enumeration_get_mapping_index_by_name( * * @param enumeration Enumeration type. * @param value Value. - * @param index Pointer where the enumeration's mapping index will be returned. * - * Returns 0 on success, a negative value on error. + * Returns mapping index on success, a negative value on error. */ extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value( - struct bt_ctf_field_type *enumeration, int64_t value, - size_t *index); + struct bt_ctf_field_type *enumeration, int64_t value); /* * bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value: get an @@ -303,13 +299,11 @@ extern int bt_ctf_field_type_enumeration_get_mapping_index_by_value( * * @param enumeration Enumeration type. * @param value Value. - * @param index Pointer where the enumeration's mapping index will be returned. * * Returns 0 on success, a negative value on error. */ extern int bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value( - struct bt_ctf_field_type *enumeration, uint64_t value, - size_t *index); + struct bt_ctf_field_type *enumeration, uint64_t value); /* * bt_ctf_field_type_floating_point_create: create a floating point field type. @@ -412,7 +406,7 @@ extern int bt_ctf_field_type_structure_add_field( * * Returns the field count on success, a negative value on error. */ -extern int64_t bt_ctf_field_type_structure_get_field_count( +extern int bt_ctf_field_type_structure_get_field_count( struct bt_ctf_field_type *structure); /* @@ -430,7 +424,7 @@ extern int64_t bt_ctf_field_type_structure_get_field_count( extern int bt_ctf_field_type_structure_get_field( struct bt_ctf_field_type *structure, const char **field_name, struct bt_ctf_field_type **field_type, - size_t index); + int index); /* * bt_ctf_field_type_structure_get_field_type_by_name: get a structure field's @@ -531,7 +525,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( * * Returns the field count on success, a negative value on error. */ -extern int64_t bt_ctf_field_type_variant_get_field_count( +extern int bt_ctf_field_type_variant_get_field_count( struct bt_ctf_field_type *variant); /* @@ -548,7 +542,7 @@ extern int64_t bt_ctf_field_type_variant_get_field_count( */ extern int bt_ctf_field_type_variant_get_field( struct bt_ctf_field_type *variant, const char **field_name, - struct bt_ctf_field_type **field_type, size_t index); + struct bt_ctf_field_type **field_type, int index); /* * bt_ctf_field_type_array_create: create an array field type. diff --git a/include/babeltrace/ctf-ir/event.h b/include/babeltrace/ctf-ir/event.h index 7daab395..1646761a 100644 --- a/include/babeltrace/ctf-ir/event.h +++ b/include/babeltrace/ctf-ir/event.h @@ -126,7 +126,7 @@ extern int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, * * Returns the event class' field count, a negative value on error. */ -extern int64_t bt_ctf_event_class_get_field_count( +extern int bt_ctf_event_class_get_field_count( struct bt_ctf_event_class *event_class); /* @@ -143,7 +143,7 @@ extern int64_t bt_ctf_event_class_get_field_count( */ extern int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, const char **field_name, struct bt_ctf_field_type **field_type, - size_t index); + int index); /* * bt_ctf_event_class_get_field_type_by_name: Get an event class's field by name @@ -251,7 +251,7 @@ extern int bt_ctf_event_set_payload(struct bt_ctf_event *event, * Returns the event's field, NULL on error. */ extern struct bt_ctf_field *bt_ctf_event_get_payload_by_index( - struct bt_ctf_event *event, size_t index); + struct bt_ctf_event *event, int index); /* * bt_ctf_event_get and bt_ctf_event_put: increment and decrement diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index 4055ea13..d64e7141 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -144,7 +144,7 @@ extern int bt_ctf_stream_class_add_event_class( * * Returns the stream class' event count, a negative value on error. */ -extern int64_t bt_ctf_stream_class_get_event_class_count( +extern int bt_ctf_stream_class_get_event_class_count( struct bt_ctf_stream_class *stream_class); /* @@ -156,7 +156,7 @@ extern int64_t bt_ctf_stream_class_get_event_class_count( * Returns event class, NULL on error. */ extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( - struct bt_ctf_stream_class *stream_class, size_t index); + struct bt_ctf_stream_class *stream_class, int index); /* * bt_ctf_stream_class_get_event_class_by_name: Get stream class event class by diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index 42277026..bd33ab70 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -303,7 +303,6 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, const char *mapping_name_negative_test = "negative_value"; const char *ret_char; double ret_double; - size_t ret_size_t; int64_t ret_range_start_int64_t, ret_range_end_int64_t; uint64_t ret_range_start_uint64_t, ret_range_end_uint64_t; struct bt_ctf_clock *ret_clock; @@ -365,15 +364,11 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, -54, -55), "bt_ctf_field_type_enumeration_add_mapping rejects mapping where end < start"); bt_ctf_field_type_enumeration_add_mapping(enum_type, "another entry", -42000, -13000); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(NULL, -42, &ret_size_t) < 0, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(NULL, -42) < 0, "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles a NULL field type correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, -42, NULL) < 0, - "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles a NULL index correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, 1000000, &ret_size_t) < 0, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, 1000000) < 0, "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles invalid values correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, -55, &ret_size_t) == 0, - "bt_ctf_field_type_enumeration_get_mapping_index_by_value handles invalid values correctly"); - ok(ret_size_t == 1, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_value(enum_type, -55) == 1, "bt_ctf_field_type_enumeration_get_mapping_index_by_value returns the correct index"); ok(bt_ctf_event_class_add_field(simple_event_class, enum_type, @@ -619,7 +614,6 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, uint64_t ret_unsigned_int; int64_t ret_signed_int; const char *ret_string; - size_t ret_size_t; struct bt_ctf_stream_class *ret_stream_class; struct bt_ctf_event_class *ret_event_class; struct bt_ctf_field *packet_context, *packet_context_field; @@ -660,30 +654,21 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, bt_ctf_field_type_enumeration_add_mapping(enum_variant_type, "UINT35_TYPE", 2, 7); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL, "INT16_TYPE", - &ret_size_t) < 0, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(NULL, + "INT16_TYPE") < 0, "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL field type correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(enum_variant_type, NULL, - &ret_size_t) < 0, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name( + enum_variant_type, NULL) < 0, "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL name correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(enum_variant_type, "INT16_TYPE", - NULL) < 0, - "bt_ctf_field_type_enumeration_get_mapping_index_by_name handles a NULL index correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name(enum_variant_type, "INT16_TYPE", - &ret_size_t) == 0, - "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns a value"); - ok(ret_size_t == 1, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_name( + enum_variant_type, "INT16_TYPE") == 1, "bt_ctf_field_type_enumeration_get_mapping_index_by_name returns the correct index"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL, 1, &ret_size_t) < 0, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(NULL, 1) < 0, "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL field type correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, 1, NULL) < 0, - "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles a NULL index correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, -42, &ret_size_t) < 0, - "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly"); - ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, 5, &ret_size_t) == 0, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, -42) < 0, "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value handles invalid values correctly"); - ok(ret_size_t == 2, + ok(bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value(enum_variant_type, 5) == 2, "bt_ctf_field_type_enumeration_get_mapping_index_by_unsigned_value returns the correct index"); ok(bt_ctf_field_type_variant_add_field(variant_type, uint_3_type, -- 2.34.1