From 544d0515ffa2d011247e4f1d7cad5770b8ec7033 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 26 Apr 2017 17:30:51 -0400 Subject: [PATCH] Standardize *get_*_count() functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit All "count" functions now return the count as an `int64_t` value, returning -1 on error. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- cli/babeltrace.c | 6 +-- .../babeltrace/ctf-ir/attributes-internal.h | 2 +- include/babeltrace/ctf-ir/event-class.h | 4 +- include/babeltrace/ctf-ir/field-path.h | 3 +- .../babeltrace/ctf-ir/field-types-internal.h | 3 +- include/babeltrace/ctf-ir/field-types.h | 6 +-- include/babeltrace/ctf-ir/fields.h | 1 + include/babeltrace/ctf-ir/stream-class.h | 2 +- include/babeltrace/ctf-ir/trace.h | 10 +++-- include/babeltrace/ctf-ir/visitor-internal.h | 2 +- .../ctf-writer/serialize-internal.h | 2 +- .../graph/clock-class-priority-map.h | 2 +- include/babeltrace/graph/component-filter.h | 8 ++-- include/babeltrace/graph/component-internal.h | 4 +- include/babeltrace/graph/component-sink.h | 4 +- include/babeltrace/graph/component-source.h | 4 +- include/babeltrace/mmap-align-internal.h | 3 +- include/babeltrace/plugin/plugin.h | 5 ++- include/babeltrace/values.h | 10 ++--- lib/ctf-ir/attributes.c | 2 +- lib/ctf-ir/event-class.c | 12 +++--- lib/ctf-ir/field-path.c | 5 ++- lib/ctf-ir/field-types.c | 34 ++++++++-------- lib/ctf-ir/stream-class.c | 7 ++-- lib/ctf-ir/trace.c | 28 +++++++------ lib/graph/clock-class-priority-map.c | 6 +-- lib/graph/component.c | 4 +- lib/graph/filter.c | 22 +++++----- lib/graph/graph.c | 40 ++++++++++--------- lib/graph/sink.c | 13 +++--- lib/graph/source.c | 10 ++--- lib/plugin/plugin.c | 6 +-- lib/values.c | 12 +++--- plugins/utils/muxer/muxer.c | 8 ++-- tests/plugins/test-utils-muxer.c | 30 +++++++------- 35 files changed, 166 insertions(+), 154 deletions(-) diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 821772e1..1a699909 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -629,8 +629,8 @@ end: static void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) { - int i; - int count; + int64_t i; + int64_t count; count = bt_plugin_set_get_plugin_count(plugin_set); assert(count >= 0); @@ -864,7 +864,7 @@ static int cmd_help(struct bt_config *cfg) printf(" %sComponent classes%s: %d\n", bt_common_color_bold(), bt_common_color_reset(), - bt_plugin_get_component_class_count(plugin)); + (int) bt_plugin_get_component_class_count(plugin)); if (cfg->cmd_data.help.cfg_component->type != diff --git a/include/babeltrace/ctf-ir/attributes-internal.h b/include/babeltrace/ctf-ir/attributes-internal.h index b6a15a8c..fc82e729 100644 --- a/include/babeltrace/ctf-ir/attributes-internal.h +++ b/include/babeltrace/ctf-ir/attributes-internal.h @@ -42,7 +42,7 @@ BT_HIDDEN void bt_ctf_attributes_destroy(struct bt_value *attr_obj); BT_HIDDEN -int bt_ctf_attributes_get_count(struct bt_value *attr_obj); +int64_t bt_ctf_attributes_get_count(struct bt_value *attr_obj); BT_HIDDEN const char *bt_ctf_attributes_get_field_name(struct bt_value *attr_obj, diff --git a/include/babeltrace/ctf-ir/event-class.h b/include/babeltrace/ctf-ir/event-class.h index 16fbcfb3..62791967 100644 --- a/include/babeltrace/ctf-ir/event-class.h +++ b/include/babeltrace/ctf-ir/event-class.h @@ -241,7 +241,7 @@ extern int bt_ctf_event_class_set_id( @sa bt_ctf_event_class_get_attribute_value(): Returns the value of the attribute of a given event class at a given index. */ -extern int bt_ctf_event_class_get_attribute_count( +extern int64_t bt_ctf_event_class_get_attribute_count( struct bt_ctf_event_class *event_class); /** @@ -482,7 +482,7 @@ bt_ctf_field_type_structure_get_field_count(). @prenotnull{event_class} @postrefcountsame{event_class} */ -extern int bt_ctf_event_class_get_field_count( +extern int64_t bt_ctf_event_class_get_field_count( struct bt_ctf_event_class *event_class); /** diff --git a/include/babeltrace/ctf-ir/field-path.h b/include/babeltrace/ctf-ir/field-path.h index 7b009828..e53b50f1 100644 --- a/include/babeltrace/ctf-ir/field-path.h +++ b/include/babeltrace/ctf-ir/field-path.h @@ -28,6 +28,7 @@ * http://www.efficios.com/ctf */ +#include #include #ifdef __cplusplus @@ -109,7 +110,7 @@ extern enum bt_ctf_scope bt_ctf_field_path_get_root_scope( @prenotnull{field_path} @postrefcountsame{field_path} */ -extern int bt_ctf_field_path_get_index_count( +extern int64_t bt_ctf_field_path_get_index_count( const struct bt_ctf_field_path *field_path); /** diff --git a/include/babeltrace/ctf-ir/field-types-internal.h b/include/babeltrace/ctf-ir/field-types-internal.h index 129446bd..f54e859b 100644 --- a/include/babeltrace/ctf-ir/field-types-internal.h +++ b/include/babeltrace/ctf-ir/field-types-internal.h @@ -27,6 +27,7 @@ * SOFTWARE. */ +#include #include #include #include @@ -214,7 +215,7 @@ int bt_ctf_field_type_sequence_set_element_type(struct bt_ctf_field_type *array, struct bt_ctf_field_type *element_type); BT_HIDDEN -int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type); +int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *type); BT_HIDDEN struct bt_ctf_field_type *bt_ctf_field_type_get_field_at_index( diff --git a/include/babeltrace/ctf-ir/field-types.h b/include/babeltrace/ctf-ir/field-types.h index 06c77379..3e35a8d0 100644 --- a/include/babeltrace/ctf-ir/field-types.h +++ b/include/babeltrace/ctf-ir/field-types.h @@ -1336,7 +1336,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type( @preisenumft{enum_field_type} @postrefcountsame{enum_field_type} */ -extern int bt_ctf_field_type_enumeration_get_mapping_count( +extern int64_t bt_ctf_field_type_enumeration_get_mapping_count( struct bt_ctf_field_type *enum_field_type); /** @@ -1921,7 +1921,7 @@ extern struct bt_ctf_field_type *bt_ctf_field_type_structure_create(void); @preisstructft{struct_field_type} @postrefcountsame{struct_field_type} */ -extern int bt_ctf_field_type_structure_get_field_count( +extern int64_t bt_ctf_field_type_structure_get_field_count( struct bt_ctf_field_type *struct_field_type); /** @@ -2400,7 +2400,7 @@ extern struct bt_ctf_field_path *bt_ctf_field_type_variant_get_tag_field_path( @preisvarft{variant_field_type} @postrefcountsame{variant_field_type} */ -extern int bt_ctf_field_type_variant_get_field_count( +extern int64_t bt_ctf_field_type_variant_get_field_count( struct bt_ctf_field_type *variant_field_type); /** diff --git a/include/babeltrace/ctf-ir/fields.h b/include/babeltrace/ctf-ir/fields.h index 8578b518..abdc3dd1 100644 --- a/include/babeltrace/ctf-ir/fields.h +++ b/include/babeltrace/ctf-ir/fields.h @@ -32,6 +32,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index 2111ca1f..dc7b35d6 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -474,7 +474,7 @@ extern int bt_ctf_stream_class_set_event_context_type( @prenotnull{stream_class} @postrefcountsame{stream_class} */ -extern int bt_ctf_stream_class_get_event_class_count( +extern int64_t bt_ctf_stream_class_get_event_class_count( struct bt_ctf_stream_class *stream_class); /** diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index a9e4fa89..16cec454 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -293,7 +293,7 @@ extern int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace_class, @prenotnull{trace_class} @postrefcountsame{trace_class} */ -extern int bt_ctf_trace_get_environment_field_count( +extern int64_t bt_ctf_trace_get_environment_field_count( struct bt_ctf_trace *trace_class); /** @@ -548,7 +548,8 @@ extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace_class, @prenotnull{trace_class} @postrefcountsame{trace_class} */ -extern int bt_ctf_trace_get_clock_class_count(struct bt_ctf_trace *trace_class); +extern int64_t bt_ctf_trace_get_clock_class_count( + struct bt_ctf_trace *trace_class); /** @brief Returns the CTF IR clock class at index \p index in the CTF @@ -645,7 +646,8 @@ extern int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace_class, @prenotnull{trace_class} @postrefcountsame{trace_class} */ -extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace_class); +extern int64_t bt_ctf_trace_get_stream_class_count( + struct bt_ctf_trace *trace_class); /** @brief Returns the stream class at index \p index in the CTF IR trace @@ -742,7 +744,7 @@ extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace_class, @prenotnull{trace_class} @postrefcountsame{trace_class} */ -extern int bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace_class); +extern int64_t bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace_class); /** @brief Returns the stream at index \p index in the CTF IR trace diff --git a/include/babeltrace/ctf-ir/visitor-internal.h b/include/babeltrace/ctf-ir/visitor-internal.h index e37172e1..7e5e634b 100644 --- a/include/babeltrace/ctf-ir/visitor-internal.h +++ b/include/babeltrace/ctf-ir/visitor-internal.h @@ -31,7 +31,7 @@ #include typedef void *(*bt_child_accessor)(void *object, int index); -typedef int (*bt_child_count_accessor)(void *object); +typedef int64_t (*bt_child_count_accessor)(void *object); typedef int (*bt_child_visitor)(void *object, bt_ctf_visitor visitor, void *data); diff --git a/include/babeltrace/ctf-writer/serialize-internal.h b/include/babeltrace/ctf-writer/serialize-internal.h index 15ced8de..6095ae64 100644 --- a/include/babeltrace/ctf-writer/serialize-internal.h +++ b/include/babeltrace/ctf-writer/serialize-internal.h @@ -110,7 +110,7 @@ char *bt_ctf_stream_pos_get_addr(struct bt_ctf_stream_pos *pos) { /* Only makes sense to get the address after aligning on CHAR_BIT */ assert(!(pos->offset % CHAR_BIT)); - return mmap_align_addr(pos->base_mma) + + return ((char *) mmap_align_addr(pos->base_mma)) + pos->mmap_base_offset + (pos->offset / CHAR_BIT); } diff --git a/include/babeltrace/graph/clock-class-priority-map.h b/include/babeltrace/graph/clock-class-priority-map.h index 95d3168b..f810a443 100644 --- a/include/babeltrace/graph/clock-class-priority-map.h +++ b/include/babeltrace/graph/clock-class-priority-map.h @@ -109,7 +109,7 @@ extern struct bt_clock_class_priority_map *bt_clock_class_priority_map_create(); @prenotnull{clock_class_priority_map} @postrefcountsame{clock_class_priority_map} */ -extern int bt_clock_class_priority_map_get_clock_class_count( +extern int64_t bt_clock_class_priority_map_get_clock_class_count( struct bt_clock_class_priority_map *clock_class_priority_map); /** diff --git a/include/babeltrace/graph/component-filter.h b/include/babeltrace/graph/component-filter.h index f9e681f3..557432d8 100644 --- a/include/babeltrace/graph/component-filter.h +++ b/include/babeltrace/graph/component-filter.h @@ -37,8 +37,8 @@ extern "C" { struct bt_port; struct bt_component; -extern enum bt_component_status bt_component_filter_get_input_port_count( - struct bt_component *component, uint64_t *count); +extern int64_t bt_component_filter_get_input_port_count( + struct bt_component *component); extern struct bt_port *bt_component_filter_get_input_port( struct bt_component *component, const char *name); extern struct bt_port *bt_component_filter_get_input_port_at_index( @@ -46,8 +46,8 @@ extern struct bt_port *bt_component_filter_get_input_port_at_index( extern struct bt_port *bt_component_filter_get_default_input_port( struct bt_component *component); -extern enum bt_component_status bt_component_filter_get_output_port_count( - struct bt_component *component, uint64_t *count); +extern int64_t bt_component_filter_get_output_port_count( + struct bt_component *component); extern struct bt_port *bt_component_filter_get_output_port( struct bt_component *component, const char *name); extern struct bt_port *bt_component_filter_get_output_port_at_index( diff --git a/include/babeltrace/graph/component-internal.h b/include/babeltrace/graph/component-internal.h index 27b03b09..ae08b8b7 100644 --- a/include/babeltrace/graph/component-internal.h +++ b/include/babeltrace/graph/component-internal.h @@ -106,10 +106,10 @@ void bt_component_set_graph(struct bt_component *component, struct bt_graph *graph); BT_HIDDEN -uint64_t bt_component_get_input_port_count(struct bt_component *comp); +int64_t bt_component_get_input_port_count(struct bt_component *comp); BT_HIDDEN -uint64_t bt_component_get_output_port_count(struct bt_component *comp); +int64_t bt_component_get_output_port_count(struct bt_component *comp); BT_HIDDEN struct bt_port *bt_component_get_input_port_at_index(struct bt_component *comp, diff --git a/include/babeltrace/graph/component-sink.h b/include/babeltrace/graph/component-sink.h index 3bbfbb11..3c462bff 100644 --- a/include/babeltrace/graph/component-sink.h +++ b/include/babeltrace/graph/component-sink.h @@ -36,8 +36,8 @@ extern "C" { struct bt_component; struct bt_notification; -extern enum bt_component_status bt_component_sink_get_input_port_count( - struct bt_component *component, uint64_t *count); +extern int64_t bt_component_sink_get_input_port_count( + struct bt_component *component); extern struct bt_port *bt_component_sink_get_input_port( struct bt_component *component, const char *name); extern struct bt_port *bt_component_sink_get_input_port_at_index( diff --git a/include/babeltrace/graph/component-source.h b/include/babeltrace/graph/component-source.h index 165ba0d2..24a8c006 100644 --- a/include/babeltrace/graph/component-source.h +++ b/include/babeltrace/graph/component-source.h @@ -37,8 +37,8 @@ extern "C" { struct bt_component; struct bt_notification_iterator; -extern enum bt_component_status bt_component_source_get_output_port_count( - struct bt_component *component, uint64_t *count); +extern int64_t bt_component_source_get_output_port_count( + struct bt_component *component); extern struct bt_port *bt_component_source_get_output_port( struct bt_component *component, const char *name); extern struct bt_port *bt_component_source_get_output_port_at_index( diff --git a/include/babeltrace/mmap-align-internal.h b/include/babeltrace/mmap-align-internal.h index ccb0e1f4..d89affb5 100644 --- a/include/babeltrace/mmap-align-internal.h +++ b/include/babeltrace/mmap-align-internal.h @@ -27,6 +27,7 @@ #include #include +#include #include /* @@ -71,7 +72,7 @@ struct mmap_align *mmap_align(size_t length, int prot, free(mma); return MAP_FAILED; } - mma->addr = mma->page_aligned_addr + (offset - page_aligned_offset); + mma->addr = ((uint8_t *) mma->page_aligned_addr) + (offset - page_aligned_offset); return mma; } diff --git a/include/babeltrace/plugin/plugin.h b/include/babeltrace/plugin/plugin.h index 0e0bc8da..64192b3d 100644 --- a/include/babeltrace/plugin/plugin.h +++ b/include/babeltrace/plugin/plugin.h @@ -28,6 +28,7 @@ * SOFTWARE. */ +#include #include #include #include @@ -109,7 +110,7 @@ extern enum bt_plugin_status bt_plugin_get_version(struct bt_plugin *plugin, unsigned int *major, unsigned int *minor, unsigned int *patch, const char **extra); -extern int bt_plugin_get_component_class_count(struct bt_plugin *plugin); +extern int64_t bt_plugin_get_component_class_count(struct bt_plugin *plugin); extern struct bt_component_class *bt_plugin_get_component_class( struct bt_plugin *plugin, size_t index); @@ -120,7 +121,7 @@ struct bt_component_class *bt_plugin_get_component_class_by_name_and_type( enum bt_component_class_type type); extern -int bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set); +int64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set); extern struct bt_plugin *bt_plugin_set_get_plugin(struct bt_plugin_set *plugin_set, diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index 03c0024f..bc9669ce 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -181,7 +181,7 @@ enum bt_value_status { BT_VALUE_STATUS_CANCELLED = -3, /* -22 for compatibility with -EINVAL */ - /// Invalid arguments. + /// Invalid argument. BT_VALUE_STATUS_INVAL = -22, /// General error. @@ -843,7 +843,7 @@ extern struct bt_value *bt_value_array_create(void); @sa bt_value_array_is_empty(): Checks whether or not a given array value object is empty. */ -extern int bt_value_array_size(const struct bt_value *array_obj); +extern int64_t bt_value_array_size(const struct bt_value *array_obj); /** @brief Checks whether or not the array value object \p array_obj @@ -879,7 +879,7 @@ extern bool bt_value_array_is_empty(const struct bt_value *array_obj); @postrefcountsame{array_obj} */ extern struct bt_value *bt_value_array_get(const struct bt_value *array_obj, - size_t index); + uint64_t index); /** @brief Appends the value object \p element_obj to the array value @@ -1076,7 +1076,7 @@ extern enum bt_value_status bt_value_array_append_empty_map( @postrefcountsame{array_obj} */ extern enum bt_value_status bt_value_array_set(struct bt_value *array_obj, - size_t index, struct bt_value *element_obj); + uint64_t index, struct bt_value *element_obj); /** @} */ @@ -1111,7 +1111,7 @@ extern struct bt_value *bt_value_map_create(void); @sa bt_value_map_is_empty(): Checks whether or not a given map value object is empty. */ -extern int bt_value_map_size(const struct bt_value *map_obj); +extern int64_t bt_value_map_size(const struct bt_value *map_obj); /** @brief Checks whether or not the map value object \p map_obj is empty. diff --git a/lib/ctf-ir/attributes.c b/lib/ctf-ir/attributes.c index c6e8a232..0ea3cfd7 100644 --- a/lib/ctf-ir/attributes.c +++ b/lib/ctf-ir/attributes.c @@ -58,7 +58,7 @@ void bt_ctf_attributes_destroy(struct bt_value *attr_obj) } BT_HIDDEN -int bt_ctf_attributes_get_count(struct bt_value *attr_obj) +int64_t bt_ctf_attributes_get_count(struct bt_value *attr_obj) { return bt_value_array_size(attr_obj); } diff --git a/lib/ctf-ir/event-class.c b/lib/ctf-ir/event-class.c index 0cef1935..c50e39bf 100644 --- a/lib/ctf-ir/event-class.c +++ b/lib/ctf-ir/event-class.c @@ -262,10 +262,10 @@ end: return ret; } -int bt_ctf_event_class_get_attribute_count( +int64_t bt_ctf_event_class_get_attribute_count( struct bt_ctf_event_class *event_class) { - int ret = 0; + int64_t ret = 0; if (!event_class) { ret = -1; @@ -400,10 +400,10 @@ end: return ret; } -int bt_ctf_event_class_get_field_count( +int64_t bt_ctf_event_class_get_field_count( struct bt_ctf_event_class *event_class) { - int ret; + int64_t ret; if (!event_class) { ret = -1; @@ -577,8 +577,8 @@ BT_HIDDEN int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, struct metadata_context *context) { - int i; - int count; + int64_t i; + int64_t count; int ret = 0; struct bt_value *attr_value = NULL; diff --git a/lib/ctf-ir/field-path.c b/lib/ctf-ir/field-path.c index 6c0b248a..a3d42352 100644 --- a/lib/ctf-ir/field-path.c +++ b/lib/ctf-ir/field-path.c @@ -29,6 +29,7 @@ #include #include #include +#include #include static @@ -111,10 +112,10 @@ end: return scope; } -int bt_ctf_field_path_get_index_count( +int64_t bt_ctf_field_path_get_index_count( const struct bt_ctf_field_path *field_path) { - int ret = -1; + int64_t ret = -1; if (!field_path) { goto end; diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index b29d9947..442aff0e 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -590,8 +590,8 @@ int bt_ctf_field_type_structure_validate(struct bt_ctf_field_type *type) { int ret = 0; struct bt_ctf_field_type *child_type = NULL; - int field_count = bt_ctf_field_type_structure_get_field_count(type); - int i; + int64_t field_count = bt_ctf_field_type_structure_get_field_count(type); + int64_t i; if (field_count < 0) { ret = -1; @@ -660,13 +660,13 @@ static int bt_ctf_field_type_variant_validate(struct bt_ctf_field_type *type) { int ret = 0; - int field_count; + int64_t field_count; struct bt_ctf_field_type *child_type = NULL; struct bt_ctf_field_type_variant *variant = container_of(type, struct bt_ctf_field_type_variant, parent); - int i; - int tag_mappings_count; + int64_t i; + int64_t tag_mappings_count; if (variant->tag_name->len == 0 || !variant->tag) { ret = -1; @@ -1421,10 +1421,10 @@ end: return ret; } -int bt_ctf_field_type_enumeration_get_mapping_count( +int64_t bt_ctf_field_type_enumeration_get_mapping_count( struct bt_ctf_field_type *type) { - int ret = 0; + int64_t ret = 0; struct bt_ctf_field_type_enumeration *enumeration; if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_ENUM)) { @@ -1434,7 +1434,7 @@ int bt_ctf_field_type_enumeration_get_mapping_count( enumeration = container_of(type, struct bt_ctf_field_type_enumeration, parent); - ret = (int) enumeration->entries->len; + ret = (int64_t) enumeration->entries->len; end: return ret; } @@ -1597,10 +1597,10 @@ end: return ret; } -int bt_ctf_field_type_structure_get_field_count( +int64_t bt_ctf_field_type_structure_get_field_count( struct bt_ctf_field_type *type) { - int ret = 0; + int64_t ret = 0; struct bt_ctf_field_type_structure *structure; if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_STRUCT)) { @@ -1610,7 +1610,7 @@ int bt_ctf_field_type_structure_get_field_count( structure = container_of(type, struct bt_ctf_field_type_structure, parent); - ret = (int) structure->fields->len; + ret = (int64_t) structure->fields->len; end: return ret; } @@ -1891,9 +1891,9 @@ end: return field_type; } -int bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *type) +int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *type) { - int ret = 0; + int64_t ret = 0; struct bt_ctf_field_type_variant *variant; if (!type || (type->id != BT_CTF_FIELD_TYPE_ID_VARIANT)) { @@ -1903,7 +1903,7 @@ int 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 = (int) variant->fields->len; + ret = (int64_t) variant->fields->len; end: return ret; @@ -2211,7 +2211,7 @@ int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type) } case BT_CTF_FIELD_TYPE_ID_STRUCT: { - int i, element_count; + int64_t i, element_count; element_count = bt_ctf_field_type_structure_get_field_count( type); @@ -4088,9 +4088,9 @@ end: } BT_HIDDEN -int bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *field_type) +int64_t bt_ctf_field_type_get_field_count(struct bt_ctf_field_type *field_type) { - int field_count = -1; + int64_t field_count = -1; enum bt_ctf_field_type_id type_id = bt_ctf_field_type_get_type_id(field_type); switch (type_id) { diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index 0463a119..1cab9590 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -45,6 +45,7 @@ #include #include #include +#include static void bt_ctf_stream_class_destroy(struct bt_object *obj); @@ -488,10 +489,10 @@ end: return ret; } -int bt_ctf_stream_class_get_event_class_count( +int64_t bt_ctf_stream_class_get_event_class_count( struct bt_ctf_stream_class *stream_class) { - int ret; + int64_t ret; if (!stream_class) { ret = -1; @@ -694,7 +695,7 @@ void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class) } static -int get_event_class_count(void *element) +int64_t get_event_class_count(void *element) { return bt_ctf_stream_class_get_event_class_count( (struct bt_ctf_stream_class *) element); diff --git a/lib/ctf-ir/trace.c b/lib/ctf-ir/trace.c index 067e7db9..49c8308a 100644 --- a/lib/ctf-ir/trace.c +++ b/lib/ctf-ir/trace.c @@ -45,6 +45,7 @@ #include #include #include +#include #define DEFAULT_IDENTIFIER_SIZE 128 #define DEFAULT_METADATA_STRING_SIZE 4096 @@ -322,9 +323,9 @@ end: return ret; } -int bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace *trace) +int64_t bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace *trace) { - int ret = 0; + int64_t ret = 0; if (!trace) { ret = -1; @@ -411,9 +412,9 @@ end: return ret; } -int bt_ctf_trace_get_clock_class_count(struct bt_ctf_trace *trace) +int64_t bt_ctf_trace_get_clock_class_count(struct bt_ctf_trace *trace) { - int ret = -1; + int64_t ret = -1; if (!trace) { goto end; @@ -442,7 +443,8 @@ end: int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, struct bt_ctf_stream_class *stream_class) { - int ret, i; + int ret; + int64_t i; int64_t stream_id; struct bt_ctf_validation_output trace_sc_validation_output = { 0 }; struct bt_ctf_validation_output *ec_validation_outputs = NULL; @@ -455,7 +457,7 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, struct bt_ctf_field_type *packet_context_type = NULL; struct bt_ctf_field_type *event_header_type = NULL; struct bt_ctf_field_type *stream_event_ctx_type = NULL; - int event_class_count; + int64_t event_class_count; struct bt_ctf_trace *current_parent_trace = NULL; if (!trace || !stream_class || trace->is_static) { @@ -716,9 +718,9 @@ end: return ret; } -int bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace) +int64_t bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace) { - int ret; + int64_t ret; if (!trace) { ret = -1; @@ -746,9 +748,9 @@ end: return stream; } -int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace) +int64_t bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace) { - int ret; + int64_t ret; if (!trace) { ret = -1; @@ -910,8 +912,8 @@ static void append_env_metadata(struct bt_ctf_trace *trace, struct metadata_context *context) { - int i; - int env_size; + int64_t i; + int64_t env_size; env_size = bt_ctf_attributes_get_count(trace->environment); @@ -1108,7 +1110,7 @@ end: } static -int get_stream_class_count(void *element) +int64_t get_stream_class_count(void *element) { return bt_ctf_trace_get_stream_class_count( (struct bt_ctf_trace *) element); diff --git a/lib/graph/clock-class-priority-map.c b/lib/graph/clock-class-priority-map.c index 7e6543b4..98e72522 100644 --- a/lib/graph/clock-class-priority-map.c +++ b/lib/graph/clock-class-priority-map.c @@ -82,16 +82,16 @@ end: return cc_prio_map; } -int bt_clock_class_priority_map_get_clock_class_count( +int64_t bt_clock_class_priority_map_get_clock_class_count( struct bt_clock_class_priority_map *cc_prio_map) { - int ret = -1; + int64_t ret = -1; if (!cc_prio_map) { goto end; } - ret = (int) cc_prio_map->entries->len; + ret = (int64_t) cc_prio_map->entries->len; end: return ret; diff --git a/lib/graph/component.c b/lib/graph/component.c index 8837c0d1..e3464f45 100644 --- a/lib/graph/component.c +++ b/lib/graph/component.c @@ -188,14 +188,14 @@ end: } BT_HIDDEN -uint64_t bt_component_get_input_port_count(struct bt_component *comp) +int64_t bt_component_get_input_port_count(struct bt_component *comp) { assert(comp); return comp->input_ports->len; } BT_HIDDEN -uint64_t bt_component_get_output_port_count(struct bt_component *comp) +int64_t bt_component_get_output_port_count(struct bt_component *comp) { assert(comp); return comp->output_ports->len; diff --git a/lib/graph/filter.c b/lib/graph/filter.c index 5931b3b3..f7d29618 100644 --- a/lib/graph/filter.c +++ b/lib/graph/filter.c @@ -80,20 +80,20 @@ end: return ret; } -enum bt_component_status bt_component_filter_get_input_port_count( +int64_t bt_component_filter_get_input_port_count( struct bt_component *component, uint64_t *count) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + int64_t ret; - if (!component || !count || + if (!component || component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - status = BT_COMPONENT_STATUS_INVALID; + ret = -1; goto end; } - *count = bt_component_get_input_port_count(component); + ret = bt_component_get_input_port_count(component); end: - return status; + return ret; } struct bt_port *bt_component_filter_get_input_port( @@ -133,20 +133,20 @@ struct bt_port *bt_component_filter_get_default_input_port( DEFAULT_INPUT_PORT_NAME); } -enum bt_component_status bt_component_filter_get_output_port_count( +int64_t bt_component_filter_get_output_port_count( struct bt_component *component, uint64_t *count) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + int64_t ret; if (!component || !count || component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - status = BT_COMPONENT_STATUS_INVALID; + ret = -1; goto end; } - *count = bt_component_get_output_port_count(component); + ret = bt_component_get_output_port_count(component); end: - return status; + return ret; } struct bt_port *bt_component_filter_get_output_port( diff --git a/lib/graph/graph.c b/lib/graph/graph.c index e397d354..5a7e9e0b 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -287,35 +287,39 @@ error: static enum bt_component_status get_component_port_counts( - struct bt_component *component, uint64_t *input_count, - uint64_t *output_count) + struct bt_component *component, int64_t *input_count, + int64_t *output_count) { enum bt_component_status ret; switch (bt_component_get_class_type(component)) { case BT_COMPONENT_CLASS_TYPE_SOURCE: - ret = bt_component_source_get_output_port_count(component, - output_count); - if (ret != BT_COMPONENT_STATUS_OK) { + *output_count = + bt_component_source_get_output_port_count(component); + if (*output_count < 0) { + ret = BT_COMPONENT_STATUS_ERROR; goto end; } break; case BT_COMPONENT_CLASS_TYPE_FILTER: - ret = bt_component_filter_get_output_port_count(component, - output_count); - if (ret != BT_COMPONENT_STATUS_OK) { + *output_count = + bt_component_filter_get_output_port_count(component); + if (*output_count < 0) { + ret = BT_COMPONENT_STATUS_ERROR; goto end; } - ret = bt_component_filter_get_input_port_count(component, - input_count); - if (ret != BT_COMPONENT_STATUS_OK) { + *input_count = + bt_component_filter_get_input_port_count(component); + if (*input_count < 0) { + ret = BT_COMPONENT_STATUS_ERROR; goto end; } break; case BT_COMPONENT_CLASS_TYPE_SINK: - ret = bt_component_sink_get_input_port_count(component, - input_count); - if (ret != BT_COMPONENT_STATUS_OK) { + *input_count = + bt_component_sink_get_input_port_count(component); + if (*input_count < 0) { + ret = BT_COMPONENT_STATUS_ERROR; goto end; } break; @@ -332,10 +336,10 @@ enum bt_graph_status bt_graph_add_component_as_sibling(struct bt_graph *graph, struct bt_component *origin, struct bt_component *new_component) { - uint64_t origin_input_port_count = 0; - uint64_t origin_output_port_count = 0; - uint64_t new_input_port_count = 0; - uint64_t new_output_port_count = 0; + int64_t origin_input_port_count = 0; + int64_t origin_output_port_count = 0; + int64_t new_input_port_count = 0; + int64_t new_output_port_count = 0; enum bt_graph_status status = BT_GRAPH_STATUS_OK; struct bt_graph *origin_graph = NULL; struct bt_graph *new_graph = NULL; diff --git a/lib/graph/sink.c b/lib/graph/sink.c index 49bd8402..916979ad 100644 --- a/lib/graph/sink.c +++ b/lib/graph/sink.c @@ -100,20 +100,19 @@ end: return ret; } -enum bt_component_status bt_component_sink_get_input_port_count( - struct bt_component *component, uint64_t *count) +int64_t bt_component_sink_get_input_port_count(struct bt_component *component) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + int64_t ret; - if (!component || !count || + if (!component || component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { - status = BT_COMPONENT_STATUS_INVALID; + ret = -1; goto end; } - *count = bt_component_get_input_port_count(component); + ret = bt_component_get_input_port_count(component); end: - return status; + return ret; } struct bt_port *bt_component_sink_get_input_port( diff --git a/lib/graph/source.c b/lib/graph/source.c index 0c4f1817..7ab4eeae 100644 --- a/lib/graph/source.c +++ b/lib/graph/source.c @@ -79,20 +79,20 @@ end: return source ? &source->parent : NULL; } -enum bt_component_status bt_component_source_get_output_port_count( +int64_t bt_component_source_get_output_port_count( struct bt_component *component, uint64_t *count) { - enum bt_component_status status = BT_COMPONENT_STATUS_OK; + int64_t ret; if (!component || !count || component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { - status = BT_COMPONENT_STATUS_INVALID; + ret = -1; goto end; } - *count = bt_component_get_output_port_count(component); + ret = bt_component_get_output_port_count(component); end: - return status; + return ret; } struct bt_port *bt_component_source_get_output_port( diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index 5f251030..a55b9843 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -81,9 +81,9 @@ void fini_python_plugin_provider(void) { #endif extern -int bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set) +int64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set) { - int count = -1; + int64_t count = -1; if (!plugin_set) { goto end; @@ -502,7 +502,7 @@ end: return status; } -int bt_plugin_get_component_class_count(struct bt_plugin *plugin) +int64_t bt_plugin_get_component_class_count(struct bt_plugin *plugin) { return plugin ? plugin->comp_classes->len : -1; } diff --git a/lib/values.c b/lib/values.c index 6d08aaeb..fb62293e 100644 --- a/lib/values.c +++ b/lib/values.c @@ -812,9 +812,9 @@ end: return ret; } -int bt_value_array_size(const struct bt_value *array_obj) +int64_t bt_value_array_size(const struct bt_value *array_obj) { - int ret; + int64_t ret; struct bt_value_array *typed_array_obj = BT_VALUE_TO_ARRAY(array_obj); @@ -823,7 +823,7 @@ int bt_value_array_size(const struct bt_value *array_obj) goto end; } - ret = (int) typed_array_obj->garray->len; + ret = (int64_t) typed_array_obj->garray->len; end: return ret; @@ -981,9 +981,9 @@ end: return ret; } -int bt_value_map_size(const struct bt_value *map_obj) +int64_t bt_value_map_size(const struct bt_value *map_obj) { - int ret; + int64_t ret; struct bt_value_map *typed_map_obj = BT_VALUE_TO_MAP(map_obj); if (!map_obj || !bt_value_is_map(map_obj)) { @@ -991,7 +991,7 @@ int bt_value_map_size(const struct bt_value *map_obj) goto end; } - ret = (int) g_hash_table_size(typed_map_obj->ght); + ret = (int64_t) g_hash_table_size(typed_map_obj->ght); end: return ret; diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index d78884d4..75b19597 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -802,8 +802,8 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, struct muxer_notif_iter *muxer_notif_iter) { struct bt_component *comp; - uint64_t count; - uint64_t i; + int64_t count; + int64_t i; int ret = 0; /* @@ -813,8 +813,8 @@ int muxer_notif_iter_init_newly_connected_ports(struct muxer_comp *muxer_comp, */ comp = bt_component_from_private_component(muxer_comp->priv_comp); assert(comp); - ret = bt_component_filter_get_input_port_count(comp, &count); - if (ret) { + count = bt_component_filter_get_input_port_count(comp); + if (count < 0) { goto end; } diff --git a/tests/plugins/test-utils-muxer.c b/tests/plugins/test-utils-muxer.c index 9c369b39..4b78966d 100644 --- a/tests/plugins/test-utils-muxer.c +++ b/tests/plugins/test-utils-muxer.c @@ -983,10 +983,9 @@ void do_std_test(enum test test, const char *name, struct bt_port *upstream_port; struct bt_port *downstream_port; struct bt_graph *graph; - size_t i; - uint64_t count; + int64_t i; + int64_t count; void *conn; - int ret; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; clear_test_events(); @@ -998,8 +997,8 @@ void do_std_test(enum test test, const char *name, /* Connect source output ports to muxer input ports */ if (with_upstream) { - ret = bt_component_source_get_output_port_count(src_comp, &count); - assert(ret == 0); + count = bt_component_source_get_output_port_count(src_comp); + assert(count >= 0); for (i = 0; i < count; i++) { upstream_port = bt_component_source_get_output_port_at_index( @@ -1344,12 +1343,11 @@ void connect_port_to_first_avail_muxer_port(struct bt_graph *graph, { struct bt_port *avail_muxer_port = NULL; void *conn; - uint64_t i; - uint64_t count; - int ret; + int64_t i; + int64_t count; - ret = bt_component_filter_get_input_port_count(muxer_comp, &count); - assert(ret == 0); + count = bt_component_filter_get_input_port_count(muxer_comp); + assert(count >= 0); for (i = 0; i < count; i++) { struct bt_port *muxer_port = @@ -1402,8 +1400,8 @@ void test_single_end_then_multiple_full(void) struct bt_port *upstream_port; struct bt_port *downstream_port; struct bt_graph *graph; - size_t i; - uint64_t count; + int64_t i; + int64_t count; void *conn; int ret; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; @@ -1482,7 +1480,7 @@ void test_single_end_then_multiple_full(void) assert(ret == 0); /* Connect source output ports to muxer input ports */ - ret = bt_component_source_get_output_port_count(src_comp, &count); + count = bt_component_source_get_output_port_count(src_comp); assert(ret == 0); for (i = 0; i < count; i++) { @@ -1530,8 +1528,8 @@ void test_single_again_end_then_multiple_full(void) struct bt_port *upstream_port; struct bt_port *downstream_port; struct bt_graph *graph; - size_t i; - uint64_t count; + int64_t i; + int64_t count; void *conn; int ret; enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK; @@ -1611,7 +1609,7 @@ void test_single_again_end_then_multiple_full(void) assert(ret == 0); /* Connect source output ports to muxer input ports */ - ret = bt_component_source_get_output_port_count(src_comp, &count); + count = bt_component_source_get_output_port_count(src_comp); assert(ret == 0); for (i = 0; i < count; i++) { -- 2.34.1