Ensure types used for index and count in CTF IR API match
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Oct 2014 20:03:31 +0000 (16:03 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 21 Oct 2014 22:05:20 +0000 (18:05 -0400)
This makes it easier for users to write code not producing
warnings.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/babeltrace.i.in
formats/ctf/ir/event-fields.c
formats/ctf/ir/event-types.c
formats/ctf/ir/event.c
formats/ctf/ir/stream-class.c
include/babeltrace/ctf-ir/event-fields.h
include/babeltrace/ctf-ir/event-types.h
include/babeltrace/ctf-ir/event.h
include/babeltrace/ctf-ir/stream-class.h
tests/lib/test_ctf_writer.c

index cba70e8fe5c44a8864207feb2f24be3ae7bb2a2f..2dd77a549cf9694edb1a95dcd9ed51df6fefc540 100644 (file)
@@ -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:
index 809ffc33a95300d22f38bd1ed33b088c5d7378e0..52682b65e1cb1330456487598691dcab1a00caac 100644 (file)
@@ -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;
index 5e9b31fe954b869e7c46c9aeb6c27543adffe1ed..1d5f0909a16213894925711cf6d568f97ffae11d 100644 (file)
@@ -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;
index 99294979541d1aaaf3509e2a7d06a27d6b50e766..58c9c494b5c355a0bcf333b438226828fe723da3 100644 (file)
@@ -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;
        }
 
index 48c3d4c5c10970a37b8219a862c555185d45115b..aab7f29afa08ded27f7fc266e43b728c2c2901c3 100644 (file)
@@ -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;
        }
 
index e08e36b9787ec0363c73e8e130d0b2564a51b6f1..f0dd825ceb24485ddf034d7f99e2ee2d0e51ee90 100644 (file)
@@ -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".
index 18929eaa4ac45945fa8a886c1a0983ede553e951..69f4df7a518b0c2873be8567e4c4fa715b82de8d 100644 (file)
@@ -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.
index 7daab39578c24882dc18c868251d93b6faa01372..1646761a535c5719b45fa3a31e984dc6c4615a4b 100644 (file)
@@ -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
index 4055ea13b4b8d4b82bb41ae8425aaa42b96293c7..d64e71413df61bd62491bf3dcd7fa51c60147570 100644 (file)
@@ -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
index 42277026fcb9b2ac95e31dcdadd7305ae9ed0f22..bd33ab70bb7e2a5afb64e45f0efa819541b6ab65 100644 (file)
@@ -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,
This page took 0.040836 seconds and 4 git commands to generate.