From 094ff7c009937bb23c056333baffe734308a6b06 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 13 Apr 2018 02:54:35 -0400 Subject: [PATCH] lib: add "borrow" functions where "get" functions exist The new bt_*_borrow_*() functions return a "borrowed reference" instead of a new reference like the bt_*_get_*() functions return. Use the "borrow" functions as much as possible internally. This can improve performance, especially for objects which are obtained often, and for a short time, in the fast path (fields, events, packets, notifications, some metadata objects), as it avoids one bt_get() and one bt_put() call for each function call. Signed-off-by: Philippe Proulx --- .../babeltrace/ctf-ir/attributes-internal.h | 4 +- include/babeltrace/ctf-ir/clock-value.h | 13 +- .../babeltrace/ctf-ir/event-class-internal.h | 16 +- include/babeltrace/ctf-ir/event-class.h | 36 +++- include/babeltrace/ctf-ir/event-internal.h | 29 +-- include/babeltrace/ctf-ir/event.h | 73 ++++++-- .../babeltrace/ctf-ir/field-types-internal.h | 39 ++-- include/babeltrace/ctf-ir/field-types.h | 166 +++++++++++++++--- include/babeltrace/ctf-ir/fields-internal.h | 72 +++----- include/babeltrace/ctf-ir/fields.h | 111 ++++++++++-- include/babeltrace/ctf-ir/packet-internal.h | 8 - include/babeltrace/ctf-ir/packet.h | 38 +++- .../babeltrace/ctf-ir/stream-class-internal.h | 41 ++--- include/babeltrace/ctf-ir/stream-class.h | 77 ++++++-- include/babeltrace/ctf-ir/stream-internal.h | 14 -- include/babeltrace/ctf-ir/stream.h | 14 +- include/babeltrace/ctf-ir/trace-internal.h | 33 ++-- include/babeltrace/ctf-ir/trace.h | 97 ++++++++-- .../graph/clock-class-priority-map.h | 46 ++++- ...notification-discarded-elements-internal.h | 18 +- .../graph/notification-discarded-events.h | 35 +++- .../graph/notification-discarded-packets.h | 36 +++- .../graph/notification-event-internal.h | 24 --- include/babeltrace/graph/notification-event.h | 26 ++- .../graph/notification-inactivity.h | 26 ++- .../babeltrace/graph/notification-iterator.h | 14 +- .../graph/notification-packet-internal.h | 24 --- .../babeltrace/graph/notification-packet.h | 23 ++- .../graph/notification-stream-internal.h | 24 --- .../babeltrace/graph/notification-stream.h | 21 ++- include/babeltrace/values.h | 25 ++- lib/ctf-ir/attributes.c | 47 ++--- lib/ctf-ir/clock-class.c | 4 +- lib/ctf-ir/event-class.c | 14 +- lib/ctf-ir/event.c | 90 ++++------ lib/ctf-ir/field-types.c | 155 ++++++++-------- lib/ctf-ir/fields.c | 48 ++--- lib/ctf-ir/packet.c | 19 +- lib/ctf-ir/resolve.c | 9 +- lib/ctf-ir/stream-class.c | 54 +++--- lib/ctf-ir/stream.c | 4 +- lib/ctf-ir/trace.c | 133 +++++--------- lib/ctf-ir/validation.c | 4 +- lib/ctf-writer/event-class.c | 9 +- lib/ctf-writer/event.c | 8 +- lib/ctf-writer/field-types.c | 54 +++--- lib/ctf-writer/fields.c | 40 +++-- lib/ctf-writer/stream-class.c | 22 +-- lib/ctf-writer/stream.c | 2 +- lib/ctf-writer/trace.c | 36 ++-- lib/graph/clock-class-priority-map.c | 12 +- lib/graph/iterator.c | 5 +- lib/graph/notification/discarded-elements.c | 12 +- lib/graph/notification/discarded-events.c | 12 +- lib/graph/notification/discarded-packets.c | 12 +- lib/graph/notification/event.c | 8 +- lib/graph/notification/inactivity.c | 10 +- lib/graph/notification/packet.c | 8 +- lib/graph/notification/stream.c | 8 +- lib/values.c | 28 ++- 60 files changed, 1231 insertions(+), 859 deletions(-) diff --git a/include/babeltrace/ctf-ir/attributes-internal.h b/include/babeltrace/ctf-ir/attributes-internal.h index b820a70d..d7dda55e 100644 --- a/include/babeltrace/ctf-ir/attributes-internal.h +++ b/include/babeltrace/ctf-ir/attributes-internal.h @@ -50,7 +50,7 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, uint64_t index); BT_HIDDEN -struct bt_value *bt_attributes_get_field_value(struct bt_value *attr_obj, +struct bt_value *bt_attributes_borrow_field_value(struct bt_value *attr_obj, uint64_t index); BT_HIDDEN @@ -58,7 +58,7 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, const char *name, struct bt_value *value_obj); BT_HIDDEN -struct bt_value *bt_attributes_get_field_value_by_name( +struct bt_value *bt_attributes_borrow_field_value_by_name( struct bt_value *attr_obj, const char *name); BT_HIDDEN diff --git a/include/babeltrace/ctf-ir/clock-value.h b/include/babeltrace/ctf-ir/clock-value.h index c40c8284..706e36df 100644 --- a/include/babeltrace/ctf-ir/clock-value.h +++ b/include/babeltrace/ctf-ir/clock-value.h @@ -31,6 +31,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + #include #ifdef __cplusplus @@ -42,8 +45,16 @@ struct bt_clock_value; extern struct bt_clock_value *bt_clock_value_create( struct bt_clock_class *clock_class, uint64_t value); -extern struct bt_clock_class *bt_clock_value_get_class( +extern struct bt_clock_class *bt_clock_value_borrow_class( struct bt_clock_value *clock_value); + +static inline +struct bt_clock_class *bt_clock_value_get_class( + struct bt_clock_value *clock_value) +{ + return bt_get(bt_clock_value_borrow_class(clock_value)); +} + extern int bt_clock_value_get_value( struct bt_clock_value *clock_value, uint64_t *raw_value); extern int bt_clock_value_get_value_ns_from_epoch( diff --git a/include/babeltrace/ctf-ir/event-class-internal.h b/include/babeltrace/ctf-ir/event-class-internal.h index 4836ec36..a89e82dd 100644 --- a/include/babeltrace/ctf-ir/event-class-internal.h +++ b/include/babeltrace/ctf-ir/event-class-internal.h @@ -83,14 +83,6 @@ struct bt_stream_class_common *bt_event_class_common_borrow_stream_class( return (void *) bt_object_borrow_parent(event_class); } -static inline -struct bt_stream_class *bt_event_class_borrow_stream_class( - struct bt_event_class *event_class) -{ - return BT_FROM_COMMON(bt_event_class_common_borrow_stream_class( - BT_TO_COMMON(event_class))); -} - typedef struct bt_field_type_common *(*bt_field_type_structure_create_func)(); BT_HIDDEN @@ -295,7 +287,7 @@ end: } static inline -struct bt_field_type_common *bt_event_class_common_get_context_field_type( +struct bt_field_type_common *bt_event_class_common_borrow_context_field_type( struct bt_event_class_common *event_class) { struct bt_field_type_common *context_ft = NULL; @@ -310,7 +302,7 @@ struct bt_field_type_common *bt_event_class_common_get_context_field_type( goto end; } - context_ft = bt_get(event_class->context_field_type); + context_ft = event_class->context_field_type; end: return context_ft; @@ -364,11 +356,11 @@ end: } static inline -struct bt_field_type_common *bt_event_class_common_get_payload_field_type( +struct bt_field_type_common *bt_event_class_common_borrow_payload_field_type( struct bt_event_class_common *event_class) { BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); - return bt_get(event_class->payload_field_type); + return event_class->payload_field_type; } static inline diff --git a/include/babeltrace/ctf-ir/event-class.h b/include/babeltrace/ctf-ir/event-class.h index a8a3a673..12d78015 100644 --- a/include/babeltrace/ctf-ir/event-class.h +++ b/include/babeltrace/ctf-ir/event-class.h @@ -30,6 +30,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + #include #include @@ -204,6 +207,9 @@ Framework URI. */ extern struct bt_event_class *bt_event_class_create(const char *name); +extern struct bt_stream_class *bt_event_class_borrow_stream_class( + struct bt_event_class *event_class); + /** @brief Returns the parent CTF IR stream class of the CTF IR event class \p event_class. @@ -226,8 +232,12 @@ bt_stream_class_add_event_class(). @sa bt_stream_class_add_event_class(): Add an event class to a stream class. */ -extern struct bt_stream_class *bt_event_class_get_stream_class( - struct bt_event_class *event_class); +static inline +struct bt_stream_class *bt_event_class_get_stream_class( + struct bt_event_class *event_class) +{ + return bt_get(bt_event_class_borrow_stream_class(event_class)); +} /** @} */ @@ -392,6 +402,9 @@ extern int bt_event_class_set_emf_uri( @{ */ +extern struct bt_field_type *bt_event_class_borrow_context_field_type( + struct bt_event_class *event_class); + /** @brief Returns the context field type of the CTF IR event class \p event_class. @@ -408,8 +421,12 @@ extern int bt_event_class_set_emf_uri( @sa bt_event_class_set_context_field_type(): Sets the context field type of a given event class. */ -extern struct bt_field_type *bt_event_class_get_context_field_type( - struct bt_event_class *event_class); +static inline +struct bt_field_type *bt_event_class_get_context_field_type( + struct bt_event_class *event_class) +{ + return bt_get(bt_event_class_borrow_context_field_type(event_class)); +} /** @brief Sets the context field type of the CTF IR event class \p event_class to @@ -444,6 +461,9 @@ extern int bt_event_class_set_context_field_type( struct bt_event_class *event_class, struct bt_field_type *context_type); +extern struct bt_field_type *bt_event_class_borrow_payload_field_type( + struct bt_event_class *event_class); + /** @brief Returns the payload field type of the CTF IR event class \p event_class. @@ -460,8 +480,12 @@ extern int bt_event_class_set_context_field_type( @sa bt_event_class_set_payload_field_type(): Sets the payload field type of a given event class. */ -extern struct bt_field_type *bt_event_class_get_payload_field_type( - struct bt_event_class *event_class); +static inline +struct bt_field_type *bt_event_class_get_payload_field_type( + struct bt_event_class *event_class) +{ + return bt_get(bt_event_class_borrow_payload_field_type(event_class)); +} /** @brief Sets the payload field type of the CTF IR event class \p event_class to diff --git a/include/babeltrace/ctf-ir/event-internal.h b/include/babeltrace/ctf-ir/event-internal.h index d9d0fe3e..7f37f14f 100644 --- a/include/babeltrace/ctf-ir/event-internal.h +++ b/include/babeltrace/ctf-ir/event-internal.h @@ -83,15 +83,6 @@ void _bt_event_freeze(struct bt_event *event); #define BT_ASSERT_PRE_EVENT_COMMON_HOT(_event, _name) \ BT_ASSERT_PRE_HOT((_event), (_name), ": +%!+_e", (_event)) -static inline struct bt_packet *bt_event_borrow_packet(struct bt_event *event) -{ - BT_ASSERT(event); - return event->packet; -} - -BT_HIDDEN -struct bt_stream *bt_event_borrow_stream(struct bt_event *event); - static inline struct bt_event_class_common *bt_event_common_borrow_class( struct bt_event_common *event) @@ -100,13 +91,6 @@ struct bt_event_class_common *bt_event_common_borrow_class( return event->class; } -static inline -struct bt_event_class *bt_event_borrow_class(struct bt_event *event) -{ - return BT_FROM_COMMON(bt_event_common_borrow_class( - BT_TO_COMMON(event))); -} - BT_HIDDEN int bt_event_common_initialize(struct bt_event_common *event, struct bt_event_class_common *event_class, @@ -120,7 +104,7 @@ int bt_event_common_initialize(struct bt_event_common *event, void *(*create_field_func)(void *)); static inline -struct bt_field_common *bt_event_common_get_payload( +struct bt_field_common *bt_event_common_borrow_payload( struct bt_event_common *event) { struct bt_field_common *payload = NULL; @@ -136,7 +120,6 @@ struct bt_field_common *bt_event_common_get_payload( } payload = event->payload_field; - bt_get(payload); end: return payload; @@ -176,7 +159,7 @@ int bt_event_common_set_payload(struct bt_event_common *event, } static inline -struct bt_field_common *bt_event_common_get_header( +struct bt_field_common *bt_event_common_borrow_header( struct bt_event_common *event) { struct bt_field_common *header = NULL; @@ -192,7 +175,6 @@ struct bt_field_common *bt_event_common_get_header( } header = event->header_field; - bt_get(header); end: return header; @@ -237,7 +219,7 @@ int bt_event_common_set_header(struct bt_event_common *event, } static inline -struct bt_field_common *bt_event_common_get_context( +struct bt_field_common *bt_event_common_borrow_context( struct bt_event_common *event) { struct bt_field_common *context = NULL; @@ -253,7 +235,6 @@ struct bt_field_common *bt_event_common_get_context( } context = event->context_field; - bt_get(context); end: return context; @@ -292,7 +273,7 @@ int bt_event_common_set_context(struct bt_event_common *event, } static inline -struct bt_field_common *bt_event_common_get_stream_event_context( +struct bt_field_common *bt_event_common_borrow_stream_event_context( struct bt_event_common *event) { struct bt_field_common *stream_event_context = NULL; @@ -310,7 +291,7 @@ struct bt_field_common *bt_event_common_get_stream_event_context( stream_event_context = event->stream_event_context_field; end: - return bt_get(stream_event_context); + return stream_event_context; } static inline diff --git a/include/babeltrace/ctf-ir/event.h b/include/babeltrace/ctf-ir/event.h index 3bdee29b..46211aae 100644 --- a/include/babeltrace/ctf-ir/event.h +++ b/include/babeltrace/ctf-ir/event.h @@ -30,6 +30,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + #include #include @@ -164,6 +167,8 @@ with bt_trace_add_stream_class(), then this function fails. */ extern struct bt_event *bt_event_create(struct bt_event_class *event_class); +extern struct bt_event_class *bt_event_borrow_class(struct bt_event *event); + /** @brief Returns the parent CTF IR event class of the CTF IR event \p event. @@ -179,7 +184,13 @@ create the event object in the first place with bt_event_create(). @postrefcountsame{event} @postsuccessrefcountretinc */ -extern struct bt_event_class *bt_event_get_class(struct bt_event *event); +static inline +struct bt_event_class *bt_event_get_class(struct bt_event *event) +{ + return bt_get(bt_event_borrow_class(event)); +} + +extern struct bt_packet *bt_event_borrow_packet(struct bt_event *event); /** @brief Returns the CTF IR packet associated to the CTF IR event @@ -200,7 +211,11 @@ This function returns a reference to the event class which was set to @sa bt_event_set_packet(): Associates a given event to a given packet. */ -extern struct bt_packet *bt_event_get_packet(struct bt_event *event); +static inline +struct bt_packet *bt_event_get_packet(struct bt_event *event) +{ + return bt_get(bt_event_borrow_packet(event)); +} /** @brief Associates the CTF IR event \p event to the CTF IR packet @@ -235,6 +250,8 @@ On success, this function also sets the parent stream object of extern int bt_event_set_packet(struct bt_event *event, struct bt_packet *packet); +extern struct bt_stream *bt_event_borrow_stream(struct bt_event *event); + /** @brief Returns the parent CTF IR stream associated to the CTF IR event \p event. @@ -246,7 +263,11 @@ extern int bt_event_set_packet(struct bt_event *event, @postrefcountsame{event} @postsuccessrefcountretinc */ -extern struct bt_stream *bt_event_get_stream(struct bt_event *event); +static inline +struct bt_stream *bt_event_get_stream(struct bt_event *event) +{ + return bt_get(bt_event_borrow_stream(event)); +} /** @} */ @@ -255,6 +276,8 @@ extern struct bt_stream *bt_event_get_stream(struct bt_event *event); @{ */ +extern struct bt_field *bt_event_borrow_header(struct bt_event *event); + /** @brief Returns the stream event header field of the CTF IR event \p event. @@ -272,7 +295,11 @@ extern struct bt_stream *bt_event_get_stream(struct bt_event *event); @sa bt_event_get_header(): Sets the stream event header field of a given event. */ -extern struct bt_field *bt_event_get_header(struct bt_event *event); +static inline +struct bt_field *bt_event_get_header(struct bt_event *event) +{ + return bt_get(bt_event_borrow_header(event)); +} /** @brief Sets the stream event header field of the CTF IR event @@ -304,6 +331,9 @@ of \p event. extern int bt_event_set_header(struct bt_event *event, struct bt_field *header); +extern struct bt_field *bt_event_borrow_stream_event_context( + struct bt_event *event); + /** @brief Returns the stream event context field of the CTF IR event \p event. @@ -321,8 +351,11 @@ extern int bt_event_set_header(struct bt_event *event, @sa bt_event_set_stream_event_context(): Sets the stream event context field of a given event. */ -extern struct bt_field *bt_event_get_stream_event_context( - struct bt_event *event); +static inline +struct bt_field *bt_event_get_stream_event_context(struct bt_event *event) +{ + return bt_get(bt_event_borrow_stream_event_context(event)); +} /** @brief Sets the stream event context field of the CTF IR event @@ -353,6 +386,8 @@ of \p event. extern int bt_event_set_stream_event_context(struct bt_event *event, struct bt_field *context); +extern struct bt_field *bt_event_borrow_context(struct bt_event *event); + /** @brief Returns the event context field of the CTF IR event \p event. @@ -367,7 +402,11 @@ extern int bt_event_set_stream_event_context(struct bt_event *event, @sa bt_event_set_context(): Sets the event context field of a given event. */ -extern struct bt_field *bt_event_get_context(struct bt_event *event); +static inline +struct bt_field *bt_event_get_context(struct bt_event *event) +{ + return bt_get(bt_event_borrow_context(event)); +} /** @brief Sets the event context field of the CTF IR event \p event to \p context, @@ -395,6 +434,8 @@ bt_event_class_get_context_type() for the parent class of \p event. extern int bt_event_set_context(struct bt_event *event, struct bt_field *context); +extern struct bt_field *bt_event_borrow_payload(struct bt_event *event); + /** @brief Returns the payload field of the CTF IR event \p event. @@ -409,7 +450,11 @@ extern int bt_event_set_context(struct bt_event *event, @sa bt_event_set_payload(): Sets the payload field of a given event. */ -extern struct bt_field *bt_event_get_payload(struct bt_event *event); +static inline +struct bt_field *bt_event_get_payload(struct bt_event *event) +{ + return bt_get(bt_event_borrow_payload(event)); +} /** @brief Sets the payload field of the CTF IR event \p event to \p payload, @@ -444,6 +489,10 @@ extern int bt_event_set_payload(struct bt_event *event, @{ */ +extern struct bt_clock_value *bt_event_borrow_clock_value( + struct bt_event *event, + struct bt_clock_class *clock_class); + /** @brief Returns the value, as of the CTF IR event \p event, of the clock described by the @@ -463,9 +512,13 @@ extern int bt_event_set_payload(struct bt_event *event, @sa bt_event_set_clock_value(): Sets the clock value of a given event. */ -extern struct bt_clock_value *bt_event_get_clock_value( +static inline +struct bt_clock_value *bt_event_get_clock_value( struct bt_event *event, - struct bt_clock_class *clock_class); + struct bt_clock_class *clock_class) +{ + return bt_get(bt_event_borrow_clock_value(event, clock_class)); +} /** @brief Sets the value, as of the CTF IR event \p event, of the diff --git a/include/babeltrace/ctf-ir/field-types-internal.h b/include/babeltrace/ctf-ir/field-types-internal.h index 70a15b0c..8d013b18 100644 --- a/include/babeltrace/ctf-ir/field-types-internal.h +++ b/include/babeltrace/ctf-ir/field-types-internal.h @@ -362,7 +362,7 @@ int bt_field_type_common_integer_set_encoding(struct bt_field_type_common *ft, enum bt_string_encoding encoding); BT_HIDDEN -struct bt_clock_class *bt_field_type_common_integer_get_mapped_clock_class( +struct bt_clock_class *bt_field_type_common_integer_borrow_mapped_clock_class( struct bt_field_type_common *ft); BT_HIDDEN @@ -403,7 +403,8 @@ int bt_field_type_common_enumeration_unsigned_get_mapping_by_index( uint64_t *range_end); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_enumeration_get_container_field_type( +struct bt_field_type_common * +bt_field_type_common_enumeration_borrow_container_field_type( struct bt_field_type_common *ft); BT_HIDDEN @@ -453,17 +454,19 @@ int64_t bt_field_type_common_structure_get_field_count( struct bt_field_type_common *ft); BT_HIDDEN -int bt_field_type_common_structure_get_field_by_index( +int bt_field_type_common_structure_borrow_field_by_index( struct bt_field_type_common *ft, const char **field_name, struct bt_field_type_common **field_type, uint64_t index); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_structure_get_field_type_by_name( +struct bt_field_type_common * +bt_field_type_common_structure_borrow_field_type_by_name( struct bt_field_type_common *ft, const char *name); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_tag_field_type( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_tag_field_type( struct bt_field_type_common *ft); BT_HIDDEN @@ -480,12 +483,14 @@ int bt_field_type_common_variant_add_field(struct bt_field_type_common *ft, const char *field_name); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_by_name( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_by_name( struct bt_field_type_common *ft, const char *field_name); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_from_tag( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_from_tag( struct bt_field_type_common *ft, struct bt_field_common *tag_field, bt_field_common_create_func field_create_func); @@ -495,13 +500,14 @@ int64_t bt_field_type_common_variant_get_field_count( struct bt_field_type_common *ft); BT_HIDDEN -int bt_field_type_common_variant_get_field_by_index( +int bt_field_type_common_variant_borrow_field_by_index( struct bt_field_type_common *ft, const char **field_name, struct bt_field_type_common **field_type, uint64_t index); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_array_get_element_field_type( +struct bt_field_type_common * +bt_field_type_common_array_borrow_element_field_type( struct bt_field_type_common *ft); BT_HIDDEN @@ -513,7 +519,8 @@ BT_HIDDEN int64_t bt_field_type_common_array_get_length(struct bt_field_type_common *ft); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_sequence_get_element_field_type( +struct bt_field_type_common * +bt_field_type_common_sequence_borrow_element_field_type( struct bt_field_type_common *ft); BT_HIDDEN @@ -559,12 +566,14 @@ BT_HIDDEN void _bt_field_type_freeze(struct bt_field_type *ft); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_signed( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_signed( struct bt_field_type_common_variant *var_ft, int64_t tag_value); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_unsigned( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_unsigned( struct bt_field_type_common_variant *var_ft, uint64_t tag_value); @@ -695,7 +704,7 @@ BT_HIDDEN int64_t bt_field_type_common_get_field_count(struct bt_field_type_common *ft); BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_get_field_at_index( +struct bt_field_type_common *bt_field_type_common_borrow_field_at_index( struct bt_field_type_common *ft, int index); BT_HIDDEN @@ -703,11 +712,11 @@ int bt_field_type_common_get_field_index(struct bt_field_type_common *ft, const char *name); BT_HIDDEN -struct bt_field_path *bt_field_type_common_variant_get_tag_field_path( +struct bt_field_path *bt_field_type_common_variant_borrow_tag_field_path( struct bt_field_type_common *ft); BT_HIDDEN -struct bt_field_path *bt_field_type_common_sequence_get_length_field_path( +struct bt_field_path *bt_field_type_common_sequence_borrow_length_field_path( struct bt_field_type_common *ft); BT_HIDDEN diff --git a/include/babeltrace/ctf-ir/field-types.h b/include/babeltrace/ctf-ir/field-types.h index f1f6ef7a..13d9b6b4 100644 --- a/include/babeltrace/ctf-ir/field-types.h +++ b/include/babeltrace/ctf-ir/field-types.h @@ -30,6 +30,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + /* For bt_bool */ #include @@ -950,6 +953,9 @@ extern int bt_field_type_integer_set_encoding( struct bt_field_type *int_field_type, enum bt_string_encoding encoding); +extern struct bt_clock_class *bt_field_type_integer_borrow_mapped_clock_class( + struct bt_field_type *int_field_type); + /** @brief Returns the \link ctfirclockclass CTF IR clock class\endlink mapped to the @intft \p int_field_type. @@ -972,8 +978,13 @@ This mapped clock class is only indicative. @sa bt_field_type_integer_set_mapped_clock_class(): Sets the mapped clock class of a given integer field type. */ -extern struct bt_clock_class *bt_field_type_integer_get_mapped_clock_class( - struct bt_field_type *int_field_type); +static inline +struct bt_clock_class *bt_field_type_integer_get_mapped_clock_class( + struct bt_field_type *int_field_type) +{ + return bt_get(bt_field_type_integer_borrow_mapped_clock_class( + int_field_type)); +} /** @brief Sets the \link ctfirclockclass CTF IR clock class\endlink mapped @@ -1278,6 +1289,10 @@ the \c CHERRY mapping. extern struct bt_field_type *bt_field_type_enumeration_create( struct bt_field_type *int_field_type); +extern +struct bt_field_type *bt_field_type_enumeration_borrow_container_field_type( + struct bt_field_type *enum_field_type); + /** @brief Returns the @intft wrapped by the @enumft \p enum_field_type. @@ -1292,9 +1307,13 @@ extern struct bt_field_type *bt_field_type_enumeration_create( @postrefcountsame{enum_field_type} @postsuccessrefcountretinc */ -extern +static inline struct bt_field_type *bt_field_type_enumeration_get_container_field_type( - struct bt_field_type *enum_field_type); + struct bt_field_type *enum_field_type) +{ + return bt_get(bt_field_type_enumeration_borrow_container_field_type( + enum_field_type)); +} /** @brief Returns the number of mappings contained in the @@ -1898,6 +1917,11 @@ extern struct bt_field_type *bt_field_type_structure_create(void); extern int64_t bt_field_type_structure_get_field_count( struct bt_field_type *struct_field_type); +extern int bt_field_type_structure_borrow_field_by_index( + struct bt_field_type *struct_field_type, + const char **field_name, struct bt_field_type **field_type, + uint64_t index); + /** @brief Returns the field of the @structft \p struct_field_type at index \p index. @@ -1929,10 +1953,26 @@ On success, the field's type is placed in \p *field_type if @sa bt_field_type_structure_get_field_type_by_name(): Finds a structure field type's field by name. */ -extern int bt_field_type_structure_get_field_by_index( +static inline +int bt_field_type_structure_get_field_by_index( struct bt_field_type *struct_field_type, const char **field_name, struct bt_field_type **field_type, - uint64_t index); + uint64_t index) +{ + int ret = bt_field_type_structure_borrow_field_by_index( + struct_field_type, field_name, field_type, index); + + if (ret == 0 && field_type) { + bt_get(*field_type); + } + + return ret; +} + +extern +struct bt_field_type *bt_field_type_structure_borrow_field_type_by_name( + struct bt_field_type *struct_field_type, + const char *field_name); /** @brief Returns the type of the field named \p field_name found in @@ -1954,10 +1994,14 @@ extern int bt_field_type_structure_get_field_by_index( @sa bt_field_type_structure_get_field_by_index(): Finds a structure field type's field by index. */ -extern +static inline struct bt_field_type *bt_field_type_structure_get_field_type_by_name( struct bt_field_type *struct_field_type, - const char *field_name); + const char *field_name) +{ + return bt_get(bt_field_type_structure_borrow_field_type_by_name( + struct_field_type, field_name)); +} /** @brief Adds a field named \p field_name with the @ft @@ -2042,6 +2086,9 @@ extern struct bt_field_type *bt_field_type_array_create( struct bt_field_type *element_field_type, unsigned int length); +extern struct bt_field_type *bt_field_type_array_borrow_element_field_type( + struct bt_field_type *array_field_type); + /** @brief Returns the @ft of the @fields contained in the @arrayfields described by the @arrayft \p array_field_type. @@ -2059,8 +2106,13 @@ extern struct bt_field_type *bt_field_type_array_create( @postrefcountsame{array_field_type} @postsuccessrefcountretinc */ -extern struct bt_field_type *bt_field_type_array_get_element_field_type( - struct bt_field_type *array_field_type); +static inline +struct bt_field_type *bt_field_type_array_get_element_field_type( + struct bt_field_type *array_field_type) +{ + return bt_get(bt_field_type_array_borrow_element_field_type( + array_field_type)); +} /** @brief Returns the number of @fields contained in the @@ -2134,6 +2186,9 @@ extern struct bt_field_type *bt_field_type_sequence_create( struct bt_field_type *element_field_type, const char *length_name); +extern struct bt_field_type *bt_field_type_sequence_borrow_element_field_type( + struct bt_field_type *sequence_field_type); + /** @brief Returns the @ft of the @fields contained in the @seqft described by the @seqft \p sequence_field_type. @@ -2151,8 +2206,13 @@ extern struct bt_field_type *bt_field_type_sequence_create( @postrefcountsame{sequence_field_type} @postsuccessrefcountretinc */ -extern struct bt_field_type *bt_field_type_sequence_get_element_field_type( - struct bt_field_type *sequence_field_type); +static inline +struct bt_field_type *bt_field_type_sequence_get_element_field_type( + struct bt_field_type *sequence_field_type) +{ + return bt_get(bt_field_type_sequence_borrow_element_field_type( + sequence_field_type)); +} /** @brief Returns the length name of the @seqft \p sequence_field_type. @@ -2174,6 +2234,9 @@ the returned string. extern const char *bt_field_type_sequence_get_length_field_name( struct bt_field_type *sequence_field_type); +extern struct bt_field_path *bt_field_type_sequence_borrow_length_field_path( + struct bt_field_type *sequence_field_type); + /** @brief Returns the length's CTF IR field path of the @seqft \p sequence_field_type. @@ -2195,8 +2258,13 @@ resolving is performed (see \ref ctfirfieldtypes). @sa bt_field_type_sequence_get_length_field_name(): Returns the length's name of a given sequence field type. */ -extern struct bt_field_path *bt_field_type_sequence_get_length_field_path( - struct bt_field_type *sequence_field_type); +static inline +struct bt_field_path *bt_field_type_sequence_get_length_field_path( + struct bt_field_type *sequence_field_type) +{ + return bt_get(bt_field_type_sequence_borrow_length_field_path( + sequence_field_type)); +} /** @} */ @@ -2271,6 +2339,9 @@ extern struct bt_field_type *bt_field_type_variant_create( struct bt_field_type *tag_field_type, const char *tag_name); +extern struct bt_field_type *bt_field_type_variant_borrow_tag_field_type( + struct bt_field_type *variant_field_type); + /** @brief Returns the tag's @enumft of the @varft \p variant_field_type. @@ -2286,8 +2357,13 @@ extern struct bt_field_type *bt_field_type_variant_create( @postrefcountsame{variant_field_type} @postsuccessrefcountretinc */ -extern struct bt_field_type *bt_field_type_variant_get_tag_field_type( - struct bt_field_type *variant_field_type); +static inline +struct bt_field_type *bt_field_type_variant_get_tag_field_type( + struct bt_field_type *variant_field_type) +{ + return bt_get(bt_field_type_variant_borrow_tag_field_type( + variant_field_type)); +} /** @brief Returns the tag name of the @varft \p variant_field_type. @@ -2336,6 +2412,9 @@ extern int bt_field_type_variant_set_tag_name( struct bt_field_type *variant_field_type, const char *tag_name); +extern struct bt_field_path *bt_field_type_variant_borrow_tag_field_path( + struct bt_field_type *variant_field_type); + /** @brief Returns the tag's CTF IR field path of the @varft \p variant_field_type. @@ -2357,8 +2436,13 @@ resolving is performed (see \ref ctfirfieldtypes). @sa bt_field_type_variant_get_tag_name(): Returns the tag's name of a given variant field type. */ -extern struct bt_field_path *bt_field_type_variant_get_tag_field_path( - struct bt_field_type *variant_field_type); +static inline +struct bt_field_path *bt_field_type_variant_get_tag_field_path( + struct bt_field_type *variant_field_type) +{ + return bt_get(bt_field_type_variant_borrow_tag_field_path( + variant_field_type)); +} /** @brief Returns the number of fields (choices) contained in the @varft @@ -2377,6 +2461,11 @@ extern struct bt_field_path *bt_field_type_variant_get_tag_field_path( extern int64_t bt_field_type_variant_get_field_count( struct bt_field_type *variant_field_type); +extern int bt_field_type_variant_borrow_field_by_index( + struct bt_field_type *variant_field_type, + const char **field_name, + struct bt_field_type **field_type, uint64_t index); + /** @brief Returns the field (choice) of the @varft \p variant_field_type at index \p index. @@ -2410,10 +2499,26 @@ On success, the field's type is placed in \p *field_type if @sa bt_field_type_variant_get_field_type_from_tag(): Finds a variant field type's field by current tag value. */ -extern int bt_field_type_variant_get_field_by_index( +static inline +int bt_field_type_variant_get_field_by_index( struct bt_field_type *variant_field_type, const char **field_name, - struct bt_field_type **field_type, uint64_t index); + struct bt_field_type **field_type, uint64_t index) +{ + int ret = bt_field_type_variant_borrow_field_by_index( + variant_field_type, field_name, field_type, index); + + if (ret == 0 && field_type) { + bt_get(*field_type); + } + + return ret; +} + +extern +struct bt_field_type *bt_field_type_variant_borrow_field_type_by_name( + struct bt_field_type *variant_field_type, + const char *field_name); /** @brief Returns the type of the field (choice) named \p field_name @@ -2437,10 +2542,19 @@ extern int bt_field_type_variant_get_field_by_index( @sa bt_field_type_variant_get_field_type_from_tag(): Finds a variant field type's field by current tag value. */ -extern +static inline struct bt_field_type *bt_field_type_variant_get_field_type_by_name( struct bt_field_type *variant_field_type, - const char *field_name); + const char *field_name) +{ + return bt_get(bt_field_type_variant_borrow_field_type_by_name( + variant_field_type, field_name)); +} + +extern +struct bt_field_type *bt_field_type_variant_borrow_field_type_from_tag( + struct bt_field_type *variant_field_type, + struct bt_field *tag_field); /** @brief Returns the type of the field (choice) selected by the value of @@ -2473,10 +2587,14 @@ bt_field_type_variant_get_tag_field_type() for \p variant_field_type. @sa bt_field_type_variant_get_field_type_by_name(): Finds a variant field type's field by name. */ -extern +static inline struct bt_field_type *bt_field_type_variant_get_field_type_from_tag( struct bt_field_type *variant_field_type, - struct bt_field *tag_field); + struct bt_field *tag_field) +{ + return bt_get(bt_field_type_variant_borrow_field_type_from_tag( + variant_field_type, tag_field)); +} /** @brief Adds a field (a choice) named \p field_name with the @ft diff --git a/include/babeltrace/ctf-ir/fields-internal.h b/include/babeltrace/ctf-ir/fields-internal.h index 0f6afca6..388b0cb2 100644 --- a/include/babeltrace/ctf-ir/fields-internal.h +++ b/include/babeltrace/ctf-ir/fields-internal.h @@ -135,15 +135,6 @@ struct bt_field_common_string { GString *payload; }; -static inline -struct bt_field_type *bt_field_borrow_type(struct bt_field *field) -{ - struct bt_field_common *field_common = (void *) field; - - BT_ASSERT(field); - return (void *) field_common->type; -} - BT_HIDDEN int64_t bt_field_sequence_get_int_length(struct bt_field *field); @@ -367,13 +358,13 @@ void bt_field_common_initialize(struct bt_field_common *field, } static inline -struct bt_field_type_common *bt_field_common_get_type( +struct bt_field_type_common *bt_field_common_borrow_type( struct bt_field_common *field) { struct bt_field_type_common *ret = NULL; BT_ASSERT_PRE_NON_NULL(field, "Field"); - ret = bt_get(field->type); + ret = field->type; return ret; } @@ -397,7 +388,7 @@ end: } static inline -struct bt_field_common *bt_field_common_sequence_get_length( +struct bt_field_common *bt_field_common_sequence_borrow_length( struct bt_field_common *field) { struct bt_field_common_sequence *sequence = BT_FROM_COMMON(field); @@ -405,7 +396,7 @@ struct bt_field_common *bt_field_common_sequence_get_length( BT_ASSERT_PRE_NON_NULL(field, "Sequence field"); BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_SEQUENCE, "Field"); - return bt_get(sequence->length); + return sequence->length; } static inline @@ -451,7 +442,7 @@ end: } static inline -struct bt_field_common *bt_field_common_structure_get_field_by_name( +struct bt_field_common *bt_field_common_structure_borrow_field_by_name( struct bt_field_common *field, const char *name) { struct bt_field_common *ret = NULL; @@ -477,7 +468,7 @@ struct bt_field_common *bt_field_common_structure_get_field_by_name( goto error; } - ret = bt_get(structure->fields->pdata[index]); + ret = structure->fields->pdata[index]; BT_ASSERT(ret); error: @@ -485,7 +476,7 @@ error: } static inline -struct bt_field_common *bt_field_common_structure_get_field_by_index( +struct bt_field_common *bt_field_common_structure_borrow_field_by_index( struct bt_field_common *field, uint64_t index) { struct bt_field_common_structure *structure = BT_FROM_COMMON(field); @@ -497,7 +488,7 @@ struct bt_field_common *bt_field_common_structure_get_field_by_index( "Index is out of bound: %![struct-field-]+_f, " "index=%" PRIu64 ", count=%u", field, index, structure->fields->len); - return bt_get(structure->fields->pdata[index]); + return structure->fields->pdata[index]; } BT_ASSERT_PRE_FUNC @@ -509,7 +500,7 @@ static inline bool field_to_set_has_expected_type( struct bt_field_type_common *expected_field_type = NULL; expected_field_type = - bt_field_type_common_structure_get_field_type_by_name( + bt_field_type_common_structure_borrow_field_type_by_name( struct_field->type, name); if (bt_field_type_common_compare(expected_field_type, value->type)) { @@ -521,7 +512,6 @@ static inline bool field_to_set_has_expected_type( } end: - bt_put(expected_field_type); return ret; } @@ -564,7 +554,7 @@ end: } static inline -struct bt_field_common *bt_field_common_array_get_field( +struct bt_field_common *bt_field_common_array_borrow_field( struct bt_field_common *field, uint64_t index, bt_field_common_create_func field_create_func) { @@ -579,7 +569,7 @@ struct bt_field_common *bt_field_common_array_get_field( "index=%" PRIu64 ", count=%u", field, index, array->elements->len); - field_type = bt_field_type_common_array_get_element_field_type( + field_type = bt_field_type_common_array_borrow_element_field_type( field->type); if (array->elements->pdata[(size_t) index]) { new_field = array->elements->pdata[(size_t) index]; @@ -592,13 +582,11 @@ struct bt_field_common *bt_field_common_array_get_field( array->elements->pdata[(size_t) index] = new_field; end: - bt_put(field_type); - bt_get(new_field); return new_field; } static inline -struct bt_field_common *bt_field_common_sequence_get_field( +struct bt_field_common *bt_field_common_sequence_borrow_field( struct bt_field_common *field, uint64_t index, bt_field_common_create_func field_create_func) { @@ -614,7 +602,7 @@ struct bt_field_common *bt_field_common_sequence_get_field( "Index is out of bound: %![seq-field-]+_f, " "index=%" PRIu64 ", count=%u", field, index, sequence->elements->len); - field_type = bt_field_type_common_sequence_get_element_field_type( + field_type = bt_field_type_common_sequence_borrow_element_field_type( field->type); if (sequence->elements->pdata[(size_t) index]) { new_field = sequence->elements->pdata[(size_t) index]; @@ -627,13 +615,11 @@ struct bt_field_common *bt_field_common_sequence_get_field( sequence->elements->pdata[(size_t) index] = new_field; end: - bt_put(field_type); - bt_get(new_field); return new_field; } static inline -struct bt_field_common *bt_field_common_enumeration_get_container( +struct bt_field_common *bt_field_common_enumeration_borrow_container( struct bt_field_common *field, bt_field_common_create_func field_create_func) { @@ -655,11 +641,11 @@ struct bt_field_common *bt_field_common_enumeration_get_container( BT_TO_COMMON(enumeration_type->container_ft)); } - return bt_get(enumeration->payload); + return enumeration->payload; } static inline -struct bt_field_common *bt_field_common_variant_get_field( +struct bt_field_common *bt_field_common_variant_borrow_field( struct bt_field_common *field, struct bt_field_common *tag_field, bt_field_common_create_func field_create_func) @@ -680,7 +666,7 @@ struct bt_field_common *bt_field_common_variant_get_field( BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(tag_field, BT_FIELD_TYPE_ID_ENUM, "Tag field"); variant_type = BT_FROM_COMMON(field->type); - tag_enum = bt_field_common_enumeration_get_container(tag_field, + tag_enum = bt_field_common_enumeration_borrow_container(tag_field, field_create_func); BT_ASSERT_PRE_NON_NULL(tag_enum, "Tag field's container"); tag_enum_integer = BT_FROM_COMMON(tag_enum); @@ -699,23 +685,21 @@ struct bt_field_common *bt_field_common_variant_get_field( int64_t cur_tag_value; cur_tag_container = - bt_field_common_enumeration_get_container(variant->tag, - field_create_func); + bt_field_common_enumeration_borrow_container( + variant->tag, field_create_func); BT_ASSERT(cur_tag_container); cur_tag_enum_integer = BT_FROM_COMMON(cur_tag_container); - bt_put(cur_tag_container); cur_tag_value = cur_tag_enum_integer->payload.signd; if (cur_tag_value == tag_enum_value) { new_field = variant->payload; - bt_get(new_field); goto end; } } /* We don't want to modify this field if it's frozen */ BT_ASSERT_PRE_FIELD_COMMON_HOT(field, "Variant field"); - field_type = bt_field_type_common_variant_get_field_type_signed( + field_type = bt_field_type_common_variant_borrow_field_type_signed( variant_type, tag_enum_value); /* It's the caller's job to make sure the tag's value is valid */ @@ -735,18 +719,15 @@ struct bt_field_common *bt_field_common_variant_get_field( bt_put(variant->tag); bt_put(variant->payload); - bt_get(new_field); - bt_get(tag_field); - variant->tag = tag_field; + variant->tag = bt_get(tag_field); variant->payload = new_field; end: - bt_put(tag_enum); return new_field; } static inline -struct bt_field_common *bt_field_common_variant_get_current_field( +struct bt_field_common *bt_field_common_variant_borrow_current_field( struct bt_field_common *variant_field) { struct bt_field_common_variant *variant = BT_FROM_COMMON(variant_field); @@ -754,11 +735,11 @@ struct bt_field_common *bt_field_common_variant_get_current_field( BT_ASSERT_PRE_NON_NULL(variant_field, "Variant field"); BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field, BT_FIELD_TYPE_ID_VARIANT, "Field"); - return bt_get(variant->payload); + return variant->payload; } static inline -struct bt_field_common *bt_field_common_variant_get_tag( +struct bt_field_common *bt_field_common_variant_borrow_tag( struct bt_field_common *variant_field) { struct bt_field_common_variant *variant = BT_FROM_COMMON(variant_field); @@ -766,7 +747,7 @@ struct bt_field_common *bt_field_common_variant_get_tag( BT_ASSERT_PRE_NON_NULL(variant_field, "Variant field"); BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(variant_field, BT_FIELD_TYPE_ID_VARIANT, "Field"); - return bt_get(variant->tag); + return variant->tag; } static inline @@ -896,7 +877,7 @@ bt_field_common_enumeration_get_mappings(struct bt_field_common *field, BT_ASSERT_PRE_NON_NULL(field, "Enumeration field"); BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field, BT_FIELD_TYPE_ID_ENUM, "Field"); - container = bt_field_common_enumeration_get_container(field, + container = bt_field_common_enumeration_borrow_container(field, field_create_func); BT_ASSERT_PRE(container, "Enumeration field has no container field: %!+_f", field); @@ -922,7 +903,6 @@ bt_field_common_enumeration_get_mappings(struct bt_field_common *field, field->type, value); } - bt_put(container); return iter; } diff --git a/include/babeltrace/ctf-ir/fields.h b/include/babeltrace/ctf-ir/fields.h index 896cd4e4..ab0ba546 100644 --- a/include/babeltrace/ctf-ir/fields.h +++ b/include/babeltrace/ctf-ir/fields.h @@ -33,6 +33,9 @@ #include #include +/* For bt_get() */ +#include + /* For bt_bool */ #include @@ -162,6 +165,8 @@ its specific setters. */ extern struct bt_field *bt_field_create(struct bt_field_type *field_type); +extern struct bt_field_type *bt_field_borrow_type(struct bt_field *field); + /** @brief Returns the parent @ft of the @field \p field. @@ -176,7 +181,11 @@ create the field object in the first place with bt_field_create(). @postrefcountsame{field} @postsuccessrefcountretinc */ -extern struct bt_field_type *bt_field_get_type(struct bt_field *field); +static inline +struct bt_field_type *bt_field_get_type(struct bt_field *field) +{ + return bt_get(bt_field_borrow_type(field)); +} /** @} */ @@ -611,6 +620,9 @@ returns a @enumftiter. @{ */ +extern struct bt_field *bt_field_enumeration_borrow_container( + struct bt_field *enum_field); + /** @brief Returns the @intfield, potentially creating it, wrapped by the @enumfield \p enum_field. @@ -628,8 +640,12 @@ exist. @postrefcountsame{enum_field} @postsuccessrefcountretinc */ -extern struct bt_field *bt_field_enumeration_get_container( - struct bt_field *enum_field); +static inline +struct bt_field *bt_field_enumeration_get_container( + struct bt_field *enum_field) +{ + return bt_get(bt_field_enumeration_borrow_container(enum_field)); +} /** @brief Returns a @enumftiter on all the mappings of the field type of @@ -827,6 +843,9 @@ field with bt_field_structure_set_field_by_name(). @{ */ +extern struct bt_field *bt_field_structure_borrow_field_by_name( + struct bt_field *struct_field, const char *name); + /** @brief Returns the @field named \p name, potentially creating it, in the @structfield \p struct_field. @@ -851,8 +870,16 @@ exist. @sa bt_field_structure_set_field_by_name(): Sets the field of a given structure field by name. */ -extern struct bt_field *bt_field_structure_get_field_by_name( - struct bt_field *struct_field, const char *name); +static inline +struct bt_field *bt_field_structure_get_field_by_name( + struct bt_field *struct_field, const char *name) +{ + return bt_get(bt_field_structure_borrow_field_by_name(struct_field, + name)); +} + +extern struct bt_field *bt_field_structure_borrow_field_by_index( + struct bt_field *struct_field, uint64_t index); /** @brief Returns the @field at index \p index in the @structfield @@ -877,8 +904,13 @@ extern struct bt_field *bt_field_structure_get_field_by_name( @sa bt_field_structure_set_field_by_name(): Sets the field of a given structure field by name. */ -extern struct bt_field *bt_field_structure_get_field_by_index( - struct bt_field *struct_field, uint64_t index); +static inline +struct bt_field *bt_field_structure_get_field_by_index( + struct bt_field *struct_field, uint64_t index) +{ + return bt_get(bt_field_structure_borrow_field_by_index(struct_field, + index)); +} /** @brief Sets the field of the @structfield \p struct_field named \p name @@ -949,6 +981,9 @@ first get the field with bt_field_array_get_field(). @{ */ +extern struct bt_field *bt_field_array_borrow_field( + struct bt_field *array_field, uint64_t index); + /** @brief Returns the @field at index \p index, potentially creating it, in the @arrayfield \p array_field. @@ -969,8 +1004,12 @@ exist. @postrefcountsame{array_field} @postsuccessrefcountretinc */ -extern struct bt_field *bt_field_array_get_field( - struct bt_field *array_field, uint64_t index); +static inline +struct bt_field *bt_field_array_get_field( + struct bt_field *array_field, uint64_t index) +{ + return bt_get(bt_field_array_borrow_field(array_field, index)); +} /** @} */ @@ -1000,6 +1039,9 @@ it contains. @{ */ +extern struct bt_field *bt_field_sequence_borrow_field( + struct bt_field *sequence_field, uint64_t index); + /** @brief Returns the @field at index \p index, potentially creating it, in the @seqfield \p sequence_field. @@ -1024,8 +1066,15 @@ exist. @postrefcountsame{sequence_field} @postsuccessrefcountretinc */ -extern struct bt_field *bt_field_sequence_get_field( - struct bt_field *sequence_field, uint64_t index); +static inline +struct bt_field *bt_field_sequence_get_field( + struct bt_field *sequence_field, uint64_t index) +{ + return bt_get(bt_field_sequence_borrow_field(sequence_field, index)); +} + +extern struct bt_field *bt_field_sequence_borrow_length( + struct bt_field *sequence_field); /** @brief Returns the length @intfield of the @seqfield \p sequence_field. @@ -1049,8 +1098,12 @@ number of fields contained in \p sequence_field. @sa bt_field_sequence_set_length(): Sets the length field of a given sequence field. */ -extern struct bt_field *bt_field_sequence_get_length( - struct bt_field *sequence_field); +static inline +struct bt_field *bt_field_sequence_get_length( + struct bt_field *sequence_field) +{ + return bt_get(bt_field_sequence_borrow_length(sequence_field)); +} /** @brief Sets the length @intfield of the @seqfield \p sequence_field @@ -1105,6 +1158,10 @@ field again. @{ */ +extern struct bt_field *bt_field_variant_borrow_field( + struct bt_field *variant_field, + struct bt_field *tag_field); + /** @brief Returns the @field, potentially creating it, selected by the tag @intfield \p tag_field in the @varfield \p variant_field. @@ -1130,9 +1187,16 @@ and you can call bt_field_variant_get_tag() to get \p tag_field. @postsuccessrefcountinc{tag_field} @postsuccessrefcountretinc */ -extern struct bt_field *bt_field_variant_get_field( +static inline +struct bt_field *bt_field_variant_get_field( struct bt_field *variant_field, - struct bt_field *tag_field); + struct bt_field *tag_field) +{ + return bt_get(bt_field_variant_borrow_field(variant_field, tag_field)); +} + +extern struct bt_field *bt_field_variant_borrow_current_field( + struct bt_field *variant_field); /** @brief Returns the currently selected @field of the @varfield @@ -1151,7 +1215,14 @@ extern struct bt_field *bt_field_variant_get_field( @postrefcountsame{variant_field} @postsuccessrefcountretinc */ -extern struct bt_field *bt_field_variant_get_current_field( +static inline +struct bt_field *bt_field_variant_get_current_field( + struct bt_field *variant_field) +{ + return bt_get(bt_field_variant_borrow_current_field(variant_field)); +} + +extern struct bt_field *bt_field_variant_borrow_tag( struct bt_field *variant_field); /** @@ -1170,8 +1241,12 @@ extern struct bt_field *bt_field_variant_get_current_field( @postsuccessrefcountretinc @post On success, the returned field is a @enumfield. */ -extern struct bt_field *bt_field_variant_get_tag( - struct bt_field *variant_field); +static inline +struct bt_field *bt_field_variant_get_tag( + struct bt_field *variant_field) +{ + return bt_get(bt_field_variant_borrow_tag(variant_field)); +} /** @} */ diff --git a/include/babeltrace/ctf-ir/packet-internal.h b/include/babeltrace/ctf-ir/packet-internal.h index f3fe96cf..9f66fb14 100644 --- a/include/babeltrace/ctf-ir/packet-internal.h +++ b/include/babeltrace/ctf-ir/packet-internal.h @@ -48,12 +48,4 @@ void _bt_packet_freeze(struct bt_packet *packet); # define bt_packet_freeze #endif /* BT_DEV_MODE */ -static inline -struct bt_stream *bt_packet_borrow_stream( - struct bt_packet *packet) -{ - BT_ASSERT(packet); - return packet->stream; -} - #endif /* BABELTRACE_CTF_IR_PACKET_INTERNAL_H */ diff --git a/include/babeltrace/ctf-ir/packet.h b/include/babeltrace/ctf-ir/packet.h index 996f6e7c..ef3b83ea 100644 --- a/include/babeltrace/ctf-ir/packet.h +++ b/include/babeltrace/ctf-ir/packet.h @@ -28,6 +28,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + #include #ifdef __cplusplus @@ -118,6 +121,9 @@ bt_packet_set_header() and bt_packet_set_context(). extern struct bt_packet *bt_packet_create( struct bt_stream *stream); +extern struct bt_stream *bt_packet_borrow_stream( + struct bt_packet *packet); + /** @brief Returns the parent CTF IR stream of the CTF IR packet \p packet. @@ -131,8 +137,12 @@ the packet object in the first place with bt_packet_create(). @postrefcountsame{packet} @postsuccessrefcountretinc */ -extern struct bt_stream *bt_packet_get_stream( - struct bt_packet *packet); +static inline +struct bt_stream *bt_packet_get_stream( + struct bt_packet *packet) +{ + return bt_get(bt_packet_borrow_stream(packet)); +} /** @} */ @@ -141,6 +151,9 @@ extern struct bt_stream *bt_packet_get_stream( @{ */ +extern +struct bt_field *bt_packet_borrow_header(struct bt_packet *packet); + /** @brief Returns the trace packet header field of the CTF IR packet \p packet. @@ -158,8 +171,11 @@ extern struct bt_stream *bt_packet_get_stream( @sa bt_packet_set_header(): Sets the trace packet header field of a given packet. */ -extern struct bt_field *bt_packet_get_header( - struct bt_packet *packet); +static inline +struct bt_field *bt_packet_get_header(struct bt_packet *packet) +{ + return bt_get(bt_packet_borrow_header(packet)); +} /** @brief Sets the trace packet header field of the CTF IR packet \p packet to @@ -187,8 +203,11 @@ bt_trace_get_packet_header_type() for the parent trace class of @sa bt_packet_get_header(): Returns the trace packet header field of a given packet. */ -extern int bt_packet_set_header( - struct bt_packet *packet, struct bt_field *header); +extern int bt_packet_set_header(struct bt_packet *packet, + struct bt_field *header); + +extern struct bt_field *bt_packet_borrow_context( + struct bt_packet *packet); /** @brief Returns the stream packet context field of the CTF IR packet @@ -207,8 +226,11 @@ extern int bt_packet_set_header( @sa bt_packet_set_context(): Sets the stream packet context field of a given packet. */ -extern struct bt_field *bt_packet_get_context( - struct bt_packet *packet); +static inline +struct bt_field *bt_packet_get_context(struct bt_packet *packet) +{ + return bt_get(bt_packet_borrow_context(packet)); +} /** @brief Sets the stream packet context field of the CTF IR packet \p packet to diff --git a/include/babeltrace/ctf-ir/stream-class-internal.h b/include/babeltrace/ctf-ir/stream-class-internal.h index 40411108..9968fc54 100644 --- a/include/babeltrace/ctf-ir/stream-class-internal.h +++ b/include/babeltrace/ctf-ir/stream-class-internal.h @@ -158,22 +158,6 @@ struct bt_trace_common *bt_stream_class_common_borrow_trace( return (void *) bt_object_borrow_parent(stream_class); } -static inline -struct bt_trace *bt_stream_class_borrow_trace( - struct bt_stream_class *stream_class) -{ - return BT_FROM_COMMON(bt_stream_class_common_borrow_trace( - BT_TO_COMMON(stream_class))); -} - -static inline -struct bt_trace_common *bt_stream_class_common_get_trace( - struct bt_stream_class_common *stream_class) -{ - BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); - return bt_get(bt_stream_class_common_borrow_trace(stream_class)); -} - static inline int bt_stream_class_common_set_name(struct bt_stream_class_common *stream_class, const char *name) @@ -302,7 +286,7 @@ end: } static inline -struct bt_event_class_common *bt_stream_class_common_get_event_class_by_index( +struct bt_event_class_common *bt_stream_class_common_borrow_event_class_by_index( struct bt_stream_class_common *stream_class, uint64_t index) { BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); @@ -310,11 +294,11 @@ struct bt_event_class_common *bt_stream_class_common_get_event_class_by_index( "Index is out of bounds: index=%" PRIu64 ", " "count=%u", index, stream_class->event_classes->len); - return bt_get(g_ptr_array_index(stream_class->event_classes, index)); + return g_ptr_array_index(stream_class->event_classes, index); } static inline -struct bt_event_class_common *bt_stream_class_common_get_event_class_by_id( +struct bt_event_class_common *bt_stream_class_common_borrow_event_class_by_id( struct bt_stream_class_common *stream_class, uint64_t id) { int64_t id_key = (int64_t) id; @@ -322,16 +306,17 @@ struct bt_event_class_common *bt_stream_class_common_get_event_class_by_id( BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); BT_ASSERT_PRE(id_key >= 0, "Invalid event class ID: %" PRIu64, id); - return bt_get(g_hash_table_lookup(stream_class->event_classes_ht, - &id_key)); + return g_hash_table_lookup(stream_class->event_classes_ht, + &id_key); } static inline -struct bt_field_type_common *bt_stream_class_common_get_packet_context_field_type( +struct bt_field_type_common * +bt_stream_class_common_borrow_packet_context_field_type( struct bt_stream_class_common *stream_class) { BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); - return bt_get(stream_class->packet_context_field_type); + return stream_class->packet_context_field_type; } static inline @@ -387,7 +372,8 @@ end: } static inline -struct bt_field_type_common *bt_stream_class_common_get_event_header_field_type( +struct bt_field_type_common * +bt_stream_class_common_borrow_event_header_field_type( struct bt_stream_class_common *stream_class) { struct bt_field_type_common *ret = NULL; @@ -403,7 +389,7 @@ struct bt_field_type_common *bt_stream_class_common_get_event_header_field_type( goto end; } - ret = bt_get(stream_class->event_header_field_type); + ret = stream_class->event_header_field_type; end: return ret; @@ -461,7 +447,8 @@ end: } static inline -struct bt_field_type_common *bt_stream_class_common_get_event_context_field_type( +struct bt_field_type_common * +bt_stream_class_common_borrow_event_context_field_type( struct bt_stream_class_common *stream_class) { struct bt_field_type_common *ret = NULL; @@ -472,7 +459,7 @@ struct bt_field_type_common *bt_stream_class_common_get_event_context_field_type goto end; } - ret = bt_get(stream_class->event_context_field_type); + ret = stream_class->event_context_field_type; end: return ret; diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index 94d7c9b8..c34d3315 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -32,6 +32,9 @@ #include +/* For bt_get() */ +#include + /* For bt_visitor */ #include @@ -178,6 +181,9 @@ bt_stream_class_set_event_header_field_type(). */ extern struct bt_stream_class *bt_stream_class_create(const char *name); +extern struct bt_trace *bt_stream_class_borrow_trace( + struct bt_stream_class *stream_class); + /** @brief Returns the parent CTF IR trace class of the CTF IR stream class \p stream_class. @@ -200,8 +206,12 @@ bt_trace_add_stream_class(). @sa bt_trace_add_stream_class(): Add a stream class to a trace class. */ -extern struct bt_trace *bt_stream_class_get_trace( - struct bt_stream_class *stream_class); +static inline +struct bt_trace *bt_stream_class_get_trace( + struct bt_stream_class *stream_class) +{ + return bt_get(bt_stream_class_borrow_trace(stream_class)); +} /** @} */ @@ -300,6 +310,9 @@ extern int bt_stream_class_set_id( @{ */ +extern struct bt_field_type *bt_stream_class_borrow_packet_context_field_type( + struct bt_stream_class *stream_class); + /** @brief Returns the packet context field type of the CTF IR stream class \p stream_class. @@ -318,8 +331,13 @@ extern int bt_stream_class_set_id( @sa bt_stream_class_set_packet_context_field_type(): Sets the packet context field type of a given stream class. */ -extern struct bt_field_type *bt_stream_class_get_packet_context_field_type( - struct bt_stream_class *stream_class); +static inline +struct bt_field_type *bt_stream_class_get_packet_context_field_type( + struct bt_stream_class *stream_class) +{ + return bt_get(bt_stream_class_borrow_packet_context_field_type( + stream_class)); +} /** @brief Sets the packet context field type of the CTF IR stream class @@ -354,6 +372,10 @@ extern int bt_stream_class_set_packet_context_field_type( struct bt_stream_class *stream_class, struct bt_field_type *packet_context_type); +extern struct bt_field_type * +bt_stream_class_borrow_event_header_field_type( + struct bt_stream_class *stream_class); + /** @brief Returns the event header field type of the CTF IR stream class \p stream_class. @@ -372,9 +394,13 @@ extern int bt_stream_class_set_packet_context_field_type( @sa bt_stream_class_set_event_header_field_type(): Sets the event header field type of a given stream class. */ -extern struct bt_field_type * -bt_stream_class_get_event_header_field_type( - struct bt_stream_class *stream_class); +static inline +struct bt_field_type *bt_stream_class_get_event_header_field_type( + struct bt_stream_class *stream_class) +{ + return bt_get(bt_stream_class_borrow_event_header_field_type( + stream_class)); +} /** @brief Sets the event header field type of the CTF IR stream class @@ -409,6 +435,10 @@ extern int bt_stream_class_set_event_header_field_type( struct bt_stream_class *stream_class, struct bt_field_type *event_header_type); +extern struct bt_field_type * +bt_stream_class_borrow_event_context_field_type( + struct bt_stream_class *stream_class); + /** @brief Returns the event context field type of the CTF IR stream class \p stream_class. @@ -428,9 +458,14 @@ extern int bt_stream_class_set_event_header_field_type( @sa bt_stream_class_set_event_context_field_type(): Sets the event context field type of a given stream class. */ -extern struct bt_field_type * +static inline +struct bt_field_type * bt_stream_class_get_event_context_field_type( - struct bt_stream_class *stream_class); + struct bt_stream_class *stream_class) +{ + return bt_get(bt_stream_class_borrow_event_context_field_type( + stream_class)); +} /** @brief Sets the event context field type of the CTF IR stream class @@ -488,6 +523,9 @@ extern int bt_stream_class_set_event_context_field_type( extern int64_t bt_stream_class_get_event_class_count( struct bt_stream_class *stream_class); +extern struct bt_event_class *bt_stream_class_borrow_event_class_by_index( + struct bt_stream_class *stream_class, uint64_t index); + /** @brief Returns the event class at index \p index in the CTF IR stream class \p stream_class. @@ -507,8 +545,16 @@ extern int64_t bt_stream_class_get_event_class_count( @sa bt_stream_class_get_event_class_by_id(): Finds an event class by ID. */ -extern struct bt_event_class *bt_stream_class_get_event_class_by_index( - struct bt_stream_class *stream_class, uint64_t index); +static inline +struct bt_event_class *bt_stream_class_get_event_class_by_index( + struct bt_stream_class *stream_class, uint64_t index) +{ + return bt_get(bt_stream_class_borrow_event_class_by_index(stream_class, + index)); +} + +extern struct bt_event_class *bt_stream_class_borrow_event_class_by_id( + struct bt_stream_class *stream_class, uint64_t id); /** @brief Returns the event class with ID \c id found in the CTF IR stream @@ -523,8 +569,13 @@ extern struct bt_event_class *bt_stream_class_get_event_class_by_index( @postrefcountsame{stream_class} @postsuccessrefcountretinc */ -extern struct bt_event_class *bt_stream_class_get_event_class_by_id( - struct bt_stream_class *stream_class, uint64_t id); +static inline +struct bt_event_class *bt_stream_class_get_event_class_by_id( + struct bt_stream_class *stream_class, uint64_t id) +{ + return bt_get(bt_stream_class_borrow_event_class_by_id(stream_class, + id)); +} /** @brief Adds the CTF IR event class \p event_class to the diff --git a/include/babeltrace/ctf-ir/stream-internal.h b/include/babeltrace/ctf-ir/stream-internal.h index 14765f49..78c16c1d 100644 --- a/include/babeltrace/ctf-ir/stream-internal.h +++ b/include/babeltrace/ctf-ir/stream-internal.h @@ -85,20 +85,6 @@ struct bt_stream_class_common *bt_stream_common_borrow_class( return stream->stream_class; } -static inline -struct bt_stream_class *bt_stream_borrow_class(struct bt_stream *stream) -{ - BT_ASSERT(stream); - return BT_FROM_COMMON(bt_stream_common_borrow_class(BT_TO_COMMON(stream))); -} - -static inline -struct bt_stream_class_common *bt_stream_common_get_class( - struct bt_stream_common *stream) -{ - return bt_get(bt_stream_common_borrow_class(stream)); -} - static inline const char *bt_stream_common_get_name(struct bt_stream_common *stream) { diff --git a/include/babeltrace/ctf-ir/stream.h b/include/babeltrace/ctf-ir/stream.h index 4b4ac3cf..5f0fd26b 100644 --- a/include/babeltrace/ctf-ir/stream.h +++ b/include/babeltrace/ctf-ir/stream.h @@ -30,6 +30,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + #include #ifdef __cplusplus @@ -153,6 +156,9 @@ extern const char *bt_stream_get_name(struct bt_stream *stream); */ extern int64_t bt_stream_get_id(struct bt_stream *stream); +extern struct bt_stream_class *bt_stream_borrow_class( + struct bt_stream *stream); + /** @brief Returns the parent CTF IR stream class of the CTF IR stream \p stream. @@ -169,8 +175,12 @@ bt_stream_create(). @postrefcountsame{stream} @postsuccessrefcountretinc */ -extern struct bt_stream_class *bt_stream_get_class( - struct bt_stream *stream); +static inline +struct bt_stream_class *bt_stream_get_class( + struct bt_stream *stream) +{ + return bt_get(bt_stream_borrow_class(stream)); +} /** @} */ diff --git a/include/babeltrace/ctf-ir/trace-internal.h b/include/babeltrace/ctf-ir/trace-internal.h index 05f25beb..f2ca55c1 100644 --- a/include/babeltrace/ctf-ir/trace-internal.h +++ b/include/babeltrace/ctf-ir/trace-internal.h @@ -166,28 +166,27 @@ int64_t bt_trace_common_get_environment_field_count( static inline const char * bt_trace_common_get_environment_field_name_by_index( - struct bt_trace_common *trace, - uint64_t index) + struct bt_trace_common *trace, uint64_t index) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); return bt_attributes_get_field_name(trace->environment, index); } static inline -struct bt_value *bt_trace_common_get_environment_field_value_by_index( +struct bt_value *bt_trace_common_borrow_environment_field_value_by_index( struct bt_trace_common *trace, uint64_t index) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - return bt_attributes_get_field_value(trace->environment, index); + return bt_attributes_borrow_field_value(trace->environment, index); } static inline -struct bt_value *bt_trace_common_get_environment_field_value_by_name( +struct bt_value *bt_trace_common_borrow_environment_field_value_by_name( struct bt_trace_common *trace, const char *name) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); BT_ASSERT_PRE_NON_NULL(name, "Name"); - return bt_attributes_get_field_value_by_name(trace->environment, + return bt_attributes_borrow_field_value_by_name(trace->environment, name); } @@ -203,7 +202,7 @@ int64_t bt_trace_common_get_clock_class_count(struct bt_trace_common *trace) } static inline -struct bt_clock_class *bt_trace_common_get_clock_class_by_index( +struct bt_clock_class *bt_trace_common_borrow_clock_class_by_index( struct bt_trace_common *trace, uint64_t index) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); @@ -211,7 +210,7 @@ struct bt_clock_class *bt_trace_common_get_clock_class_by_index( "Index is out of bounds: index=%" PRIu64 ", " "count=%u", index, trace->clock_classes->len); - return bt_get(g_ptr_array_index(trace->clock_classes, index)); + return g_ptr_array_index(trace->clock_classes, index); } static inline @@ -222,7 +221,7 @@ int64_t bt_trace_common_get_stream_count(struct bt_trace_common *trace) } static inline -struct bt_stream_common *bt_trace_common_get_stream_by_index( +struct bt_stream_common *bt_trace_common_borrow_stream_by_index( struct bt_trace_common *trace, uint64_t index) { @@ -231,7 +230,7 @@ struct bt_stream_common *bt_trace_common_get_stream_by_index( "Index is out of bounds: index=%" PRIu64 ", " "count=%u", index, trace->streams->len); - return bt_get(g_ptr_array_index(trace->streams, index)); + return g_ptr_array_index(trace->streams, index); } static inline @@ -242,7 +241,7 @@ int64_t bt_trace_common_get_stream_class_count(struct bt_trace_common *trace) } static inline -struct bt_stream_class_common *bt_trace_common_get_stream_class_by_index( +struct bt_stream_class_common *bt_trace_common_borrow_stream_class_by_index( struct bt_trace_common *trace, uint64_t index) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); @@ -250,11 +249,11 @@ struct bt_stream_class_common *bt_trace_common_get_stream_class_by_index( "Index is out of bounds: index=%" PRIu64 ", " "count=%u", index, trace->stream_classes->len); - return bt_get(g_ptr_array_index(trace->stream_classes, index)); + return g_ptr_array_index(trace->stream_classes, index); } static inline -struct bt_stream_class_common *bt_trace_common_get_stream_class_by_id( +struct bt_stream_class_common *bt_trace_common_borrow_stream_class_by_id( struct bt_trace_common *trace, uint64_t id_param) { int i; @@ -274,7 +273,6 @@ struct bt_stream_class_common *bt_trace_common_get_stream_class_by_id( if (bt_stream_class_common_get_id(stream_class_candidate) == (int64_t) id) { stream_class = stream_class_candidate; - bt_get(stream_class); goto end; } } @@ -284,7 +282,7 @@ end: } static inline -struct bt_clock_class *bt_trace_common_get_clock_class_by_name( +struct bt_clock_class *bt_trace_common_borrow_clock_class_by_name( struct bt_trace_common *trace, const char *name) { size_t i; @@ -304,7 +302,6 @@ struct bt_clock_class *bt_trace_common_get_clock_class_by_name( if (!strcmp(cur_clk_name, name)) { clock_class = cur_clk; - bt_get(clock_class); goto end; } } @@ -326,11 +323,11 @@ int bt_trace_common_set_native_byte_order(struct bt_trace_common *trace, enum bt_byte_order byte_order, bool allow_unspecified); static inline -struct bt_field_type_common *bt_trace_common_get_packet_header_field_type( +struct bt_field_type_common *bt_trace_common_borrow_packet_header_field_type( struct bt_trace_common *trace) { BT_ASSERT_PRE_NON_NULL(trace, "Trace"); - return bt_get(trace->packet_header_field_type); + return trace->packet_header_field_type; } BT_HIDDEN diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index a80cfc01..e855e636 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -30,6 +30,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + /* For bt_visitor */ #include @@ -390,6 +393,10 @@ extern const char * bt_trace_get_environment_field_name_by_index( struct bt_trace *trace_class, uint64_t index); +extern struct bt_value * +bt_trace_borrow_environment_field_value_by_index(struct bt_trace *trace_class, + uint64_t index); + /** @brief Returns the value of the environment entry at index \p index in the CTF IR trace class \p trace_class. @@ -411,9 +418,17 @@ bt_trace_get_environment_field_name_by_index( @sa bt_trace_set_environment_field(): Sets the value of a trace class's environment entry. */ +static inline +struct bt_value *bt_trace_get_environment_field_value_by_index( + struct bt_trace *trace_class, uint64_t index) +{ + return bt_get(bt_trace_borrow_environment_field_value_by_index( + trace_class, index)); +} + extern struct bt_value * -bt_trace_get_environment_field_value_by_index(struct bt_trace *trace_class, - uint64_t index); +bt_trace_borrow_environment_field_value_by_name( + struct bt_trace *trace_class, const char *name); /** @brief Returns the value of the environment entry named \p name @@ -436,9 +451,15 @@ bt_trace_get_environment_field_value_by_index(struct bt_trace *trace_class, @sa bt_trace_set_environment_field(): Sets the value of a trace class's environment entry. */ -extern struct bt_value * +static inline +struct bt_value * bt_trace_get_environment_field_value_by_name( - struct bt_trace *trace_class, const char *name); + struct bt_trace *trace_class, const char *name) +{ + return bt_get( + bt_trace_borrow_environment_field_value_by_name( + trace_class, name)); +} /** @brief Sets the environment entry named \p name in the @@ -539,6 +560,9 @@ extern int bt_trace_set_environment_field_string( @{ */ +extern struct bt_field_type *bt_trace_borrow_packet_header_field_type( + struct bt_trace *trace_class); + /** @brief Returns the packet header field type of the CTF IR trace class \p trace_class. @@ -557,8 +581,12 @@ extern int bt_trace_set_environment_field_string( @sa bt_trace_set_packet_header_field_type(): Sets the packet header field type of a given trace class. */ -extern struct bt_field_type *bt_trace_get_packet_header_field_type( - struct bt_trace *trace_class); +static inline +struct bt_field_type *bt_trace_get_packet_header_field_type( + struct bt_trace *trace_class) +{ + return bt_get(bt_trace_borrow_packet_header_field_type(trace_class)); +} /** @brief Sets the packet header field type of the CTF IR trace class @@ -615,6 +643,9 @@ extern int bt_trace_set_packet_header_field_type(struct bt_trace *trace_class, extern int64_t bt_trace_get_clock_class_count( struct bt_trace *trace_class); +extern struct bt_clock_class *bt_trace_borrow_clock_class_by_index( + struct bt_trace *trace_class, uint64_t index); + /** @brief Returns the CTF IR clock class at index \p index in the CTF IR trace class \p trace_class. @@ -637,8 +668,16 @@ extern int64_t bt_trace_get_clock_class_count( in a given trace class. @sa bt_trace_add_clock_class(): Adds a clock class to a trace class. */ -extern struct bt_clock_class *bt_trace_get_clock_class_by_index( - struct bt_trace *trace_class, uint64_t index); +static inline +struct bt_clock_class *bt_trace_get_clock_class_by_index( + struct bt_trace *trace_class, uint64_t index) +{ + return bt_get(bt_trace_borrow_clock_class_by_index( + trace_class, index)); +} + +extern struct bt_clock_class *bt_trace_borrow_clock_class_by_name( + struct bt_trace *trace_class, const char *name); /** @brief Returns the CTF IR clock class named \c name found in the CTF @@ -659,8 +698,12 @@ extern struct bt_clock_class *bt_trace_get_clock_class_by_index( in a given trace class at a given index. @sa bt_trace_add_clock_class(): Adds a clock class to a trace class. */ -extern struct bt_clock_class *bt_trace_get_clock_class_by_name( - struct bt_trace *trace_class, const char *name); +static inline +struct bt_clock_class *bt_trace_get_clock_class_by_name( + struct bt_trace *trace_class, const char *name) +{ + return bt_get(bt_trace_borrow_clock_class_by_name(trace_class, name)); +} /** @brief Adds the CTF IR clock class \p clock_class to the CTF IR @@ -713,6 +756,9 @@ extern int bt_trace_add_clock_class(struct bt_trace *trace_class, extern int64_t bt_trace_get_stream_class_count( struct bt_trace *trace_class); +extern struct bt_stream_class *bt_trace_borrow_stream_class_by_index( + struct bt_trace *trace_class, uint64_t index); + /** @brief Returns the stream class at index \p index in the CTF IR trace class \p trace_class. @@ -731,8 +777,16 @@ extern int64_t bt_trace_get_stream_class_count( @sa bt_trace_get_stream_class_by_id(): Finds a stream class by ID. @sa bt_trace_add_stream_class(): Adds a stream class to a trace class. */ -extern struct bt_stream_class *bt_trace_get_stream_class_by_index( - struct bt_trace *trace_class, uint64_t index); +static inline +struct bt_stream_class *bt_trace_get_stream_class_by_index( + struct bt_trace *trace_class, uint64_t index) +{ + return bt_get(bt_trace_borrow_stream_class_by_index( + trace_class, index)); +} + +extern struct bt_stream_class *bt_trace_borrow_stream_class_by_id( + struct bt_trace *trace_class, uint64_t id); /** @brief Returns the stream class with ID \c id found in the CTF IR @@ -751,8 +805,12 @@ extern struct bt_stream_class *bt_trace_get_stream_class_by_index( in a given trace class at a given index. @sa bt_trace_add_stream_class(): Adds a stream class to a trace class. */ -extern struct bt_stream_class *bt_trace_get_stream_class_by_id( - struct bt_trace *trace_class, uint64_t id); +static inline +struct bt_stream_class *bt_trace_get_stream_class_by_id( + struct bt_trace *trace_class, uint64_t id) +{ + return bt_get(bt_trace_borrow_stream_class_by_id(trace_class, id)); +} /** @brief Adds the CTF IR stream class \p stream_class to the @@ -810,6 +868,9 @@ extern int bt_trace_add_stream_class(struct bt_trace *trace_class, */ extern int64_t bt_trace_get_stream_count(struct bt_trace *trace_class); +extern struct bt_stream *bt_trace_borrow_stream_by_index( + struct bt_trace *trace_class, uint64_t index); + /** @brief Returns the stream at index \p index in the CTF IR trace class \p trace_class. @@ -825,8 +886,12 @@ extern int64_t bt_trace_get_stream_count(struct bt_trace *trace_class); bt_trace_get_stream_count()). @postrefcountsame{trace_class} */ -extern struct bt_stream *bt_trace_get_stream_by_index( - struct bt_trace *trace_class, uint64_t index); +static inline +struct bt_stream *bt_trace_get_stream_by_index( + struct bt_trace *trace_class, uint64_t index) +{ + return bt_get(bt_trace_borrow_stream_by_index(trace_class, index)); +} /** @} */ diff --git a/include/babeltrace/graph/clock-class-priority-map.h b/include/babeltrace/graph/clock-class-priority-map.h index cc471889..93f05ab8 100644 --- a/include/babeltrace/graph/clock-class-priority-map.h +++ b/include/babeltrace/graph/clock-class-priority-map.h @@ -26,6 +26,9 @@ * http://www.efficios.com/ctf */ +/* For bt_get() */ +#include + #include #include @@ -112,6 +115,11 @@ extern struct bt_clock_class_priority_map *bt_clock_class_priority_map_create(vo extern int64_t bt_clock_class_priority_map_get_clock_class_count( struct bt_clock_class_priority_map *clock_class_priority_map); +extern struct bt_clock_class * +bt_clock_class_priority_map_borrow_clock_class_by_index( + struct bt_clock_class_priority_map *clock_class_priority_map, + uint64_t index); + /** @brief Returns the CTF IR clock class at index \p index in the clock class priority map \p clock_class_priority_map. @@ -139,10 +147,20 @@ extern int64_t bt_clock_class_priority_map_get_clock_class_count( @sa bt_clock_class_priority_map_add_clock_class(): Adds a clock class to a clock class priority map. */ -extern struct bt_clock_class * +static inline +struct bt_clock_class * bt_clock_class_priority_map_get_clock_class_by_index( struct bt_clock_class_priority_map *clock_class_priority_map, - uint64_t index); + uint64_t index) +{ + return bt_get(bt_clock_class_priority_map_borrow_clock_class_by_index( + clock_class_priority_map, index)); +} + +extern struct bt_clock_class * +bt_clock_class_priority_map_borrow_clock_class_by_name( + struct bt_clock_class_priority_map *clock_class_priority_map, + const char *name); /** @brief Returns the CTF IR clock class named \c name found in the clock @@ -171,10 +189,18 @@ bt_clock_class_priority_map_get_clock_class_by_index( @sa bt_clock_class_priority_map_add_clock_class(): Adds a clock class to a clock class priority map. */ -extern struct bt_clock_class * -bt_clock_class_priority_map_get_clock_class_by_name( +static inline +struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_name( struct bt_clock_class_priority_map *clock_class_priority_map, - const char *name); + const char *name) +{ + return bt_get(bt_clock_class_priority_map_borrow_clock_class_by_name( + clock_class_priority_map, name)); +} + +extern struct bt_clock_class * +bt_clock_class_priority_map_borrow_highest_priority_clock_class( + struct bt_clock_class_priority_map *clock_class_priority_map); /** @brief Returns the CTF IR clock class with the currently highest @@ -207,9 +233,15 @@ this function returns. @sa bt_clock_class_priority_map_add_clock_class(): Adds a clock class to a clock class priority map. */ -extern struct bt_clock_class * +static inline +struct bt_clock_class * bt_clock_class_priority_map_get_highest_priority_clock_class( - struct bt_clock_class_priority_map *clock_class_priority_map); + struct bt_clock_class_priority_map *clock_class_priority_map) +{ + return bt_get( + bt_clock_class_priority_map_borrow_highest_priority_clock_class( + clock_class_priority_map)); +} /** @brief Returns the priority of the CTF IR clock class \p clock_class diff --git a/include/babeltrace/graph/notification-discarded-elements-internal.h b/include/babeltrace/graph/notification-discarded-elements-internal.h index 9697525c..489a0464 100644 --- a/include/babeltrace/graph/notification-discarded-elements-internal.h +++ b/include/babeltrace/graph/notification-discarded-elements-internal.h @@ -50,19 +50,19 @@ struct bt_notification *bt_notification_discarded_elements_create( uint64_t count); BT_HIDDEN -struct bt_stream *bt_notification_discarded_elements_get_stream( +struct bt_stream *bt_notification_discarded_elements_borrow_stream( enum bt_notification_type type, struct bt_notification *notification); BT_HIDDEN struct bt_clock_value * -bt_notification_discarded_elements_get_begin_clock_value( +bt_notification_discarded_elements_borrow_begin_clock_value( enum bt_notification_type type, struct bt_notification *notification); BT_HIDDEN struct bt_clock_value * -bt_notification_discarded_elements_get_end_clock_value( +bt_notification_discarded_elements_borrow_end_clock_value( enum bt_notification_type type, struct bt_notification *notification); @@ -71,16 +71,4 @@ int64_t bt_notification_discarded_elements_get_count( enum bt_notification_type type, struct bt_notification *notification); -static inline -struct bt_stream *bt_notification_discarded_elements_borrow_stream( - struct bt_notification *notification) -{ - struct bt_notification_discarded_elements *discarded_elems_notif; - - BT_ASSERT(notification); - discarded_elems_notif = container_of(notification, - struct bt_notification_discarded_elements, parent); - return discarded_elems_notif->stream; -} - #endif /* BABELTRACE_GRAPH_NOTIFICATION_DISCARDED_ELEMENTS_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-discarded-events.h b/include/babeltrace/graph/notification-discarded-events.h index 6a760f86..90108820 100644 --- a/include/babeltrace/graph/notification-discarded-events.h +++ b/include/babeltrace/graph/notification-discarded-events.h @@ -23,6 +23,9 @@ * SOFTWARE. */ +/* For bt_get() */ +#include + #include #ifdef __cplusplus @@ -35,19 +38,45 @@ struct bt_clock_class; struct bt_stream; extern struct bt_clock_value * -bt_notification_discarded_events_get_begin_clock_value( +bt_notification_discarded_events_borrow_begin_clock_value( struct bt_notification *notification); +static inline +struct bt_clock_value * +bt_notification_discarded_events_get_begin_clock_value( + struct bt_notification *notification) +{ + return bt_get(bt_notification_discarded_events_borrow_begin_clock_value( + notification)); +} + extern struct bt_clock_value * -bt_notification_discarded_events_get_end_clock_value( +bt_notification_discarded_events_borrow_end_clock_value( struct bt_notification *notification); +static inline +struct bt_clock_value * +bt_notification_discarded_events_get_end_clock_value( + struct bt_notification *notification) +{ + return bt_get(bt_notification_discarded_events_borrow_end_clock_value( + notification)); +} + extern int64_t bt_notification_discarded_events_get_count( struct bt_notification *notification); -extern struct bt_stream *bt_notification_discarded_events_get_stream( +extern struct bt_stream *bt_notification_discarded_events_borrow_stream( struct bt_notification *notification); +static inline +struct bt_stream *bt_notification_discarded_events_get_stream( + struct bt_notification *notification) +{ + return bt_get(bt_notification_discarded_events_borrow_stream( + notification)); +} + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification-discarded-packets.h b/include/babeltrace/graph/notification-discarded-packets.h index 4fc6a4b4..1627f249 100644 --- a/include/babeltrace/graph/notification-discarded-packets.h +++ b/include/babeltrace/graph/notification-discarded-packets.h @@ -23,6 +23,9 @@ * SOFTWARE. */ +/* For bt_get() */ +#include + #include #ifdef __cplusplus @@ -35,19 +38,46 @@ struct bt_clock_class; struct bt_stream; extern struct bt_clock_value * -bt_notification_discarded_packets_get_begin_clock_value( +bt_notification_discarded_packets_borrow_begin_clock_value( struct bt_notification *notification); +static inline +struct bt_clock_value * +bt_notification_discarded_packets_get_begin_clock_value( + struct bt_notification *notification) +{ + return bt_get( + bt_notification_discarded_packets_borrow_begin_clock_value( + notification)); +} + extern struct bt_clock_value * -bt_notification_discarded_packets_get_end_clock_value( +bt_notification_discarded_packets_borrow_end_clock_value( struct bt_notification *notification); +static inline +struct bt_clock_value * +bt_notification_discarded_packets_get_end_clock_value( + struct bt_notification *notification) +{ + return bt_get(bt_notification_discarded_packets_borrow_end_clock_value( + notification)); +} + extern int64_t bt_notification_discarded_packets_get_count( struct bt_notification *notification); -extern struct bt_stream *bt_notification_discarded_packets_get_stream( +extern struct bt_stream *bt_notification_discarded_packets_borrow_stream( struct bt_notification *notification); +static inline +struct bt_stream *bt_notification_discarded_packets_get_stream( + struct bt_notification *notification) +{ + return bt_get(bt_notification_discarded_packets_borrow_stream( + notification)); +} + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification-event-internal.h b/include/babeltrace/graph/notification-event-internal.h index 62b8a3ab..a5dea56f 100644 --- a/include/babeltrace/graph/notification-event-internal.h +++ b/include/babeltrace/graph/notification-event-internal.h @@ -43,30 +43,6 @@ struct bt_notification_event { struct bt_clock_class_priority_map *cc_prio_map; }; -static inline -struct bt_event *bt_notification_event_borrow_event( - struct bt_notification *notif) -{ - struct bt_notification_event *notif_event = container_of(notif, - struct bt_notification_event, parent); - - BT_ASSERT(notif_event); - return notif_event->event; -} - -static inline -struct bt_clock_class_priority_map * -bt_notification_event_borrow_clock_class_priority_map( - struct bt_notification *notif) -{ - struct bt_notification_event *notif_event = container_of(notif, - struct bt_notification_event, parent); - - BT_ASSERT(notif_event); - return notif_event->cc_prio_map; -} - - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification-event.h b/include/babeltrace/graph/notification-event.h index af2666b8..1df54eb2 100644 --- a/include/babeltrace/graph/notification-event.h +++ b/include/babeltrace/graph/notification-event.h @@ -27,6 +27,9 @@ * SOFTWARE. */ +/* For bt_get() */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -35,7 +38,6 @@ struct bt_notification; struct bt_event; struct bt_clock_class_priority_map; -/***BT_NOTIFICATION_TYPE_EVENT ***/ /** * Create an event notification. * @@ -48,6 +50,9 @@ extern struct bt_notification *bt_notification_event_create( struct bt_event *event, struct bt_clock_class_priority_map *clock_class_priority_map); +extern struct bt_event *bt_notification_event_borrow_event( + struct bt_notification *notification); + /** * Get an event notification's event. * @@ -56,13 +61,26 @@ extern struct bt_notification *bt_notification_event_create( * * @see #bt_event */ -extern struct bt_event *bt_notification_event_get_event( - struct bt_notification *notification); +static inline +struct bt_event *bt_notification_event_get_event( + struct bt_notification *notification) +{ + return bt_get(bt_notification_event_borrow_event(notification)); +} extern struct bt_clock_class_priority_map * -bt_notification_event_get_clock_class_priority_map( +bt_notification_event_borrow_clock_class_priority_map( struct bt_notification *notification); +static inline +struct bt_clock_class_priority_map * +bt_notification_event_get_clock_class_priority_map( + struct bt_notification *notification) +{ + return bt_get(bt_notification_event_borrow_clock_class_priority_map( + notification)); +} + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification-inactivity.h b/include/babeltrace/graph/notification-inactivity.h index 44dade89..34099731 100644 --- a/include/babeltrace/graph/notification-inactivity.h +++ b/include/babeltrace/graph/notification-inactivity.h @@ -23,6 +23,9 @@ * SOFTWARE. */ +/* For bt_get() */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -35,13 +38,32 @@ extern struct bt_notification *bt_notification_inactivity_create( struct bt_clock_class_priority_map *clock_class_priority_map); extern struct bt_clock_class_priority_map * -bt_notification_inactivity_get_clock_class_priority_map( +bt_notification_inactivity_borrow_clock_class_priority_map( struct bt_notification *notification); -extern struct bt_clock_value *bt_notification_inactivity_get_clock_value( +static inline +struct bt_clock_class_priority_map * +bt_notification_inactivity_get_clock_class_priority_map( + struct bt_notification *notification) +{ + return bt_get( + bt_notification_inactivity_borrow_clock_class_priority_map( + notification)); +} + +extern struct bt_clock_value *bt_notification_inactivity_borrow_clock_value( struct bt_notification *notification, struct bt_clock_class *clock_class); +static inline +struct bt_clock_value *bt_notification_inactivity_get_clock_value( + struct bt_notification *notification, + struct bt_clock_class *clock_class) +{ + return bt_get(bt_notification_inactivity_borrow_clock_value( + notification, clock_class)); +} + extern int bt_notification_inactivity_set_clock_value( struct bt_notification *notification, struct bt_clock_value *clock_value); diff --git a/include/babeltrace/graph/notification-iterator.h b/include/babeltrace/graph/notification-iterator.h index 4d94e22c..a062f2e4 100644 --- a/include/babeltrace/graph/notification-iterator.h +++ b/include/babeltrace/graph/notification-iterator.h @@ -27,6 +27,9 @@ * SOFTWARE. */ +/* For bt_get() */ +#include + #include #ifdef __cplusplus @@ -58,6 +61,9 @@ enum bt_notification_iterator_status { BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED = -2, }; +extern struct bt_notification *bt_notification_iterator_borrow_notification( + struct bt_notification_iterator *iterator); + /** * Get current notification at iterator's position. * @@ -69,8 +75,12 @@ enum bt_notification_iterator_status { * * @see bt_put() */ -extern struct bt_notification *bt_notification_iterator_get_notification( - struct bt_notification_iterator *iterator); +static inline +struct bt_notification *bt_notification_iterator_get_notification( + struct bt_notification_iterator *iterator) +{ + return bt_get(bt_notification_iterator_borrow_notification(iterator)); +} /** * Advance the iterator's position forward. diff --git a/include/babeltrace/graph/notification-packet-internal.h b/include/babeltrace/graph/notification-packet-internal.h index 1c591751..467d0861 100644 --- a/include/babeltrace/graph/notification-packet-internal.h +++ b/include/babeltrace/graph/notification-packet-internal.h @@ -42,28 +42,4 @@ struct bt_notification_packet_end { struct bt_packet *packet; }; -static inline -struct bt_packet *bt_notification_packet_begin_borrow_packet( - struct bt_notification *notif) -{ - struct bt_notification_packet_begin *notif_packet_begin = - container_of(notif, - struct bt_notification_packet_begin, parent); - - BT_ASSERT(notif_packet_begin); - return notif_packet_begin->packet; -} - -static inline -struct bt_packet *bt_notification_packet_end_borrow_packet( - struct bt_notification *notif) -{ - struct bt_notification_packet_end *notif_packet_end = - container_of(notif, - struct bt_notification_packet_end, parent); - - BT_ASSERT(notif_packet_end); - return notif_packet_end->packet; -} - #endif /* BABELTRACE_GRAPH_NOTIFICATION_PACKET_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-packet.h b/include/babeltrace/graph/notification-packet.h index 38c4f6e6..6b237c3b 100644 --- a/include/babeltrace/graph/notification-packet.h +++ b/include/babeltrace/graph/notification-packet.h @@ -27,6 +27,9 @@ * SOFTWARE. */ +/* For bt_get() */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -40,14 +43,26 @@ extern struct bt_notification *bt_notification_packet_begin_create( extern struct bt_notification *bt_notification_packet_end_create( struct bt_packet *packet); -/*** BT_NOTIFICATION_TYPE_PACKET_BEGIN ***/ -extern struct bt_packet *bt_notification_packet_begin_get_packet( +extern struct bt_packet *bt_notification_packet_begin_borrow_packet( struct bt_notification *notification); -/*** BT_NOTIFICATION_TYPE_PACKET_END ***/ -extern struct bt_packet *bt_notification_packet_end_get_packet( +static inline +struct bt_packet *bt_notification_packet_begin_get_packet( + struct bt_notification *notification) +{ + return bt_get(bt_notification_packet_begin_borrow_packet(notification)); +} + +extern struct bt_packet *bt_notification_packet_end_borrow_packet( struct bt_notification *notification); +static inline +struct bt_packet *bt_notification_packet_end_get_packet( + struct bt_notification *notification) +{ + return bt_get(bt_notification_packet_end_borrow_packet(notification)); +} + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/graph/notification-stream-internal.h b/include/babeltrace/graph/notification-stream-internal.h index a9067947..708d0fae 100644 --- a/include/babeltrace/graph/notification-stream-internal.h +++ b/include/babeltrace/graph/notification-stream-internal.h @@ -42,28 +42,4 @@ struct bt_notification_stream_end { struct bt_stream *stream; }; -static inline -struct bt_stream *bt_notification_stream_begin_borrow_stream( - struct bt_notification *notif) -{ - struct bt_notification_stream_begin *notif_stream_begin = - container_of(notif, - struct bt_notification_stream_begin, parent); - - BT_ASSERT(notif_stream_begin); - return notif_stream_begin->stream; -} - -static inline -struct bt_stream *bt_notification_stream_end_borrow_stream( - struct bt_notification *notif) -{ - struct bt_notification_stream_end *notif_stream_end = - container_of(notif, - struct bt_notification_stream_end, parent); - - BT_ASSERT(notif_stream_end); - return notif_stream_end->stream; -} - #endif /* BABELTRACE_GRAPH_NOTIFICATION_STREAM_INTERNAL_H */ diff --git a/include/babeltrace/graph/notification-stream.h b/include/babeltrace/graph/notification-stream.h index bb4c5d60..5deff05b 100644 --- a/include/babeltrace/graph/notification-stream.h +++ b/include/babeltrace/graph/notification-stream.h @@ -27,6 +27,9 @@ * SOFTWARE. */ +/* For bt_get() */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -40,12 +43,26 @@ extern struct bt_notification *bt_notification_stream_begin_create( extern struct bt_notification *bt_notification_stream_end_create( struct bt_stream *stream); -extern struct bt_stream *bt_notification_stream_begin_get_stream( +extern struct bt_stream *bt_notification_stream_begin_borrow_stream( struct bt_notification *notification); -extern struct bt_stream *bt_notification_stream_end_get_stream( +static inline +struct bt_stream *bt_notification_stream_begin_get_stream( + struct bt_notification *notification) +{ + return bt_get(bt_notification_stream_begin_borrow_stream(notification)); +} + +extern struct bt_stream *bt_notification_stream_end_borrow_stream( struct bt_notification *notification); +static inline +struct bt_stream *bt_notification_stream_end_get_stream( + struct bt_notification *notification) +{ + return bt_get(bt_notification_stream_end_borrow_stream(notification)); +} + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index d15256da..89894f69 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -32,6 +32,9 @@ /* For bt_bool */ #include +/* For bt_get() */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -811,6 +814,9 @@ extern int64_t bt_value_array_size(const struct bt_value *array_obj); */ extern bt_bool bt_value_array_is_empty(const struct bt_value *array_obj); +extern struct bt_value *bt_value_array_borrow(const struct bt_value *array_obj, + uint64_t index); + /** @brief Returns the value object contained in the array value object \p array_obj at the index \p index. @@ -828,8 +834,12 @@ extern bt_bool bt_value_array_is_empty(const struct bt_value *array_obj); \ref bt_value_null, its reference count is incremented. @postrefcountsame{array_obj} */ -extern struct bt_value *bt_value_array_get(const struct bt_value *array_obj, - uint64_t index); +static inline +struct bt_value *bt_value_array_get(const struct bt_value *array_obj, + uint64_t index) +{ + return bt_get(bt_value_array_borrow(array_obj, index)); +} /** @brief Appends the value object \p element_obj to the array value @@ -1077,6 +1087,9 @@ extern int64_t bt_value_map_size(const struct bt_value *map_obj); */ extern bt_bool bt_value_map_is_empty(const struct bt_value *map_obj); +extern struct bt_value *bt_value_map_borrow(const struct bt_value *map_obj, + const char *key); + /** @brief Returns the value object associated with the key \p key within the map value object \p map_obj. @@ -1093,8 +1106,12 @@ extern bt_bool bt_value_map_is_empty(const struct bt_value *map_obj); @post On success, if the returned value object is not \ref bt_value_null, its reference count is incremented. */ -extern struct bt_value *bt_value_map_get(const struct bt_value *map_obj, - const char *key); +static inline +struct bt_value *bt_value_map_get(const struct bt_value *map_obj, + const char *key) +{ + return bt_get(bt_value_map_borrow(map_obj, key)); +} /** @brief User function type to use with bt_value_map_foreach(). diff --git a/lib/ctf-ir/attributes.c b/lib/ctf-ir/attributes.c index b5fe54cd..ccd93b17 100644 --- a/lib/ctf-ir/attributes.c +++ b/lib/ctf-ir/attributes.c @@ -104,14 +104,14 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, goto end; } - attr_field_obj = bt_value_array_get(attr_obj, index); + attr_field_obj = bt_value_array_borrow(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - attr_field_name_obj = bt_value_array_get(attr_field_obj, + attr_field_name_obj = bt_value_array_borrow(attr_field_obj, BT_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -128,13 +128,11 @@ const char *bt_attributes_get_field_name(struct bt_value *attr_obj, } end: - BT_PUT(attr_field_name_obj); - BT_PUT(attr_field_obj); return ret; } BT_HIDDEN -struct bt_value *bt_attributes_get_field_value(struct bt_value *attr_obj, +struct bt_value *bt_attributes_borrow_field_value(struct bt_value *attr_obj, uint64_t index) { struct bt_value *value_obj = NULL; @@ -152,14 +150,14 @@ struct bt_value *bt_attributes_get_field_value(struct bt_value *attr_obj, goto end; } - attr_field_obj = bt_value_array_get(attr_obj, index); + attr_field_obj = bt_value_array_borrow(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - value_obj = bt_value_array_get(attr_field_obj, + value_obj = bt_value_array_borrow(attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -168,12 +166,11 @@ struct bt_value *bt_attributes_get_field_value(struct bt_value *attr_obj, } end: - BT_PUT(attr_field_obj); return value_obj; } static -struct bt_value *bt_attributes_get_field_by_name( +struct bt_value *bt_attributes_borrow_field_by_name( struct bt_value *attr_obj, const char *name) { uint64_t i; @@ -192,18 +189,19 @@ struct bt_value *bt_attributes_get_field_by_name( int ret; const char *field_name; - value_obj = bt_value_array_get(attr_obj, i); + value_obj = bt_value_array_borrow(attr_obj, i); if (!value_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, i); goto error; } - attr_field_name_obj = bt_value_array_get(value_obj, 0); + attr_field_name_obj = bt_value_array_borrow(value_obj, + BT_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " "value-addr=%p, index=%" PRIu64, - value_obj, (int64_t) 0); + value_obj, (int64_t) BT_ATTR_NAME_INDEX); goto error; } @@ -215,20 +213,16 @@ struct bt_value *bt_attributes_get_field_by_name( } if (!strcmp(field_name, name)) { - BT_PUT(attr_field_name_obj); break; } - BT_PUT(attr_field_name_obj); - BT_PUT(value_obj); + value_obj = NULL; } return value_obj; error: - BT_PUT(attr_field_name_obj); - BT_PUT(value_obj); - + value_obj = NULL; return value_obj; } @@ -247,10 +241,11 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, goto end; } - attr_field_obj = bt_attributes_get_field_by_name(attr_obj, name); + attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name); if (attr_field_obj) { ret = bt_value_array_set(attr_field_obj, BT_ATTR_VALUE_INDEX, value_obj); + attr_field_obj = NULL; goto end; } @@ -277,13 +272,12 @@ int bt_attributes_set_field_value(struct bt_value *attr_obj, } end: - BT_PUT(attr_field_obj); - + bt_put(attr_field_obj); return ret; } BT_HIDDEN -struct bt_value *bt_attributes_get_field_value_by_name( +struct bt_value *bt_attributes_borrow_field_value_by_name( struct bt_value *attr_obj, const char *name) { struct bt_value *value_obj = NULL; @@ -295,14 +289,14 @@ struct bt_value *bt_attributes_get_field_value_by_name( goto end; } - attr_field_obj = bt_attributes_get_field_by_name(attr_obj, name); + attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name); if (!attr_field_obj) { BT_LOGD("Cannot find attributes object's field by name: " "value-addr=%p, name=\"%s\"", attr_obj, name); goto end; } - value_obj = bt_value_array_get(attr_field_obj, + value_obj = bt_value_array_borrow(attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -311,8 +305,6 @@ struct bt_value *bt_attributes_get_field_value_by_name( } end: - BT_PUT(attr_field_obj); - return value_obj; } @@ -341,7 +333,7 @@ int bt_attributes_freeze(struct bt_value *attr_obj) for (i = 0; i < count; ++i) { struct bt_value *obj = NULL; - obj = bt_attributes_get_field_value(attr_obj, i); + obj = bt_attributes_borrow_field_value(attr_obj, i); if (!obj) { BT_LOGE("Cannot get attributes object's field value by index: " "value-addr=%p, index=%" PRIu64, @@ -351,7 +343,6 @@ int bt_attributes_freeze(struct bt_value *attr_obj) } bt_value_freeze(obj); - BT_PUT(obj); } end: diff --git a/lib/ctf-ir/clock-class.c b/lib/ctf-ir/clock-class.c index 40654e99..316364b9 100644 --- a/lib/ctf-ir/clock-class.c +++ b/lib/ctf-ir/clock-class.c @@ -790,7 +790,7 @@ end: return ret; } -struct bt_clock_class *bt_clock_value_get_class( +struct bt_clock_class *bt_clock_value_borrow_class( struct bt_clock_value *clock_value) { struct bt_clock_class *clock_class = NULL; @@ -800,7 +800,7 @@ struct bt_clock_class *bt_clock_value_get_class( goto end; } - clock_class = bt_get(clock_value->clock_class); + clock_class = clock_value->clock_class; end: return clock_class; diff --git a/lib/ctf-ir/event-class.c b/lib/ctf-ir/event-class.c index 7780095b..79cd123e 100644 --- a/lib/ctf-ir/event-class.c +++ b/lib/ctf-ir/event-class.c @@ -198,17 +198,19 @@ int bt_event_class_set_emf_uri(struct bt_event_class *event_class, emf_uri); } -struct bt_stream_class *bt_event_class_get_stream_class( +struct bt_stream_class *bt_event_class_borrow_stream_class( struct bt_event_class *event_class) { BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); - return bt_get(bt_event_class_borrow_stream_class(event_class)); + return BT_FROM_COMMON( + bt_event_class_common_borrow_stream_class(BT_TO_COMMON( + event_class))); } -struct bt_field_type *bt_event_class_get_payload_field_type( +struct bt_field_type *bt_event_class_borrow_payload_field_type( struct bt_event_class *event_class) { - return BT_FROM_COMMON(bt_event_class_common_get_payload_field_type( + return BT_FROM_COMMON(bt_event_class_common_borrow_payload_field_type( BT_TO_COMMON(event_class))); } @@ -219,10 +221,10 @@ int bt_event_class_set_payload_field_type(struct bt_event_class *event_class, BT_TO_COMMON(event_class), (void *) field_type); } -struct bt_field_type *bt_event_class_get_context_field_type( +struct bt_field_type *bt_event_class_borrow_context_field_type( struct bt_event_class *event_class) { - return BT_FROM_COMMON(bt_event_class_common_get_context_field_type( + return BT_FROM_COMMON(bt_event_class_common_borrow_context_field_type( BT_TO_COMMON(event_class))); } diff --git a/lib/ctf-ir/event.c b/lib/ctf-ir/event.c index a026cac9..7e1050ae 100644 --- a/lib/ctf-ir/event.c +++ b/lib/ctf-ir/event.c @@ -84,31 +84,31 @@ int bt_event_common_validate_types_for_create( trace = bt_stream_class_common_borrow_trace(stream_class); if (trace) { BT_LOGD_STR("Event class is part of a trace."); - packet_header_type = bt_trace_common_get_packet_header_field_type(trace); + packet_header_type = + bt_trace_common_borrow_packet_header_field_type(trace); trace_valid = trace->valid; BT_ASSERT(trace_valid); environment = trace->environment; } - packet_context_type = bt_stream_class_common_get_packet_context_field_type( - stream_class); - event_header_type = bt_stream_class_common_get_event_header_field_type( - stream_class); - stream_event_ctx_type = bt_stream_class_common_get_event_context_field_type( - stream_class); - event_context_type = bt_event_class_common_get_context_field_type(event_class); - event_payload_type = bt_event_class_common_get_payload_field_type(event_class); + packet_context_type = + bt_stream_class_common_borrow_packet_context_field_type( + stream_class); + event_header_type = + bt_stream_class_common_borrow_event_header_field_type( + stream_class); + stream_event_ctx_type = + bt_stream_class_common_borrow_event_context_field_type( + stream_class); + event_context_type = + bt_event_class_common_borrow_context_field_type(event_class); + event_payload_type = + bt_event_class_common_borrow_payload_field_type(event_class); ret = bt_validate_class_types(environment, packet_header_type, packet_context_type, event_header_type, stream_event_ctx_type, event_context_type, event_payload_type, trace_valid, stream_class->valid, event_class->valid, validation_output, validation_flags, copy_field_type_func); - BT_PUT(packet_header_type); - BT_PUT(packet_context_type); - BT_PUT(event_header_type); - BT_PUT(stream_event_ctx_type); - BT_PUT(event_context_type); - BT_PUT(event_payload_type); if (ret) { /* * This means something went wrong during the validation @@ -133,12 +133,6 @@ error: ret = -1; end: - BT_ASSERT(!packet_header_type); - BT_ASSERT(!packet_context_type); - BT_ASSERT(!event_header_type); - BT_ASSERT(!stream_event_ctx_type); - BT_ASSERT(!event_context_type); - BT_ASSERT(!event_payload_type); return ret; } @@ -494,7 +488,7 @@ struct bt_event *bt_event_create(struct bt_event_class *event_class) } event->clock_values = g_hash_table_new_full(g_direct_hash, - g_direct_equal, bt_put, bt_put); + g_direct_equal, NULL, bt_put); assert(event->clock_values); goto end; @@ -505,35 +499,23 @@ end: return event; } -struct bt_event_class *bt_event_get_class(struct bt_event *event) +struct bt_event_class *bt_event_borrow_class(struct bt_event *event) { BT_ASSERT_PRE_NON_NULL(event, "Event"); - return bt_get(bt_event_common_borrow_class(BT_TO_COMMON(event))); + return BT_FROM_COMMON( + bt_event_common_borrow_class(BT_TO_COMMON(event))); } -BT_HIDDEN struct bt_stream *bt_event_borrow_stream(struct bt_event *event) -{ - struct bt_stream *stream = NULL; - - BT_ASSERT(event); - - if (event->packet) { - stream = event->packet->stream; - } - - return stream; -} - -struct bt_stream *bt_event_get_stream(struct bt_event *event) { BT_ASSERT_PRE_NON_NULL(event, "Event"); - return bt_get(bt_event_borrow_stream(event)); + return event->packet ? event->packet->stream : NULL; } -struct bt_field *bt_event_get_payload(struct bt_event *event) +struct bt_field *bt_event_borrow_payload(struct bt_event *event) { - return BT_FROM_COMMON(bt_event_common_get_payload(BT_TO_COMMON(event))); + return BT_FROM_COMMON( + bt_event_common_borrow_payload(BT_TO_COMMON(event))); } int bt_event_set_payload(struct bt_event *event, struct bt_field *field) @@ -542,9 +524,10 @@ int bt_event_set_payload(struct bt_event *event, struct bt_field *field) (void *) field); } -struct bt_field *bt_event_get_header(struct bt_event *event) +struct bt_field *bt_event_borrow_header(struct bt_event *event) { - return BT_FROM_COMMON(bt_event_common_get_header(BT_TO_COMMON(event))); + return BT_FROM_COMMON( + bt_event_common_borrow_header(BT_TO_COMMON(event))); } int bt_event_set_header(struct bt_event *event, struct bt_field *field) @@ -552,9 +535,10 @@ int bt_event_set_header(struct bt_event *event, struct bt_field *field) return bt_event_common_set_header(BT_TO_COMMON(event), (void *) field); } -struct bt_field *bt_event_get_context(struct bt_event *event) +struct bt_field *bt_event_borrow_context(struct bt_event *event) { - return BT_FROM_COMMON(bt_event_common_get_context(BT_TO_COMMON(event))); + return BT_FROM_COMMON( + bt_event_common_borrow_context(BT_TO_COMMON(event))); } int bt_event_set_context(struct bt_event *event, struct bt_field *field) @@ -562,10 +546,10 @@ int bt_event_set_context(struct bt_event *event, struct bt_field *field) return bt_event_common_set_context(BT_TO_COMMON(event), (void *) field); } -struct bt_field *bt_event_get_stream_event_context( +struct bt_field *bt_event_borrow_stream_event_context( struct bt_event *event) { - return BT_FROM_COMMON(bt_event_common_get_stream_event_context( + return BT_FROM_COMMON(bt_event_common_borrow_stream_event_context( BT_TO_COMMON(event))); } @@ -587,7 +571,7 @@ void bt_event_destroy(struct bt_object *obj) g_free(event); } -struct bt_clock_value *bt_event_get_clock_value( +struct bt_clock_value *bt_event_borrow_clock_value( struct bt_event *event, struct bt_clock_class *clock_class) { struct bt_clock_value *clock_value = NULL; @@ -606,8 +590,6 @@ struct bt_clock_value *bt_event_get_clock_value( goto end; } - bt_get(clock_value); - end: return clock_value; } @@ -623,7 +605,7 @@ int bt_event_set_clock_value(struct bt_event *event, BT_ASSERT_PRE_NON_NULL(event, "Event"); BT_ASSERT_PRE_NON_NULL(value, "Clock value"); BT_ASSERT_PRE_EVENT_COMMON_HOT(BT_TO_COMMON(event), "Event"); - clock_class = bt_clock_value_get_class(value); + clock_class = bt_clock_value_borrow_class(value); event_class = BT_FROM_COMMON(event->common.class); BT_ASSERT(event_class); stream_class = bt_event_class_borrow_stream_class(event_class); @@ -645,12 +627,10 @@ int bt_event_set_clock_value(struct bt_event *event, bt_event_class_common_get_id(event->common.class), clock_class, bt_clock_class_get_name(clock_class), value, value->value); - clock_class = NULL; - bt_put(clock_class); return 0; } -struct bt_packet *bt_event_get_packet(struct bt_event *event) +struct bt_packet *bt_event_borrow_packet(struct bt_event *event) { struct bt_packet *packet = NULL; @@ -663,7 +643,7 @@ struct bt_packet *bt_event_get_packet(struct bt_event *event) goto end; } - packet = bt_get(event->packet); + packet = event->packet; end: return packet; diff --git a/lib/ctf-ir/field-types.c b/lib/ctf-ir/field-types.c index deb9c0ed..084dc74d 100644 --- a/lib/ctf-ir/field-types.c +++ b/lib/ctf-ir/field-types.c @@ -796,7 +796,7 @@ int bt_field_type_common_structure_validate_recursive( for (i = 0; i < field_count; ++i) { const char *field_name; - ret = bt_field_type_common_structure_get_field_by_index(ft, + ret = bt_field_type_common_structure_borrow_field_by_index(ft, &field_name, &child_ft, i); BT_ASSERT(ret == 0); ret = bt_field_type_common_validate(child_ft); @@ -808,12 +808,9 @@ int bt_field_type_common_structure_validate_recursive( ft, child_ft, field_name, i); goto end; } - - BT_PUT(child_ft); } end: - BT_PUT(child_ft); return ret; } @@ -888,7 +885,7 @@ int bt_field_type_common_variant_validate_recursive( for (i = 0; i < field_count; ++i) { const char *field_name; - ret = bt_field_type_common_variant_get_field_by_index(ft, + ret = bt_field_type_common_variant_borrow_field_by_index(ft, &field_name, &child_ft, i); BT_ASSERT(ret == 0); ret = bt_field_type_common_validate(child_ft); @@ -902,12 +899,9 @@ int bt_field_type_common_variant_validate_recursive( field_name, i); goto end; } - - BT_PUT(child_ft); } end: - BT_PUT(child_ft); return ret; } @@ -1244,7 +1238,7 @@ int bt_field_type_integer_set_encoding(struct bt_field_type *ft, } BT_HIDDEN -struct bt_clock_class *bt_field_type_common_integer_get_mapped_clock_class( +struct bt_clock_class *bt_field_type_common_integer_borrow_mapped_clock_class( struct bt_field_type_common *ft) { struct bt_field_type_common_integer *int_ft = BT_FROM_COMMON(ft); @@ -1252,13 +1246,14 @@ struct bt_clock_class *bt_field_type_common_integer_get_mapped_clock_class( BT_ASSERT_PRE_NON_NULL(ft, "Field type"); BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft, BT_FIELD_TYPE_ID_INTEGER, "Field type"); - return bt_get(int_ft->mapped_clock_class); + return int_ft->mapped_clock_class; } -struct bt_clock_class *bt_field_type_integer_get_mapped_clock_class( +struct bt_clock_class *bt_field_type_integer_borrow_mapped_clock_class( struct bt_field_type *ft) { - return bt_field_type_common_integer_get_mapped_clock_class((void *) ft); + return bt_field_type_common_integer_borrow_mapped_clock_class( + (void *) ft); } BT_HIDDEN @@ -1711,20 +1706,21 @@ end: } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_enumeration_get_container_field_type( +struct bt_field_type_common * +bt_field_type_common_enumeration_borrow_container_field_type( struct bt_field_type_common *ft) { struct bt_field_type_common_enumeration *enum_ft = BT_FROM_COMMON(ft); BT_ASSERT_PRE_NON_NULL(ft, "Field type"); BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft, BT_FIELD_TYPE_ID_ENUM, "Field type"); - return bt_get(enum_ft->container_ft); + return BT_TO_COMMON(enum_ft->container_ft); } -struct bt_field_type *bt_field_type_enumeration_get_container_field_type( +struct bt_field_type *bt_field_type_enumeration_borrow_container_field_type( struct bt_field_type *ft) { - return (void *) bt_field_type_common_enumeration_get_container_field_type( + return (void *) bt_field_type_common_enumeration_borrow_container_field_type( (void *) ft); } @@ -2254,7 +2250,7 @@ int64_t bt_field_type_structure_get_field_count(struct bt_field_type *ft) } BT_HIDDEN -int bt_field_type_common_structure_get_field_by_index( +int bt_field_type_common_structure_borrow_field_by_index( struct bt_field_type_common *ft, const char **field_name, struct bt_field_type_common **field_type, uint64_t index) @@ -2273,7 +2269,6 @@ int bt_field_type_common_structure_get_field_by_index( if (field_type) { *field_type = field->type; - bt_get(field->type); } if (field_name) { @@ -2284,17 +2279,18 @@ int bt_field_type_common_structure_get_field_by_index( return 0; } -int bt_field_type_structure_get_field_by_index( +int bt_field_type_structure_borrow_field_by_index( struct bt_field_type *ft, const char **field_name, struct bt_field_type **field_type, uint64_t index) { - return bt_field_type_common_structure_get_field_by_index( + return bt_field_type_common_structure_borrow_field_by_index( (void *) ft, field_name, (void *) field_type, index); } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_structure_get_field_type_by_name( +struct bt_field_type_common * +bt_field_type_common_structure_borrow_field_type_by_name( struct bt_field_type_common *ft, const char *name) { size_t index; @@ -2325,16 +2321,15 @@ struct bt_field_type_common *bt_field_type_common_structure_get_field_type_by_na field = struct_ft->fields->pdata[index]; field_type = field->type; - bt_get(field_type); end: return field_type; } -struct bt_field_type *bt_field_type_structure_get_field_type_by_name( +struct bt_field_type *bt_field_type_structure_borrow_field_type_by_name( struct bt_field_type *ft, const char *name) { - return (void *) bt_field_type_common_structure_get_field_type_by_name( + return (void *) bt_field_type_common_structure_borrow_field_type_by_name( (void *) ft, name); } @@ -2377,7 +2372,8 @@ end: } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_tag_field_type( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_tag_field_type( struct bt_field_type_common *ft) { struct bt_field_type_common_variant *var_ft = BT_FROM_COMMON(ft); @@ -2393,16 +2389,16 @@ struct bt_field_type_common *bt_field_type_common_variant_get_tag_field_type( goto end; } - tag_ft = bt_get(var_ft->tag_ft); + tag_ft = BT_TO_COMMON(var_ft->tag_ft); end: return tag_ft; } -struct bt_field_type *bt_field_type_variant_get_tag_field_type( +struct bt_field_type *bt_field_type_variant_borrow_tag_field_type( struct bt_field_type *ft) { - return (void *) bt_field_type_common_variant_get_tag_field_type( + return (void *) bt_field_type_common_variant_borrow_tag_field_type( (void *) ft); } @@ -2579,7 +2575,8 @@ int bt_field_type_variant_add_field(struct bt_field_type *ft, } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_by_name( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_by_name( struct bt_field_type_common *ft, const char *field_name) { @@ -2611,22 +2608,22 @@ struct bt_field_type_common *bt_field_type_common_variant_get_field_type_by_name field = g_ptr_array_index(var_ft->fields, index); field_type = field->type; - bt_get(field_type); end: return field_type; } -struct bt_field_type *bt_field_type_variant_get_field_type_by_name( +struct bt_field_type *bt_field_type_variant_borrow_field_type_by_name( struct bt_field_type *ft, const char *field_name) { - return (void *) bt_field_type_common_variant_get_field_type_by_name( + return (void *) bt_field_type_common_variant_borrow_field_type_by_name( (void *) ft, field_name); } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_from_tag( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_from_tag( struct bt_field_type_common *ft, struct bt_field_common *tag_field, bt_field_common_create_func field_create_func) @@ -2657,7 +2654,7 @@ struct bt_field_type_common *bt_field_type_common_variant_get_field_type_from_ta goto end; } - field_type = bt_field_type_common_variant_get_field_type_by_name( + field_type = bt_field_type_common_variant_borrow_field_type_by_name( ft, enum_value); end: @@ -2665,11 +2662,11 @@ end: return field_type; } -struct bt_field_type *bt_field_type_variant_get_field_type_from_tag( +struct bt_field_type *bt_field_type_variant_borrow_field_type_from_tag( struct bt_field_type *ft, struct bt_field *tag_field) { - return (void *) bt_field_type_common_variant_get_field_type_from_tag( + return (void *) bt_field_type_common_variant_borrow_field_type_from_tag( (void *) ft, (void *) tag_field, (bt_field_common_create_func) bt_field_create); } @@ -2692,7 +2689,7 @@ int64_t bt_field_type_variant_get_field_count(struct bt_field_type *ft) } BT_HIDDEN -int bt_field_type_common_variant_get_field_by_index( +int bt_field_type_common_variant_borrow_field_by_index( struct bt_field_type_common *ft, const char **field_name, struct bt_field_type_common **field_type, uint64_t index) @@ -2711,7 +2708,6 @@ int bt_field_type_common_variant_get_field_by_index( if (field_type) { *field_type = field->type; - bt_get(field->type); } if (field_name) { @@ -2722,11 +2718,11 @@ int bt_field_type_common_variant_get_field_by_index( return 0; } -int bt_field_type_variant_get_field_by_index(struct bt_field_type *ft, +int bt_field_type_variant_borrow_field_by_index(struct bt_field_type *ft, const char **field_name, struct bt_field_type **field_type, uint64_t index) { - return bt_field_type_common_variant_get_field_by_index((void *) ft, + return bt_field_type_common_variant_borrow_field_by_index((void *) ft, field_name, (void *) field_type, index); } @@ -2771,7 +2767,8 @@ end: } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_array_get_element_field_type( +struct bt_field_type_common * +bt_field_type_common_array_borrow_element_field_type( struct bt_field_type_common *ft) { struct bt_field_type_common_array *array_ft = BT_FROM_COMMON(ft); @@ -2780,13 +2777,13 @@ struct bt_field_type_common *bt_field_type_common_array_get_element_field_type( BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft, BT_FIELD_TYPE_ID_ARRAY, "Field type"); BT_ASSERT(array_ft && array_ft->element_ft); - return bt_get(array_ft->element_ft); + return array_ft->element_ft; } -struct bt_field_type *bt_field_type_array_get_element_field_type( +struct bt_field_type *bt_field_type_array_borrow_element_field_type( struct bt_field_type *ft) { - return (void *) bt_field_type_common_array_get_element_field_type( + return (void *) bt_field_type_common_array_borrow_element_field_type( (void *) ft); } @@ -2889,7 +2886,7 @@ end: } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_sequence_get_element_field_type( +struct bt_field_type_common *bt_field_type_common_sequence_borrow_element_field_type( struct bt_field_type_common *ft) { struct bt_field_type_common_sequence *seq_ft = BT_FROM_COMMON(ft); @@ -2897,13 +2894,13 @@ struct bt_field_type_common *bt_field_type_common_sequence_get_element_field_typ BT_ASSERT_PRE_NON_NULL(ft, "Field type"); BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft, BT_FIELD_TYPE_ID_SEQUENCE, "Field type"); - return bt_get(seq_ft->element_ft); + return seq_ft->element_ft; } -struct bt_field_type *bt_field_type_sequence_get_element_field_type( +struct bt_field_type *bt_field_type_sequence_borrow_element_field_type( struct bt_field_type *ft) { - return (void *) bt_field_type_common_sequence_get_element_field_type( + return (void *) bt_field_type_common_sequence_borrow_element_field_type( (void *) ft); } @@ -3065,21 +3062,19 @@ int bt_field_type_common_get_alignment(struct bt_field_type_common *ft) case BT_FIELD_TYPE_ID_SEQUENCE: { struct bt_field_type_common *element_ft = - bt_field_type_common_sequence_get_element_field_type(ft); + bt_field_type_common_sequence_borrow_element_field_type(ft); BT_ASSERT(element_ft); ret = bt_field_type_common_get_alignment(element_ft); - bt_put(element_ft); break; } case BT_FIELD_TYPE_ID_ARRAY: { struct bt_field_type_common *element_ft = - bt_field_type_common_array_get_element_field_type(ft); + bt_field_type_common_array_borrow_element_field_type(ft); BT_ASSERT(element_ft); ret = bt_field_type_common_get_alignment(element_ft); - bt_put(element_ft); break; } case BT_FIELD_TYPE_ID_STRUCT: @@ -3094,13 +3089,12 @@ int bt_field_type_common_get_alignment(struct bt_field_type_common *ft) struct bt_field_type_common *field = NULL; int field_alignment; - ret = bt_field_type_common_structure_get_field_by_index( + ret = bt_field_type_common_structure_borrow_field_by_index( ft, NULL, &field, i); BT_ASSERT(ret == 0); BT_ASSERT(field); field_alignment = bt_field_type_common_get_alignment( field); - bt_put(field); if (field_alignment < 0) { ret = field_alignment; goto end; @@ -3377,7 +3371,8 @@ void _bt_field_type_freeze(struct bt_field_type *ft) } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_signed( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_signed( struct bt_field_type_common_variant *var_ft, int64_t tag_value) { @@ -3412,7 +3407,8 @@ end: } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_variant_get_field_type_unsigned( +struct bt_field_type_common * +bt_field_type_common_variant_borrow_field_type_unsigned( struct bt_field_type_common_variant *var_ft, uint64_t tag_value) { @@ -4351,7 +4347,7 @@ int64_t bt_field_type_common_get_field_count(struct bt_field_type_common *ft) } BT_HIDDEN -struct bt_field_type_common *bt_field_type_common_get_field_at_index( +struct bt_field_type_common *bt_field_type_common_borrow_field_at_index( struct bt_field_type_common *ft, int index) { struct bt_field_type_common *field_type = NULL; @@ -4359,7 +4355,7 @@ struct bt_field_type_common *bt_field_type_common_get_field_at_index( switch (ft->id) { case BT_FIELD_TYPE_ID_STRUCT: { - int ret = bt_field_type_common_structure_get_field_by_index( + int ret = bt_field_type_common_structure_borrow_field_by_index( ft, NULL, &field_type, index); if (ret) { field_type = NULL; @@ -4369,7 +4365,7 @@ struct bt_field_type_common *bt_field_type_common_get_field_at_index( } case BT_FIELD_TYPE_ID_VARIANT: { - int ret = bt_field_type_common_variant_get_field_by_index( + int ret = bt_field_type_common_variant_borrow_field_by_index( ft, NULL, &field_type, index); if (ret) { field_type = NULL; @@ -4378,10 +4374,12 @@ struct bt_field_type_common *bt_field_type_common_get_field_at_index( break; } case BT_FIELD_TYPE_ID_ARRAY: - field_type = bt_field_type_common_array_get_element_field_type(ft); + field_type = + bt_field_type_common_array_borrow_element_field_type(ft); break; case BT_FIELD_TYPE_ID_SEQUENCE: - field_type = bt_field_type_common_sequence_get_element_field_type(ft); + field_type = + bt_field_type_common_sequence_borrow_element_field_type(ft); break; default: break; @@ -4414,7 +4412,7 @@ int bt_field_type_common_get_field_index(struct bt_field_type_common *ft, } BT_HIDDEN -struct bt_field_path *bt_field_type_common_variant_get_tag_field_path( +struct bt_field_path *bt_field_type_common_variant_borrow_tag_field_path( struct bt_field_type_common *ft) { struct bt_field_type_common_variant *var_ft = BT_FROM_COMMON(ft); @@ -4422,17 +4420,17 @@ struct bt_field_path *bt_field_type_common_variant_get_tag_field_path( BT_ASSERT_PRE_NON_NULL(ft, "Field type"); BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft, BT_FIELD_TYPE_ID_VARIANT, "Field type"); - return bt_get(var_ft->tag_field_path); + return var_ft->tag_field_path; } -struct bt_field_path *bt_field_type_variant_get_tag_field_path( +struct bt_field_path *bt_field_type_variant_borrow_tag_field_path( struct bt_field_type *ft) { - return bt_field_type_common_variant_get_tag_field_path((void *) ft); + return bt_field_type_common_variant_borrow_tag_field_path((void *) ft); } BT_HIDDEN -struct bt_field_path *bt_field_type_common_sequence_get_length_field_path( +struct bt_field_path *bt_field_type_common_sequence_borrow_length_field_path( struct bt_field_type_common *ft) { struct bt_field_type_common_sequence *seq_ft = BT_FROM_COMMON(ft); @@ -4440,13 +4438,14 @@ struct bt_field_path *bt_field_type_common_sequence_get_length_field_path( BT_ASSERT_PRE_NON_NULL(ft, "Field type"); BT_ASSERT_PRE_FT_COMMON_HAS_ID(ft, BT_FIELD_TYPE_ID_SEQUENCE, "Field type"); - return bt_get(seq_ft->length_field_path); + return seq_ft->length_field_path; } -struct bt_field_path *bt_field_type_sequence_get_length_field_path( +struct bt_field_path *bt_field_type_sequence_borrow_length_field_path( struct bt_field_type *ft) { - return bt_field_type_common_sequence_get_length_field_path((void *) ft); + return bt_field_type_common_sequence_borrow_length_field_path( + (void *) ft); } BT_HIDDEN @@ -4466,7 +4465,7 @@ int bt_field_type_common_validate_single_clock_class( case BT_FIELD_TYPE_ID_INTEGER: { struct bt_clock_class *mapped_clock_class = - bt_field_type_common_integer_get_mapped_clock_class(ft); + bt_field_type_common_integer_borrow_mapped_clock_class(ft); if (!mapped_clock_class) { goto end; @@ -4474,7 +4473,7 @@ int bt_field_type_common_validate_single_clock_class( if (!*expected_clock_class) { /* Move reference to output parameter */ - *expected_clock_class = mapped_clock_class; + *expected_clock_class = bt_get(mapped_clock_class); mapped_clock_class = NULL; BT_LOGV("Setting expected clock class: " "expected-clock-class-addr=%p", @@ -4497,7 +4496,6 @@ int bt_field_type_common_validate_single_clock_class( } } - bt_put(mapped_clock_class); break; } case BT_FIELD_TYPE_ID_ENUM: @@ -4508,15 +4506,15 @@ int bt_field_type_common_validate_single_clock_class( switch (ft->id) { case BT_FIELD_TYPE_ID_ENUM: - sub_ft = bt_field_type_common_enumeration_get_container_field_type( + sub_ft = bt_field_type_common_enumeration_borrow_container_field_type( ft); break; case BT_FIELD_TYPE_ID_ARRAY: - sub_ft = bt_field_type_common_array_get_element_field_type( + sub_ft = bt_field_type_common_array_borrow_element_field_type( ft); break; case BT_FIELD_TYPE_ID_SEQUENCE: - sub_ft = bt_field_type_common_sequence_get_element_field_type( + sub_ft = bt_field_type_common_sequence_borrow_element_field_type( ft); break; default: @@ -4527,7 +4525,6 @@ int bt_field_type_common_validate_single_clock_class( BT_ASSERT(sub_ft); ret = bt_field_type_common_validate_single_clock_class(sub_ft, expected_clock_class); - bt_put(sub_ft); break; } case BT_FIELD_TYPE_ID_STRUCT: @@ -4540,12 +4537,11 @@ int bt_field_type_common_validate_single_clock_class( const char *name; struct bt_field_type_common *member_type; - ret = bt_field_type_common_structure_get_field_by_index( + ret = bt_field_type_common_structure_borrow_field_by_index( ft, &name, &member_type, i); BT_ASSERT(ret == 0); ret = bt_field_type_common_validate_single_clock_class( member_type, expected_clock_class); - bt_put(member_type); if (ret) { BT_LOGW("Structure field type's field's type " "is not recursively mapped to the " @@ -4567,12 +4563,11 @@ int bt_field_type_common_validate_single_clock_class( const char *name; struct bt_field_type_common *member_type; - ret = bt_field_type_common_variant_get_field_by_index( + ret = bt_field_type_common_variant_borrow_field_by_index( ft, &name, &member_type, i); BT_ASSERT(ret == 0); ret = bt_field_type_common_validate_single_clock_class( member_type, expected_clock_class); - bt_put(member_type); if (ret) { BT_LOGW("Variant field type's field's type " "is not recursively mapped to the " diff --git a/lib/ctf-ir/fields.c b/lib/ctf-ir/fields.c index b8f08cfa..bd5e1bda 100644 --- a/lib/ctf-ir/fields.c +++ b/lib/ctf-ir/fields.c @@ -191,9 +191,9 @@ end: return field; } -struct bt_field_type *bt_field_get_type(struct bt_field *field) +struct bt_field_type *bt_field_borrow_type(struct bt_field *field) { - return (void *) bt_field_common_get_type((void *) field); + return (void *) bt_field_common_borrow_type((void *) field); } enum bt_field_type_id bt_field_get_type_id(struct bt_field *field) @@ -250,9 +250,9 @@ int64_t bt_field_sequence_get_int_length(struct bt_field *field) return bt_field_common_sequence_get_int_length((void *) field); } -struct bt_field *bt_field_sequence_get_length(struct bt_field *field) +struct bt_field *bt_field_sequence_borrow_length(struct bt_field *field) { - return (void *) bt_field_common_sequence_get_length((void *) field); + return (void *) bt_field_common_sequence_borrow_length((void *) field); } int bt_field_sequence_set_length(struct bt_field *field, @@ -262,17 +262,17 @@ int bt_field_sequence_set_length(struct bt_field *field, (void *) length_field); } -struct bt_field *bt_field_structure_get_field_by_index( +struct bt_field *bt_field_structure_borrow_field_by_index( struct bt_field *field, uint64_t index) { - return (void *) bt_field_common_structure_get_field_by_index( + return (void *) bt_field_common_structure_borrow_field_by_index( (void *) field, index); } -struct bt_field *bt_field_structure_get_field_by_name( +struct bt_field *bt_field_structure_borrow_field_by_name( struct bt_field *field, const char *name) { - return (void *) bt_field_common_structure_get_field_by_name( + return (void *) bt_field_common_structure_borrow_field_by_name( (void *) field, name); } @@ -283,44 +283,45 @@ int bt_field_structure_set_field_by_name(struct bt_field_common *field, name, (void *) value); } -struct bt_field *bt_field_array_get_field( +struct bt_field *bt_field_array_borrow_field( struct bt_field *field, uint64_t index) { - return (void *) bt_field_common_array_get_field((void *) field, index, - (bt_field_common_create_func) bt_field_create); + return (void *) bt_field_common_array_borrow_field((void *) field, + index, (bt_field_common_create_func) bt_field_create); } -struct bt_field *bt_field_sequence_get_field( +struct bt_field *bt_field_sequence_borrow_field( struct bt_field *field, uint64_t index) { - return (void *) bt_field_common_sequence_get_field((void *) field, + return (void *) bt_field_common_sequence_borrow_field((void *) field, index, (bt_field_common_create_func) bt_field_create); } -struct bt_field *bt_field_variant_get_field(struct bt_field *field, +struct bt_field *bt_field_variant_borrow_field(struct bt_field *field, struct bt_field *tag_field) { - return (void *) bt_field_common_variant_get_field((void *) field, + return (void *) bt_field_common_variant_borrow_field((void *) field, (void *) tag_field, (bt_field_common_create_func) bt_field_create); } -struct bt_field *bt_field_variant_get_current_field( +struct bt_field *bt_field_variant_borrow_current_field( struct bt_field *variant_field) { - return (void *) bt_field_common_variant_get_current_field( + return (void *) bt_field_common_variant_borrow_current_field( (void *) variant_field); } -struct bt_field_common *bt_field_variant_get_tag( +struct bt_field_common *bt_field_variant_borrow_tag( struct bt_field_common *variant_field) { - return (void *) bt_field_common_variant_get_tag((void *) variant_field); + return (void *) bt_field_common_variant_borrow_tag( + (void *) variant_field); } -struct bt_field *bt_field_enumeration_get_container(struct bt_field *field) +struct bt_field *bt_field_enumeration_borrow_container(struct bt_field *field) { - return (void *) bt_field_common_enumeration_get_container( + return (void *) bt_field_common_enumeration_borrow_container( (void *) field, (bt_field_common_create_func) bt_field_create); } @@ -837,7 +838,7 @@ int bt_field_common_structure_validate_recursive(struct bt_field_common *field) int this_ret; const char *name; - this_ret = bt_field_type_common_structure_get_field_by_index( + this_ret = bt_field_type_common_structure_borrow_field_by_index( field->type, &name, NULL, i); BT_ASSERT(this_ret == 0); BT_ASSERT_PRE_MSG("Invalid structure field's field: " @@ -1245,7 +1246,7 @@ struct bt_field_common *bt_field_sequence_copy_recursive( goto error; } - src_length = bt_field_common_sequence_get_length(src); + src_length = bt_field_common_sequence_borrow_length(src); if (!src_length) { /* no length set yet: keep destination sequence empty */ goto end; @@ -1254,7 +1255,6 @@ struct bt_field_common *bt_field_sequence_copy_recursive( /* copy source length */ BT_LOGD_STR("Copying sequence field's length field."); dst_length = (void *) bt_field_copy((void *) src_length); - BT_PUT(src_length); if (!dst_length) { BT_LOGE_STR("Cannot copy sequence field's length field."); goto error; diff --git a/lib/ctf-ir/packet.c b/lib/ctf-ir/packet.c index 0004cffd..1bc5a089 100644 --- a/lib/ctf-ir/packet.c +++ b/lib/ctf-ir/packet.c @@ -42,17 +42,17 @@ #include #include -struct bt_stream *bt_packet_get_stream(struct bt_packet *packet) +struct bt_stream *bt_packet_borrow_stream(struct bt_packet *packet) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); - return bt_get(packet->stream); + return packet->stream; } -struct bt_field *bt_packet_get_header( +struct bt_field *bt_packet_borrow_header( struct bt_packet *packet) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); - return bt_get(packet->header); + return packet->header; } BT_ASSERT_PRE_FUNC @@ -104,10 +104,10 @@ int bt_packet_set_header(struct bt_packet *packet, return 0; } -struct bt_field *bt_packet_get_context(struct bt_packet *packet) +struct bt_field *bt_packet_borrow_context(struct bt_packet *packet) { BT_ASSERT_PRE_NON_NULL(packet, "Packet"); - return bt_get(packet->context); + return packet->context; } int bt_packet_set_context(struct bt_packet *packet, @@ -171,9 +171,9 @@ struct bt_packet *bt_packet_create( stream->common.stream_class, bt_stream_class_common_get_name(stream->common.stream_class), bt_stream_class_common_get_id(stream->common.stream_class)); - stream_class = bt_stream_get_class(stream); + stream_class = bt_stream_borrow_class(stream); BT_ASSERT(stream_class); - trace = bt_stream_class_get_trace(stream_class); + trace = bt_stream_class_borrow_trace(stream_class); BT_ASSERT(trace); packet = g_new0(struct bt_packet, 1); if (!packet) { @@ -211,8 +211,5 @@ struct bt_packet *bt_packet_create( BT_LOGD("Created packet object: addr=%p", packet); end: - BT_PUT(trace); - BT_PUT(stream_class); - return packet; } diff --git a/lib/ctf-ir/resolve.c b/lib/ctf-ir/resolve.c index ce155230..3f164953 100644 --- a/lib/ctf-ir/resolve.c +++ b/lib/ctf-ir/resolve.c @@ -449,7 +449,7 @@ int ptokens_to_field_path(GList *ptokens, struct bt_field_path *field_path, g_array_append_val(field_path->indexes, child_index); /* Get child field type */ - child_type = bt_field_type_common_get_field_at_index(type, + child_type = bt_field_type_common_borrow_field_at_index(type, child_index); if (!child_type) { BT_LOGW("Cannot get child field type: " @@ -460,6 +460,7 @@ int ptokens_to_field_path(GList *ptokens, struct bt_field_path *field_path, } /* Move child type to current type */ + bt_get(child_type); BT_MOVE(type, child_type); } @@ -741,7 +742,7 @@ struct bt_field_type_common *field_path_to_field_type( g_array_index(field_path->indexes, int, i); /* Get child field type */ - child_type = bt_field_type_common_get_field_at_index(type, + child_type = bt_field_type_common_borrow_field_at_index(type, child_index); if (!child_type) { BT_LOGW("Cannot get field type: " @@ -750,6 +751,7 @@ struct bt_field_type_common *field_path_to_field_type( } /* Move child type to current type */ + bt_get(child_type); BT_MOVE(type, child_type); } @@ -1167,7 +1169,7 @@ int resolve_type(struct bt_field_type_common *type, struct resolve_context *ctx) for (f_index = 0; f_index < field_count; f_index++) { struct bt_field_type_common *child_type = - bt_field_type_common_get_field_at_index(type, + bt_field_type_common_borrow_field_at_index(type, f_index); if (!child_type) { @@ -1192,7 +1194,6 @@ int resolve_type(struct bt_field_type_common *type, struct resolve_context *ctx) "index=%" PRId64 ", count=%" PRId64, type, child_type, f_index, field_count); ret = resolve_type(child_type, ctx); - BT_PUT(child_type); if (ret) { goto end; } diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index 92d09467..2bb8b290 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -147,9 +147,9 @@ error: return NULL; } -struct bt_trace *bt_stream_class_get_trace(struct bt_stream_class *stream_class) +struct bt_trace *bt_stream_class_borrow_trace(struct bt_stream_class *stream_class) { - return BT_FROM_COMMON(bt_stream_class_common_get_trace( + return BT_FROM_COMMON(bt_stream_class_common_borrow_trace( BT_TO_COMMON(stream_class))); } @@ -252,8 +252,7 @@ int bt_stream_class_common_add_event_class( event_class, bt_event_class_common_get_name(event_class), bt_event_class_common_get_id(event_class)); - - trace = bt_stream_class_common_get_trace(stream_class); + trace = bt_stream_class_common_borrow_trace(stream_class); if (stream_class->frozen) { /* @@ -341,20 +340,22 @@ int bt_stream_class_common_add_event_class( BT_ASSERT(trace->valid); BT_ASSERT(stream_class->valid); packet_header_type = - bt_trace_common_get_packet_header_field_type(trace); + bt_trace_common_borrow_packet_header_field_type(trace); packet_context_type = - bt_stream_class_common_get_packet_context_field_type( + bt_stream_class_common_borrow_packet_context_field_type( stream_class); event_header_type = - bt_stream_class_common_get_event_header_field_type( + bt_stream_class_common_borrow_event_header_field_type( stream_class); stream_event_ctx_type = - bt_stream_class_common_get_event_context_field_type( + bt_stream_class_common_borrow_event_context_field_type( stream_class); event_context_type = - bt_event_class_common_get_context_field_type(event_class); + bt_event_class_common_borrow_context_field_type( + event_class); event_payload_type = - bt_event_class_common_get_payload_field_type(event_class); + bt_event_class_common_borrow_payload_field_type( + event_class); ret = bt_validate_class_types( trace->environment, packet_header_type, packet_context_type, event_header_type, @@ -363,12 +364,6 @@ int bt_stream_class_common_add_event_class( stream_class->valid, event_class->valid, &validation_output, validation_flags, copy_field_type_func); - BT_PUT(packet_header_type); - BT_PUT(packet_context_type); - BT_PUT(event_header_type); - BT_PUT(stream_event_ctx_type); - BT_PUT(event_context_type); - BT_PUT(event_payload_type); if (ret) { /* @@ -458,15 +453,8 @@ int bt_stream_class_common_add_event_class( bt_event_class_common_get_id(event_class)); end: - BT_PUT(trace); bt_validation_output_put_types(&validation_output); bt_put(expected_clock_class); - BT_ASSERT(!packet_header_type); - BT_ASSERT(!packet_context_type); - BT_ASSERT(!event_header_type); - BT_ASSERT(!stream_event_ctx_type); - BT_ASSERT(!event_context_type); - BT_ASSERT(!event_payload_type); g_free(event_id); return ret; } @@ -521,24 +509,24 @@ int64_t bt_stream_class_get_event_class_count( BT_TO_COMMON(stream_class)); } -struct bt_event_class *bt_stream_class_get_event_class_by_index( +struct bt_event_class *bt_stream_class_borrow_event_class_by_index( struct bt_stream_class *stream_class, uint64_t index) { - return BT_FROM_COMMON(bt_stream_class_common_get_event_class_by_index( + return BT_FROM_COMMON(bt_stream_class_common_borrow_event_class_by_index( BT_TO_COMMON(stream_class), index)); } -struct bt_event_class *bt_stream_class_get_event_class_by_id( +struct bt_event_class *bt_stream_class_borrow_event_class_by_id( struct bt_stream_class *stream_class, uint64_t id) { - return BT_FROM_COMMON(bt_stream_class_common_get_event_class_by_id( + return BT_FROM_COMMON(bt_stream_class_common_borrow_event_class_by_id( BT_TO_COMMON(stream_class), id)); } -struct bt_field_type *bt_stream_class_get_packet_context_field_type( +struct bt_field_type *bt_stream_class_borrow_packet_context_field_type( struct bt_stream_class *stream_class) { - return BT_FROM_COMMON(bt_stream_class_common_get_packet_context_field_type( + return BT_FROM_COMMON(bt_stream_class_common_borrow_packet_context_field_type( BT_TO_COMMON(stream_class))); } @@ -550,10 +538,10 @@ int bt_stream_class_set_packet_context_field_type( BT_TO_COMMON(stream_class), (void *) packet_context_type); } -struct bt_field_type *bt_stream_class_get_event_header_field_type( +struct bt_field_type *bt_stream_class_borrow_event_header_field_type( struct bt_stream_class *stream_class) { - return BT_FROM_COMMON(bt_stream_class_common_get_event_header_field_type( + return BT_FROM_COMMON(bt_stream_class_common_borrow_event_header_field_type( BT_TO_COMMON(stream_class))); } @@ -565,10 +553,10 @@ int bt_stream_class_set_event_header_field_type( BT_TO_COMMON(stream_class), (void *) event_header_type); } -struct bt_field_type *bt_stream_class_get_event_context_field_type( +struct bt_field_type *bt_stream_class_borrow_event_context_field_type( struct bt_stream_class *stream_class) { - return BT_FROM_COMMON(bt_stream_class_common_get_event_context_field_type( + return BT_FROM_COMMON(bt_stream_class_common_borrow_event_context_field_type( BT_TO_COMMON(stream_class))); } diff --git a/lib/ctf-ir/stream.c b/lib/ctf-ir/stream.c index 828b2db8..2787230c 100644 --- a/lib/ctf-ir/stream.c +++ b/lib/ctf-ir/stream.c @@ -260,9 +260,9 @@ end: return stream; } -struct bt_stream_class *bt_stream_get_class(struct bt_stream *stream) +struct bt_stream_class *bt_stream_borrow_class(struct bt_stream *stream) { - return BT_FROM_COMMON(bt_stream_common_get_class(BT_TO_COMMON(stream))); + return BT_FROM_COMMON(bt_stream_common_borrow_class(BT_TO_COMMON(stream))); } const char *bt_stream_get_name(struct bt_stream *stream) diff --git a/lib/ctf-ir/trace.c b/lib/ctf-ir/trace.c index ff026011..77b8c67b 100644 --- a/lib/ctf-ir/trace.c +++ b/lib/ctf-ir/trace.c @@ -391,7 +391,7 @@ int bt_trace_common_set_environment_field(struct bt_trace_common *trace, * The object passed is frozen like all other attributes. */ struct bt_value *attribute = - bt_attributes_get_field_value_by_name( + bt_attributes_borrow_field_value_by_name( trace->environment, name); if (attribute) { @@ -399,7 +399,6 @@ int bt_trace_common_set_environment_field(struct bt_trace_common *trace, "trace-addr=%p, trace-name=\"%s\", " "env-name=\"%s\"", trace, bt_trace_common_get_name(trace), name); - BT_PUT(attribute); ret = -1; goto end; } @@ -524,17 +523,17 @@ bt_trace_get_environment_field_name_by_index(struct bt_trace *trace, BT_TO_COMMON(trace), index); } -struct bt_value *bt_trace_get_environment_field_value_by_index( +struct bt_value *bt_trace_borrow_environment_field_value_by_index( struct bt_trace *trace, uint64_t index) { - return bt_trace_common_get_environment_field_value_by_index( + return bt_trace_common_borrow_environment_field_value_by_index( BT_TO_COMMON(trace), index); } -struct bt_value *bt_trace_get_environment_field_value_by_name( +struct bt_value *bt_trace_borrow_environment_field_value_by_name( struct bt_trace *trace, const char *name) { - return bt_trace_common_get_environment_field_value_by_name( + return bt_trace_common_borrow_environment_field_value_by_name( BT_TO_COMMON(trace), name); } @@ -614,10 +613,10 @@ int64_t bt_trace_get_clock_class_count(struct bt_trace *trace) return bt_trace_common_get_clock_class_count(BT_TO_COMMON(trace)); } -struct bt_clock_class *bt_trace_get_clock_class_by_index( +struct bt_clock_class *bt_trace_borrow_clock_class_by_index( struct bt_trace *trace, uint64_t index) { - return bt_trace_common_get_clock_class_by_index( + return bt_trace_common_borrow_clock_class_by_index( BT_TO_COMMON(trace), index); } @@ -660,7 +659,7 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, * integer field type. Also it must be the first field of the * packet header field type. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_header_type, "magic"); if (field_type) { const char *field_name; @@ -687,7 +686,7 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, goto invalid; } - ret = bt_field_type_common_structure_get_field_by_index( + ret = bt_field_type_common_structure_borrow_field_by_index( packet_header_type, &field_name, NULL, 0); BT_ASSERT(ret == 0); @@ -697,15 +696,13 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, field_type, field_name); goto invalid; } - - BT_PUT(field_type); } /* * If there's a `uuid` field, it must be an array field type of * length 16 with an 8-bit unsigned integer element field type. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_header_type, "uuid"); if (field_type) { struct bt_field_type_common *elem_ft; @@ -726,7 +723,7 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, goto invalid; } - elem_ft = bt_field_type_common_array_get_element_field_type(field_type); + elem_ft = bt_field_type_common_array_borrow_element_field_type(field_type); BT_ASSERT(elem_ft); if (elem_ft->id != BT_FIELD_TYPE_ID_INTEGER) { @@ -734,14 +731,12 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, "elem-ft-addr=%p, elem-ft-id=%s", elem_ft, bt_common_field_type_id_string(elem_ft->id)); - bt_put(elem_ft); goto invalid; } if (bt_field_type_common_integer_is_signed(elem_ft)) { BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an unsigned integer field type: " "elem-ft-addr=%p", elem_ft); - bt_put(elem_ft); goto invalid; } @@ -750,19 +745,15 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, "elem-ft-addr=%p, elem-ft-size=%u", elem_ft, bt_field_type_common_integer_get_size(elem_ft)); - bt_put(elem_ft); goto invalid; } - - bt_put(elem_ft); - BT_PUT(field_type); } /* * The `stream_id` field must exist if there's more than one * stream classes in the trace. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_header_type, "stream_id"); if (!field_type && trace->stream_classes->len >= 1) { @@ -789,15 +780,13 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, "stream-id-ft-addr=%p", field_type); goto invalid; } - - BT_PUT(field_type); } /* * If there's a `packet_seq_num` field, it must be an unsigned * integer field type. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_header_type, "packet_seq_num"); if (field_type) { if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) { @@ -813,8 +802,6 @@ bool packet_header_field_type_is_valid(struct bt_trace_common *trace, "packet-seq-num-ft-addr=%p", field_type); goto invalid; } - - BT_PUT(field_type); } goto end; @@ -823,7 +810,6 @@ invalid: is_valid = false; end: - bt_put(field_type); return is_valid; } @@ -854,7 +840,7 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, * If there's a `packet_size` field, it must be an unsigned * integer field type. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_context_type, "packet_size"); if (field_type) { if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) { @@ -870,15 +856,13 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, "packet-size-ft-addr=%p", field_type); goto invalid; } - - BT_PUT(field_type); } /* * If there's a `content_size` field, it must be an unsigned * integer field type. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_context_type, "content_size"); if (field_type) { if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) { @@ -894,15 +878,13 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, "content-size-ft-addr=%p", field_type); goto invalid; } - - BT_PUT(field_type); } /* * If there's a `events_discarded` field, it must be an unsigned * integer field type. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_context_type, "events_discarded"); if (field_type) { if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) { @@ -918,8 +900,6 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, "events-discarded-ft-addr=%p", field_type); goto invalid; } - - BT_PUT(field_type); } /* @@ -928,7 +908,7 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, * trace, then we cannot automatically set the mapped clock * class of this field, so it must have a mapped clock class. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_context_type, "timestamp_begin"); if (field_type) { if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) { @@ -947,18 +927,15 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, if (check_ts_begin_end_mapped) { struct bt_clock_class *clock_class = - bt_field_type_common_integer_get_mapped_clock_class( + bt_field_type_common_integer_borrow_mapped_clock_class( field_type); - bt_put(clock_class); if (!clock_class) { BT_LOGW("Invalid packet context field type: `timestamp_begin` field must be mapped to a clock class: " "timestamp-begin-ft-addr=%p", field_type); goto invalid; } } - - BT_PUT(field_type); } /* @@ -967,7 +944,7 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, * trace, then we cannot automatically set the mapped clock * class of this field, so it must have a mapped clock class. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( packet_context_type, "timestamp_end"); if (field_type) { if (field_type->id != BT_FIELD_TYPE_ID_INTEGER) { @@ -986,18 +963,15 @@ bool packet_context_field_type_is_valid(struct bt_trace_common *trace, if (check_ts_begin_end_mapped) { struct bt_clock_class *clock_class = - bt_field_type_common_integer_get_mapped_clock_class( + bt_field_type_common_integer_borrow_mapped_clock_class( field_type); - bt_put(clock_class); if (!clock_class) { BT_LOGW("Invalid packet context field type: `timestamp_end` field must be mapped to a clock class: " "timestamp-end-ft-addr=%p", field_type); goto invalid; } } - - BT_PUT(field_type); } goto end; @@ -1006,7 +980,6 @@ invalid: is_valid = false; end: - bt_put(field_type); return is_valid; } @@ -1053,15 +1026,15 @@ bool event_header_field_type_is_valid(struct bt_trace_common *trace, * field type or an enumeration field type with an unsigned * integer container field type. */ - field_type = bt_field_type_common_structure_get_field_type_by_name( + field_type = bt_field_type_common_structure_borrow_field_type_by_name( event_header_type, "id"); if (field_type) { struct bt_field_type_common *int_ft; if (field_type->id == BT_FIELD_TYPE_ID_INTEGER) { - int_ft = bt_get(field_type); + int_ft = field_type; } else if (field_type->id == BT_FIELD_TYPE_ID_ENUM) { - int_ft = bt_field_type_common_enumeration_get_container_field_type( + int_ft = bt_field_type_common_enumeration_borrow_container_field_type( field_type); } else { BT_LOGW("Invalid event header field type: `id` field must be an integer or enumeration field type: " @@ -1077,9 +1050,6 @@ bool event_header_field_type_is_valid(struct bt_trace_common *trace, "id-ft-addr=%p", int_ft); goto invalid; } - - bt_put(int_ft); - BT_PUT(field_type); } goto end; @@ -1088,7 +1058,6 @@ invalid: is_valid = false; end: - bt_put(field_type); return is_valid; } @@ -1172,7 +1141,7 @@ int bt_trace_common_add_stream_class(struct bt_trace_common *trace, stream_class, bt_stream_class_common_get_name(stream_class), bt_stream_class_common_get_id(stream_class)); - current_parent_trace = bt_stream_class_common_get_trace(stream_class); + current_parent_trace = bt_stream_class_common_borrow_trace(stream_class); if (current_parent_trace) { /* Stream class is already associated to a trace, abort. */ BT_LOGW("Invalid parameter: stream class is already part of a trace: " @@ -1249,13 +1218,13 @@ int bt_trace_common_add_stream_class(struct bt_trace_common *trace, * class of this stream class can be validated individually. */ packet_header_type = - bt_trace_common_get_packet_header_field_type(trace); + bt_trace_common_borrow_packet_header_field_type(trace); packet_context_type = - bt_stream_class_common_get_packet_context_field_type(stream_class); + bt_stream_class_common_borrow_packet_context_field_type(stream_class); event_header_type = - bt_stream_class_common_get_event_header_field_type(stream_class); + bt_stream_class_common_borrow_event_header_field_type(stream_class); stream_event_ctx_type = - bt_stream_class_common_get_event_context_field_type(stream_class); + bt_stream_class_common_borrow_event_context_field_type(stream_class); BT_LOGD("Validating trace and stream class field types."); ret = bt_validate_class_types(trace->environment, @@ -1263,10 +1232,6 @@ int bt_trace_common_add_stream_class(struct bt_trace_common *trace, stream_event_ctx_type, NULL, NULL, trace->valid, stream_class->valid, 1, &trace_sc_validation_output, trace_sc_validation_flags, copy_field_type_func); - BT_PUT(packet_header_type); - BT_PUT(packet_context_type); - BT_PUT(event_header_type); - BT_PUT(stream_event_ctx_type); if (ret) { /* @@ -1302,15 +1267,17 @@ int bt_trace_common_add_stream_class(struct bt_trace_common *trace, /* Validate each event class individually */ for (i = 0; i < event_class_count; i++) { struct bt_event_class_common *event_class = - bt_stream_class_common_get_event_class_by_index( + bt_stream_class_common_borrow_event_class_by_index( stream_class, i); struct bt_field_type_common *event_context_type = NULL; struct bt_field_type_common *event_payload_type = NULL; event_context_type = - bt_event_class_common_get_context_field_type(event_class); + bt_event_class_common_borrow_context_field_type( + event_class); event_payload_type = - bt_event_class_common_get_payload_field_type(event_class); + bt_event_class_common_borrow_payload_field_type( + event_class); /* * It is important to use the field types returned by @@ -1329,9 +1296,6 @@ int bt_trace_common_add_stream_class(struct bt_trace_common *trace, event_context_type, event_payload_type, 1, 1, event_class->valid, &ec_validation_outputs[i], ec_validation_flags, copy_field_type_func); - BT_PUT(event_context_type); - BT_PUT(event_payload_type); - BT_PUT(event_class); if (ret) { BT_LOGE("Failed to validate event class field types: " @@ -1452,13 +1416,12 @@ int bt_trace_common_add_stream_class(struct bt_trace_common *trace, for (i = 0; i < event_class_count; i++) { struct bt_event_class_common *event_class = - bt_stream_class_common_get_event_class_by_index( + bt_stream_class_common_borrow_event_class_by_index( stream_class, i); bt_validation_replace_types(NULL, NULL, event_class, &ec_validation_outputs[i], ec_validation_flags); event_class->valid = 1; - BT_PUT(event_class); /* * Put what was not moved in @@ -1503,12 +1466,7 @@ end: g_free(ec_validation_outputs); bt_validation_output_put_types(&trace_sc_validation_output); - bt_put(current_parent_trace); bt_put(expected_clock_class); - BT_ASSERT(!packet_header_type); - BT_ASSERT(!packet_context_type); - BT_ASSERT(!event_header_type); - BT_ASSERT(!stream_event_ctx_type); return ret; } @@ -1550,11 +1508,10 @@ int64_t bt_trace_get_stream_count(struct bt_trace *trace) return bt_trace_common_get_stream_count(BT_TO_COMMON(trace)); } -struct bt_stream *bt_trace_get_stream_by_index( - struct bt_trace *trace, - uint64_t index) +struct bt_stream *bt_trace_borrow_stream_by_index( + struct bt_trace *trace, uint64_t index) { - return BT_FROM_COMMON(bt_trace_common_get_stream_by_index( + return BT_FROM_COMMON(bt_trace_common_borrow_stream_by_index( BT_TO_COMMON(trace), index)); } @@ -1563,25 +1520,25 @@ int64_t bt_trace_get_stream_class_count(struct bt_trace *trace) return bt_trace_common_get_stream_class_count(BT_TO_COMMON(trace)); } -struct bt_stream_class *bt_trace_get_stream_class_by_index( +struct bt_stream_class *bt_trace_borrow_stream_class_by_index( struct bt_trace *trace, uint64_t index) { - return BT_FROM_COMMON(bt_trace_common_get_stream_class_by_index( + return BT_FROM_COMMON(bt_trace_common_borrow_stream_class_by_index( BT_TO_COMMON(trace), index)); } -struct bt_stream_class *bt_trace_get_stream_class_by_id( +struct bt_stream_class *bt_trace_borrow_stream_class_by_id( struct bt_trace *trace, uint64_t id) { return BT_FROM_COMMON( - bt_trace_common_get_stream_class_by_id( + bt_trace_common_borrow_stream_class_by_id( BT_TO_COMMON(trace), id)); } -struct bt_clock_class *bt_trace_get_clock_class_by_name( +struct bt_clock_class *bt_trace_borrow_clock_class_by_name( struct bt_trace *trace, const char *name) { - return bt_trace_common_get_clock_class_by_name(BT_TO_COMMON(trace), + return bt_trace_common_borrow_clock_class_by_name(BT_TO_COMMON(trace), name); } @@ -1660,10 +1617,10 @@ int bt_trace_set_native_byte_order(struct bt_trace *trace, byte_order, true); } -struct bt_field_type *bt_trace_get_packet_header_field_type( +struct bt_field_type *bt_trace_borrow_packet_header_field_type( struct bt_trace *trace) { - return BT_FROM_COMMON(bt_trace_common_get_packet_header_field_type( + return BT_FROM_COMMON(bt_trace_common_borrow_packet_header_field_type( BT_TO_COMMON(trace))); } diff --git a/lib/ctf-ir/validation.c b/lib/ctf-ir/validation.c index a17ef4af..b4e889cb 100644 --- a/lib/ctf-ir/validation.c +++ b/lib/ctf-ir/validation.c @@ -242,11 +242,11 @@ int field_type_contains_sequence_or_variant_ft(struct bt_field_type_common *type for (i = 0; i < field_count; ++i) { struct bt_field_type_common *child_type = - bt_field_type_common_get_field_at_index(type, i); + bt_field_type_common_borrow_field_at_index( + type, i); ret = field_type_contains_sequence_or_variant_ft( child_type); - BT_PUT(child_type); if (ret != 0) { goto end; } diff --git a/lib/ctf-writer/event-class.c b/lib/ctf-writer/event-class.c index ca49d979..057fc12a 100644 --- a/lib/ctf-writer/event-class.c +++ b/lib/ctf-writer/event-class.c @@ -133,7 +133,7 @@ struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class( struct bt_ctf_field_type *bt_ctf_event_class_get_payload_field_type( struct bt_ctf_event_class *event_class) { - return BT_FROM_COMMON(bt_event_class_common_get_payload_field_type( + return bt_get(bt_event_class_common_borrow_payload_field_type( BT_TO_COMMON(event_class))); } @@ -148,7 +148,7 @@ int bt_ctf_event_class_set_payload_field_type( struct bt_ctf_field_type *bt_ctf_event_class_get_context_field_type( struct bt_ctf_event_class *event_class) { - return BT_FROM_COMMON(bt_event_class_common_get_context_field_type( + return bt_get(bt_event_class_common_borrow_context_field_type( BT_TO_COMMON(event_class))); } @@ -434,8 +434,9 @@ struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name( * No need to increment field_type's reference count since getting it * from the structure already does. */ - field_type = (void *) bt_field_type_common_structure_get_field_type_by_name( - event_class->common.payload_field_type, name); + field_type = bt_get( + bt_field_type_common_structure_borrow_field_type_by_name( + event_class->common.payload_field_type, name)); end: return field_type; diff --git a/lib/ctf-writer/event.c b/lib/ctf-writer/event.c index 3fff114f..86d64d16 100644 --- a/lib/ctf-writer/event.c +++ b/lib/ctf-writer/event.c @@ -157,7 +157,7 @@ struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, struct bt_ctf_field *bt_ctf_event_get_payload_field( struct bt_ctf_event *event) { - return (void *) bt_event_common_get_payload(BT_TO_COMMON(event)); + return bt_get(bt_event_common_borrow_payload(BT_TO_COMMON(event))); } int bt_ctf_event_set_payload_field(struct bt_ctf_event *event, @@ -168,7 +168,7 @@ int bt_ctf_event_set_payload_field(struct bt_ctf_event *event, struct bt_ctf_field *bt_ctf_event_get_header(struct bt_ctf_event *event) { - return BT_FROM_COMMON(bt_event_common_get_header(BT_TO_COMMON(event))); + return bt_get(bt_event_common_borrow_header(BT_TO_COMMON(event))); } int bt_ctf_event_set_header(struct bt_ctf_event *event, @@ -179,7 +179,7 @@ int bt_ctf_event_set_header(struct bt_ctf_event *event, struct bt_ctf_field *bt_ctf_event_get_context(struct bt_ctf_event *event) { - return BT_FROM_COMMON(bt_event_common_get_context(BT_TO_COMMON(event))); + return bt_get(bt_event_common_borrow_context(BT_TO_COMMON(event))); } int bt_ctf_event_set_context(struct bt_ctf_event *event, @@ -191,7 +191,7 @@ int bt_ctf_event_set_context(struct bt_ctf_event *event, struct bt_ctf_field *bt_ctf_event_get_stream_event_context( struct bt_ctf_event *event) { - return BT_FROM_COMMON(bt_event_common_get_stream_event_context( + return bt_get(bt_event_common_borrow_stream_event_context( BT_TO_COMMON(event))); } diff --git a/lib/ctf-writer/field-types.c b/lib/ctf-writer/field-types.c index 4990e2c2..f8d3ff29 100644 --- a/lib/ctf-writer/field-types.c +++ b/lib/ctf-writer/field-types.c @@ -283,7 +283,7 @@ int bt_ctf_field_type_enumeration_serialize_recursive( BT_LOGD("Serializing CTF writer enumeration field type's metadata: " "ft-addr=%p, metadata-context-addr=%p", type, context); container_type = - bt_field_type_common_enumeration_get_container_field_type(type); + bt_field_type_common_enumeration_borrow_container_field_type(type); BT_ASSERT(container_type); container_signed = bt_field_type_common_integer_is_signed( container_type); @@ -350,7 +350,6 @@ int bt_ctf_field_type_enumeration_serialize_recursive( } end: - bt_put(container_type); return ret; } @@ -677,8 +676,8 @@ int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type *ft, struct bt_ctf_clock_class *bt_ctf_field_type_integer_get_mapped_clock_class( struct bt_ctf_field_type *ft) { - return BT_FROM_COMMON( - bt_field_type_common_integer_get_mapped_clock_class((void *) ft)); + return bt_get(bt_field_type_common_integer_borrow_mapped_clock_class( + (void *) ft)); } int bt_ctf_field_type_integer_set_mapped_clock_class( @@ -755,8 +754,9 @@ end: struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_field_type( struct bt_ctf_field_type *ft) { - return (void *) bt_field_type_common_enumeration_get_container_field_type( - (void *) ft); + return bt_get( + bt_field_type_common_enumeration_borrow_container_field_type( + (void *) ft)); } int bt_ctf_field_type_enumeration_signed_add_mapping( @@ -881,15 +881,21 @@ int bt_ctf_field_type_structure_get_field_by_index( const char **field_name, struct bt_ctf_field_type **field_type, uint64_t index) { - return bt_field_type_common_structure_get_field_by_index( + int ret = bt_field_type_common_structure_borrow_field_by_index( (void *) ft, field_name, (void *) field_type, index); + + if (ret == 0 && field_type) { + bt_get(*field_type); + } + + return ret; } struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( struct bt_ctf_field_type *ft, const char *name) { - return (void *) bt_field_type_common_structure_get_field_type_by_name( - (void *) ft, name); + return bt_get(bt_field_type_common_structure_borrow_field_type_by_name( + (void *) ft, name)); } struct bt_ctf_field_type *bt_ctf_field_type_variant_create( @@ -935,8 +941,8 @@ end: struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_field_type( struct bt_ctf_field_type *ft) { - return (void *) bt_field_type_common_variant_get_tag_field_type( - (void *) ft); + return bt_get(bt_field_type_common_variant_borrow_tag_field_type( + (void *) ft)); } const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type *ft) @@ -962,17 +968,17 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( struct bt_ctf_field_type *ft, const char *field_name) { - return (void *) bt_field_type_common_variant_get_field_type_by_name( - (void *) ft, field_name); + return bt_get(bt_field_type_common_variant_borrow_field_type_by_name( + (void *) ft, field_name)); } struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_from_tag( struct bt_ctf_field_type *ft, struct bt_ctf_field *tag_field) { - return (void *) bt_field_type_common_variant_get_field_type_from_tag( + return bt_get(bt_field_type_common_variant_borrow_field_type_from_tag( (void *) ft, (void *) tag_field, - (bt_field_common_create_func) bt_field_create); + (bt_field_common_create_func) bt_field_create)); } int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type *ft) @@ -984,8 +990,14 @@ int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type *ft, const char **field_name, struct bt_ctf_field_type **field_type, uint64_t index) { - return bt_field_type_common_variant_get_field_by_index((void *) ft, - field_name, (void *) field_type, index); + int ret = bt_field_type_common_variant_borrow_field_by_index( + (void *) ft, field_name, (void *) field_type, index); + + if (ret == 0 && field_type) { + bt_get(*field_type); + } + + return ret; } struct bt_ctf_field_type *bt_ctf_field_type_array_create( @@ -1033,8 +1045,8 @@ end: struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_field_type( struct bt_ctf_field_type *ft) { - return (void *) bt_field_type_common_array_get_element_field_type( - (void *) ft); + return bt_get(bt_field_type_common_array_borrow_element_field_type( + (void *) ft)); } int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type *ft) @@ -1089,8 +1101,8 @@ end: struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_field_type( struct bt_ctf_field_type *ft) { - return (void *) bt_field_type_common_sequence_get_element_field_type( - (void *) ft); + return bt_get(bt_field_type_common_sequence_borrow_element_field_type( + (void *) ft)); } const char *bt_ctf_field_type_sequence_get_length_field_name( diff --git a/lib/ctf-writer/fields.c b/lib/ctf-writer/fields.c index f7032fcd..1a0526d2 100644 --- a/lib/ctf-writer/fields.c +++ b/lib/ctf-writer/fields.c @@ -324,7 +324,7 @@ int bt_ctf_field_structure_serialize_recursive(struct bt_field_common *field, pos->offset, member, i); if (!member) { - ret = bt_field_type_common_structure_get_field_by_index( + ret = bt_field_type_common_structure_borrow_field_by_index( field->type, &field_name, NULL, i); BT_ASSERT(ret == 0); BT_LOGW("Cannot serialize structure field's field: field is not set: " @@ -338,7 +338,7 @@ int bt_ctf_field_structure_serialize_recursive(struct bt_field_common *field, ret = bt_ctf_field_serialize_recursive((void *) member, pos, native_byte_order); if (ret) { - ret = bt_field_type_common_structure_get_field_by_index( + ret = bt_field_type_common_structure_borrow_field_by_index( field->type, &field_name, NULL, i); BT_ASSERT(ret == 0); BT_LOGW("Cannot serialize structure field's field: " @@ -502,7 +502,7 @@ end: struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field) { - return (void *) bt_field_common_get_type((void *) field); + return bt_get(bt_field_common_borrow_type((void *) field)); } enum bt_ctf_field_type_id bt_ctf_field_get_type_id(struct bt_ctf_field *field) @@ -516,7 +516,7 @@ enum bt_ctf_field_type_id bt_ctf_field_get_type_id(struct bt_ctf_field *field) struct bt_ctf_field *bt_ctf_field_sequence_get_length( struct bt_ctf_field *field) { - return (void *) bt_field_common_sequence_get_length((void *) field); + return bt_get(bt_field_common_sequence_borrow_length((void *) field)); } int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field, @@ -529,15 +529,15 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field, struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( struct bt_ctf_field *field, uint64_t index) { - return (void *) bt_field_common_structure_get_field_by_index( - (void *) field, index); + return bt_get(bt_field_common_structure_borrow_field_by_index( + (void *) field, index)); } struct bt_ctf_field *bt_ctf_field_structure_get_field_by_name( struct bt_ctf_field *field, const char *name) { - return (void *) bt_field_common_structure_get_field_by_name( - (void *) field, name); + return bt_get(bt_field_common_structure_borrow_field_by_name( + (void *) field, name)); } int bt_ctf_field_structure_set_field_by_name(struct bt_ctf_field *field, @@ -550,42 +550,44 @@ int bt_ctf_field_structure_set_field_by_name(struct bt_ctf_field *field, struct bt_ctf_field *bt_ctf_field_array_get_field( struct bt_ctf_field *field, uint64_t index) { - return (void *) bt_field_common_array_get_field((void *) field, index, - (bt_field_common_create_func) bt_ctf_field_create); + return bt_get(bt_field_common_array_borrow_field((void *) field, index, + (bt_field_common_create_func) bt_ctf_field_create)); } struct bt_ctf_field *bt_ctf_field_sequence_get_field( struct bt_ctf_field *field, uint64_t index) { - return (void *) bt_field_common_sequence_get_field((void *) field, - index, (bt_field_common_create_func) bt_ctf_field_create); + return bt_get(bt_field_common_sequence_borrow_field((void *) field, + index, (bt_field_common_create_func) bt_ctf_field_create)); } struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field, struct bt_ctf_field *tag_field) { - return (void *) bt_field_common_variant_get_field((void *) field, + return bt_get(bt_field_common_variant_borrow_field((void *) field, (void *) tag_field, - (bt_field_common_create_func) bt_ctf_field_create); + (bt_field_common_create_func) bt_ctf_field_create)); } struct bt_ctf_field *bt_ctf_field_variant_get_current_field( struct bt_ctf_field *variant_field) { - return (void *) bt_field_common_variant_get_current_field( - (void *) variant_field); + return bt_get(bt_field_common_variant_borrow_current_field( + (void *) variant_field)); } struct bt_ctf_field *bt_ctf_field_variant_get_tag( struct bt_ctf_field *variant_field) { - return (void *) bt_field_common_variant_get_tag((void *) variant_field); + return bt_get(bt_field_common_variant_borrow_tag( + (void *) variant_field)); } struct bt_ctf_field *bt_ctf_field_enumeration_get_container(struct bt_ctf_field *field) { - return (void *) bt_field_common_enumeration_get_container( - (void *) field, (bt_field_common_create_func) bt_ctf_field_create); + return bt_get(bt_field_common_enumeration_borrow_container( + (void *) field, + (bt_field_common_create_func) bt_ctf_field_create)); } int bt_ctf_field_integer_signed_get_value(struct bt_ctf_field *field, int64_t *value) diff --git a/lib/ctf-writer/stream-class.c b/lib/ctf-writer/stream-class.c index 80c2a54a..715b4e90 100644 --- a/lib/ctf-writer/stream-class.c +++ b/lib/ctf-writer/stream-class.c @@ -514,7 +514,7 @@ end: struct bt_ctf_trace *bt_ctf_stream_class_get_trace( struct bt_ctf_stream_class *stream_class) { - return BT_FROM_COMMON(bt_stream_class_common_get_trace( + return bt_get(bt_stream_class_common_borrow_trace( BT_TO_COMMON(stream_class))); } @@ -546,8 +546,8 @@ int bt_ctf_stream_class_set_id( struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type( struct bt_ctf_stream_class *stream_class) { - return BT_FROM_COMMON( - bt_stream_class_common_get_packet_context_field_type( + return bt_get( + bt_stream_class_common_borrow_packet_context_field_type( BT_TO_COMMON(stream_class))); } @@ -563,8 +563,8 @@ struct bt_ctf_field_type * bt_ctf_stream_class_get_event_header_type( struct bt_ctf_stream_class *stream_class) { - return BT_FROM_COMMON( - bt_stream_class_common_get_event_header_field_type( + return bt_get( + bt_stream_class_common_borrow_event_header_field_type( BT_TO_COMMON(stream_class))); } @@ -580,8 +580,8 @@ struct bt_ctf_field_type * bt_ctf_stream_class_get_event_context_type( struct bt_ctf_stream_class *stream_class) { - return BT_FROM_COMMON( - bt_stream_class_common_get_event_context_field_type( + return bt_get( + bt_stream_class_common_borrow_event_context_field_type( BT_TO_COMMON(stream_class))); } @@ -603,16 +603,16 @@ int64_t bt_ctf_stream_class_get_event_class_count( struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_index( struct bt_ctf_stream_class *stream_class, uint64_t index) { - return BT_FROM_COMMON( - bt_stream_class_common_get_event_class_by_index( + return bt_get( + bt_stream_class_common_borrow_event_class_by_index( BT_TO_COMMON(stream_class), index)); } struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id( struct bt_ctf_stream_class *stream_class, uint64_t id) { - return BT_FROM_COMMON( - bt_stream_class_common_get_event_class_by_id( + return bt_get( + bt_stream_class_common_borrow_event_class_by_id( BT_TO_COMMON(stream_class), id)); } diff --git a/lib/ctf-writer/stream.c b/lib/ctf-writer/stream.c index aa6a525c..ec269e17 100644 --- a/lib/ctf-writer/stream.c +++ b/lib/ctf-writer/stream.c @@ -1939,7 +1939,7 @@ int try_set_structure_field_integer(struct bt_ctf_field *structure, char *name, struct bt_ctf_stream_class *bt_ctf_stream_get_class( struct bt_ctf_stream *stream) { - return BT_FROM_COMMON(bt_stream_common_get_class(BT_TO_COMMON(stream))); + return bt_get(bt_stream_common_borrow_class(BT_TO_COMMON(stream))); } const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream) diff --git a/lib/ctf-writer/trace.c b/lib/ctf-writer/trace.c index 1e0a32e5..035f3b3c 100644 --- a/lib/ctf-writer/trace.c +++ b/lib/ctf-writer/trace.c @@ -122,15 +122,15 @@ bt_ctf_trace_get_environment_field_name_by_index(struct bt_ctf_trace *trace, struct bt_value *bt_ctf_trace_get_environment_field_value_by_index( struct bt_ctf_trace *trace, uint64_t index) { - return bt_trace_common_get_environment_field_value_by_index( - BT_TO_COMMON(trace), index); + return bt_get(bt_trace_common_borrow_environment_field_value_by_index( + BT_TO_COMMON(trace), index)); } struct bt_value *bt_ctf_trace_get_environment_field_value_by_name( struct bt_ctf_trace *trace, const char *name) { - return bt_trace_common_get_environment_field_value_by_name( - BT_TO_COMMON(trace), name); + return bt_get(bt_trace_common_borrow_environment_field_value_by_name( + BT_TO_COMMON(trace), name)); } int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace, @@ -148,8 +148,8 @@ int64_t bt_ctf_trace_get_clock_class_count(struct bt_ctf_trace *trace) struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_index( struct bt_ctf_trace *trace, uint64_t index) { - return (void *) bt_trace_common_get_clock_class_by_index( - BT_TO_COMMON(trace), index); + return bt_get(bt_trace_common_borrow_clock_class_by_index( + BT_TO_COMMON(trace), index)); } static @@ -267,7 +267,7 @@ int64_t bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace) struct bt_ctf_stream *bt_ctf_trace_get_stream_by_index( struct bt_ctf_trace *trace, uint64_t index) { - return BT_FROM_COMMON(bt_trace_common_get_stream_by_index( + return bt_get(bt_trace_common_borrow_stream_by_index( BT_TO_COMMON(trace), index)); } @@ -279,23 +279,22 @@ int64_t bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace) struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_index( struct bt_ctf_trace *trace, uint64_t index) { - return BT_FROM_COMMON(bt_trace_common_get_stream_class_by_index( + return bt_get(bt_trace_common_borrow_stream_class_by_index( BT_TO_COMMON(trace), index)); } struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id( struct bt_ctf_trace *trace, uint64_t id) { - return BT_FROM_COMMON( - bt_trace_common_get_stream_class_by_id( - BT_TO_COMMON(trace), id)); + return bt_get(bt_trace_common_borrow_stream_class_by_id( + BT_TO_COMMON(trace), id)); } struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_name( struct bt_ctf_trace *trace, const char *name) { - return BT_FROM_COMMON( - bt_trace_common_get_clock_class_by_name(BT_TO_COMMON(trace), + return bt_get( + bt_trace_common_borrow_clock_class_by_name(BT_TO_COMMON(trace), name)); } @@ -374,7 +373,7 @@ void append_env_metadata(struct bt_ctf_trace *trace, entry_name = bt_attributes_get_field_name( trace->common.environment, i); - env_field_value_obj = bt_attributes_get_field_value( + env_field_value_obj = bt_attributes_borrow_field_value( trace->common.environment, i); BT_ASSERT(entry_name); @@ -407,7 +406,7 @@ void append_env_metadata(struct bt_ctf_trace *trace, if (!escaped_str) { BT_LOGE("Cannot escape string: string=\"%s\"", str_value); - goto loop_next; + continue; } g_string_append_printf(context->string, @@ -416,11 +415,8 @@ void append_env_metadata(struct bt_ctf_trace *trace, break; } default: - goto loop_next; + continue; } - -loop_next: - BT_PUT(env_field_value_obj); } g_string_append(context->string, "};\n\n"); @@ -492,7 +488,7 @@ int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace, struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_field_type( struct bt_ctf_trace *trace) { - return BT_FROM_COMMON(bt_trace_common_get_packet_header_field_type( + return bt_get(bt_trace_common_borrow_packet_header_field_type( BT_TO_COMMON(trace))); } diff --git a/lib/graph/clock-class-priority-map.c b/lib/graph/clock-class-priority-map.c index 94a3ef0f..2d1dc520 100644 --- a/lib/graph/clock-class-priority-map.c +++ b/lib/graph/clock-class-priority-map.c @@ -103,7 +103,7 @@ int64_t bt_clock_class_priority_map_get_clock_class_count( return (int64_t) cc_prio_map->entries->len; } -struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_index( +struct bt_clock_class *bt_clock_class_priority_map_borrow_clock_class_by_index( struct bt_clock_class_priority_map *cc_prio_map, uint64_t index) { @@ -111,10 +111,10 @@ struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_index( BT_ASSERT_PRE(index < cc_prio_map->entries->len, "Index is out of bounds: index=%" PRIu64 ", count=%" PRIu64, index, cc_prio_map->entries->len); - return bt_get(g_ptr_array_index(cc_prio_map->entries, index)); + return g_ptr_array_index(cc_prio_map->entries, index); } -struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_name( +struct bt_clock_class *bt_clock_class_priority_map_borrow_clock_class_by_name( struct bt_clock_class_priority_map *cc_prio_map, const char *name) { @@ -133,7 +133,7 @@ struct bt_clock_class *bt_clock_class_priority_map_get_clock_class_by_name( BT_ASSERT(cur_cc_name); if (strcmp(cur_cc_name, name) == 0) { - clock_class = bt_get(cur_cc); + clock_class = cur_cc; goto end; } } @@ -176,11 +176,11 @@ struct clock_class_prio bt_clock_class_priority_map_current_highest_prio( } struct bt_clock_class * -bt_clock_class_priority_map_get_highest_priority_clock_class( +bt_clock_class_priority_map_borrow_highest_priority_clock_class( struct bt_clock_class_priority_map *cc_prio_map) { BT_ASSERT_PRE_NON_NULL(cc_prio_map, "Clock class priority map"); - return(bt_get(cc_prio_map->highest_prio_cc)); + return cc_prio_map->highest_prio_cc; } int bt_clock_class_priority_map_get_clock_class_priority( diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index 28ad724d..61b5298b 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -390,12 +390,11 @@ bt_private_connection_private_notification_iterator_set_user_data( return BT_NOTIFICATION_ITERATOR_STATUS_OK; } -struct bt_notification *bt_notification_iterator_get_notification( +struct bt_notification *bt_notification_iterator_borrow_notification( struct bt_notification_iterator *iterator) { BT_ASSERT_PRE_NON_NULL(iterator, "Notification iterator"); - return bt_get( - bt_notification_iterator_borrow_current_notification(iterator)); + return bt_notification_iterator_borrow_current_notification(iterator); } BT_ASSERT_PRE_FUNC diff --git a/lib/graph/notification/discarded-elements.c b/lib/graph/notification/discarded-elements.c index 3154fee3..08fa0cbf 100644 --- a/lib/graph/notification/discarded-elements.c +++ b/lib/graph/notification/discarded-elements.c @@ -101,7 +101,7 @@ end: BT_HIDDEN struct bt_clock_value * -bt_notification_discarded_elements_get_begin_clock_value( +bt_notification_discarded_elements_borrow_begin_clock_value( enum bt_notification_type type, struct bt_notification *notification) { @@ -111,12 +111,12 @@ bt_notification_discarded_elements_get_begin_clock_value( BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); - return bt_get(discarded_elems_notif->begin_clock_value); + return discarded_elems_notif->begin_clock_value; } BT_HIDDEN struct bt_clock_value * -bt_notification_discarded_elements_get_end_clock_value( +bt_notification_discarded_elements_borrow_end_clock_value( enum bt_notification_type type, struct bt_notification *notification) { @@ -126,7 +126,7 @@ bt_notification_discarded_elements_get_end_clock_value( BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); - return bt_get(discarded_elems_notif->end_clock_value); + return discarded_elems_notif->end_clock_value; } BT_HIDDEN @@ -144,7 +144,7 @@ int64_t bt_notification_discarded_elements_get_count( } BT_HIDDEN -struct bt_stream *bt_notification_discarded_elements_get_stream( +struct bt_stream *bt_notification_discarded_elements_borrow_stream( enum bt_notification_type type, struct bt_notification *notification) { @@ -154,5 +154,5 @@ struct bt_stream *bt_notification_discarded_elements_get_stream( BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type); discarded_elems_notif = container_of(notification, struct bt_notification_discarded_elements, parent); - return bt_get(discarded_elems_notif->stream); + return discarded_elems_notif->stream; } diff --git a/lib/graph/notification/discarded-events.c b/lib/graph/notification/discarded-events.c index 24794678..166ca8bd 100644 --- a/lib/graph/notification/discarded-events.c +++ b/lib/graph/notification/discarded-events.c @@ -26,18 +26,18 @@ #include struct bt_clock_value * -bt_notification_discarded_events_get_begin_clock_value( +bt_notification_discarded_events_borrow_begin_clock_value( struct bt_notification *notification) { - return bt_notification_discarded_elements_get_begin_clock_value( + return bt_notification_discarded_elements_borrow_begin_clock_value( BT_NOTIFICATION_TYPE_DISCARDED_EVENTS, notification); } struct bt_clock_value * -bt_notification_discarded_events_get_end_clock_value( +bt_notification_discarded_events_borrow_end_clock_value( struct bt_notification *notification) { - return bt_notification_discarded_elements_get_end_clock_value( + return bt_notification_discarded_elements_borrow_end_clock_value( BT_NOTIFICATION_TYPE_DISCARDED_EVENTS, notification); } @@ -48,9 +48,9 @@ int64_t bt_notification_discarded_events_get_count( BT_NOTIFICATION_TYPE_DISCARDED_EVENTS, notification); } -struct bt_stream *bt_notification_discarded_events_get_stream( +struct bt_stream *bt_notification_discarded_events_borrow_stream( struct bt_notification *notification) { - return bt_notification_discarded_elements_get_stream( + return bt_notification_discarded_elements_borrow_stream( BT_NOTIFICATION_TYPE_DISCARDED_EVENTS, notification); } diff --git a/lib/graph/notification/discarded-packets.c b/lib/graph/notification/discarded-packets.c index 5d9b0ec3..7cd85c13 100644 --- a/lib/graph/notification/discarded-packets.c +++ b/lib/graph/notification/discarded-packets.c @@ -26,18 +26,18 @@ #include struct bt_clock_value * -bt_notification_discarded_packets_get_begin_clock_value( +bt_notification_discarded_packets_borrow_begin_clock_value( struct bt_notification *notification) { - return bt_notification_discarded_elements_get_begin_clock_value( + return bt_notification_discarded_elements_borrow_begin_clock_value( BT_NOTIFICATION_TYPE_DISCARDED_PACKETS, notification); } struct bt_clock_value * -bt_notification_discarded_packets_get_end_clock_value( +bt_notification_discarded_packets_borrow_end_clock_value( struct bt_notification *notification) { - return bt_notification_discarded_elements_get_end_clock_value( + return bt_notification_discarded_elements_borrow_end_clock_value( BT_NOTIFICATION_TYPE_DISCARDED_PACKETS, notification); } @@ -48,9 +48,9 @@ int64_t bt_notification_discarded_packets_get_count( BT_NOTIFICATION_TYPE_DISCARDED_PACKETS, notification); } -struct bt_stream *bt_notification_discarded_packets_get_stream( +struct bt_stream *bt_notification_discarded_packets_borrow_stream( struct bt_notification *notification) { - return bt_notification_discarded_elements_get_stream( + return bt_notification_discarded_elements_borrow_stream( BT_NOTIFICATION_TYPE_DISCARDED_PACKETS, notification); } diff --git a/lib/graph/notification/event.c b/lib/graph/notification/event.c index 065df303..97186a4c 100644 --- a/lib/graph/notification/event.c +++ b/lib/graph/notification/event.c @@ -233,7 +233,7 @@ end: return ¬ification->parent; } -struct bt_event *bt_notification_event_get_event( +struct bt_event *bt_notification_event_borrow_event( struct bt_notification *notification) { struct bt_notification_event *event_notification; @@ -242,11 +242,11 @@ struct bt_event *bt_notification_event_get_event( BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); event_notification = container_of(notification, struct bt_notification_event, parent); - return bt_get(event_notification->event); + return event_notification->event; } extern struct bt_clock_class_priority_map * -bt_notification_event_get_clock_class_priority_map( +bt_notification_event_borrow_clock_class_priority_map( struct bt_notification *notification) { struct bt_notification_event *event_notification; @@ -255,5 +255,5 @@ bt_notification_event_get_clock_class_priority_map( BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, BT_NOTIFICATION_TYPE_EVENT); event_notification = container_of(notification, struct bt_notification_event, parent); - return bt_get(event_notification->cc_prio_map); + return event_notification->cc_prio_map; } diff --git a/lib/graph/notification/inactivity.c b/lib/graph/notification/inactivity.c index 0b5ec96e..b774d307 100644 --- a/lib/graph/notification/inactivity.c +++ b/lib/graph/notification/inactivity.c @@ -104,7 +104,7 @@ end: } extern struct bt_clock_class_priority_map * -bt_notification_inactivity_get_clock_class_priority_map( +bt_notification_inactivity_borrow_clock_class_priority_map( struct bt_notification *notification) { struct bt_notification_inactivity *inactivity_notification; @@ -114,10 +114,10 @@ bt_notification_inactivity_get_clock_class_priority_map( BT_NOTIFICATION_TYPE_INACTIVITY); inactivity_notification = container_of(notification, struct bt_notification_inactivity, parent); - return bt_get(inactivity_notification->cc_prio_map); + return inactivity_notification->cc_prio_map; } -struct bt_clock_value *bt_notification_inactivity_get_clock_value( +struct bt_clock_value *bt_notification_inactivity_borrow_clock_value( struct bt_notification *notification, struct bt_clock_class *clock_class) { @@ -129,8 +129,8 @@ struct bt_clock_value *bt_notification_inactivity_get_clock_value( BT_NOTIFICATION_TYPE_INACTIVITY); inactivity_notification = container_of(notification, struct bt_notification_inactivity, parent); - return bt_get(g_hash_table_lookup( - inactivity_notification->clock_values, clock_class)); + return g_hash_table_lookup( + inactivity_notification->clock_values, clock_class); } BT_ASSERT_PRE_FUNC diff --git a/lib/graph/notification/packet.c b/lib/graph/notification/packet.c index 3a6b3237..fb590c3c 100644 --- a/lib/graph/notification/packet.c +++ b/lib/graph/notification/packet.c @@ -107,7 +107,7 @@ error: return NULL; } -struct bt_packet *bt_notification_packet_begin_get_packet( +struct bt_packet *bt_notification_packet_begin_borrow_packet( struct bt_notification *notification) { struct bt_notification_packet_begin *packet_begin; @@ -117,7 +117,7 @@ struct bt_packet *bt_notification_packet_begin_get_packet( BT_NOTIFICATION_TYPE_PACKET_BEGIN); packet_begin = container_of(notification, struct bt_notification_packet_begin, parent); - return bt_get(packet_begin->packet); + return packet_begin->packet; } struct bt_notification *bt_notification_packet_end_create( @@ -163,7 +163,7 @@ error: return NULL; } -struct bt_packet *bt_notification_packet_end_get_packet( +struct bt_packet *bt_notification_packet_end_borrow_packet( struct bt_notification *notification) { struct bt_notification_packet_end *packet_end; @@ -173,5 +173,5 @@ struct bt_packet *bt_notification_packet_end_get_packet( BT_NOTIFICATION_TYPE_PACKET_END); packet_end = container_of(notification, struct bt_notification_packet_end, parent); - return bt_get(packet_end->packet); + return packet_end->packet; } diff --git a/lib/graph/notification/stream.c b/lib/graph/notification/stream.c index 84ee483a..8f35e3c6 100644 --- a/lib/graph/notification/stream.c +++ b/lib/graph/notification/stream.c @@ -88,7 +88,7 @@ error: return NULL; } -struct bt_stream *bt_notification_stream_end_get_stream( +struct bt_stream *bt_notification_stream_end_borrow_stream( struct bt_notification *notification) { struct bt_notification_stream_end *stream_end; @@ -98,7 +98,7 @@ struct bt_stream *bt_notification_stream_end_get_stream( BT_NOTIFICATION_TYPE_STREAM_END); stream_end = container_of(notification, struct bt_notification_stream_end, parent); - return bt_get(stream_end->stream); + return stream_end->stream; } static @@ -154,7 +154,7 @@ error: return NULL; } -struct bt_stream *bt_notification_stream_begin_get_stream( +struct bt_stream *bt_notification_stream_begin_borrow_stream( struct bt_notification *notification) { struct bt_notification_stream_begin *stream_begin; @@ -164,5 +164,5 @@ struct bt_stream *bt_notification_stream_begin_get_stream( BT_NOTIFICATION_TYPE_STREAM_BEGIN); stream_begin = container_of(notification, struct bt_notification_stream_begin, parent); - return bt_get(stream_begin->stream); + return stream_begin->stream; } diff --git a/lib/values.c b/lib/values.c index 0fb6c2be..1d5adfa9 100644 --- a/lib/values.c +++ b/lib/values.c @@ -209,13 +209,13 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) for (i = 0; i < typed_array_obj->garray->len; ++i) { struct bt_value *element_obj_copy; - struct bt_value *element_obj = bt_value_array_get(array_obj, i); + struct bt_value *element_obj = bt_value_array_borrow( + array_obj, i); BT_ASSERT(element_obj); BT_LOGD("Copying array value's element: element-addr=%p, " "index=%d", element_obj, i); element_obj_copy = bt_value_copy(element_obj); - BT_PUT(element_obj); if (!element_obj_copy) { BT_LOGE("Cannot copy array value's element: " "array-addr=%p, index=%d", @@ -402,21 +402,16 @@ bt_bool bt_value_array_compare(const struct bt_value *object_a, struct bt_value *element_obj_a; struct bt_value *element_obj_b; - element_obj_a = bt_value_array_get(object_a, i); - element_obj_b = bt_value_array_get(object_b, i); + element_obj_a = bt_value_array_borrow(object_a, i); + element_obj_b = bt_value_array_borrow(object_b, i); if (!bt_value_compare(element_obj_a, element_obj_b)) { BT_LOGV("Array values's elements are different: " "value-a-addr=%p, value-b-addr=%p, index=%d", element_obj_a, element_obj_b, i); - BT_PUT(element_obj_a); - BT_PUT(element_obj_b); ret = BT_FALSE; goto end; } - - BT_PUT(element_obj_a); - BT_PUT(element_obj_b); } end: @@ -449,18 +444,15 @@ bt_bool bt_value_map_compare(const struct bt_value *object_a, struct bt_value *element_obj_b; const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key)); - element_obj_b = bt_value_map_get(object_b, key_str); + element_obj_b = bt_value_map_borrow(object_b, key_str); if (!bt_value_compare(element_obj_a, element_obj_b)) { BT_LOGV("Map values's elements are different: " "value-a-addr=%p, value-b-addr=%p, key=\"%s\"", element_obj_a, element_obj_b, key_str); - BT_PUT(element_obj_b); ret = BT_FALSE; goto end; } - - BT_PUT(element_obj_b); } end: @@ -854,7 +846,7 @@ bt_bool bt_value_array_is_empty(const struct bt_value *array_obj) return bt_value_array_size(array_obj) == 0; } -struct bt_value *bt_value_array_get(const struct bt_value *array_obj, +struct bt_value *bt_value_array_borrow(const struct bt_value *array_obj, uint64_t index) { struct bt_value_array *typed_array_obj = @@ -864,7 +856,7 @@ struct bt_value *bt_value_array_get(const struct bt_value *array_obj, BT_ASSERT_PRE_VALUE_IS_TYPE(array_obj, BT_VALUE_TYPE_ARRAY); BT_ASSERT_PRE_VALUE_INDEX_IN_BOUNDS(index, typed_array_obj->garray->len); - return bt_get(g_ptr_array_index(typed_array_obj->garray, index)); + return g_ptr_array_index(typed_array_obj->garray, index); } enum bt_value_status bt_value_array_append(struct bt_value *array_obj, @@ -989,14 +981,14 @@ bt_bool bt_value_map_is_empty(const struct bt_value *map_obj) return bt_value_map_size(map_obj) == 0; } -struct bt_value *bt_value_map_get(const struct bt_value *map_obj, +struct bt_value *bt_value_map_borrow(const struct bt_value *map_obj, const char *key) { BT_ASSERT_PRE_NON_NULL(map_obj, "Value object"); BT_ASSERT_PRE_NON_NULL(key, "Key"); BT_ASSERT_PRE_VALUE_IS_TYPE(map_obj, BT_VALUE_TYPE_MAP); - return bt_get(g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj)->ght, - GUINT_TO_POINTER(g_quark_from_string(key)))); + return g_hash_table_lookup(BT_VALUE_TO_MAP(map_obj)->ght, + GUINT_TO_POINTER(g_quark_from_string(key))); } bt_bool bt_value_map_has_key(const struct bt_value *map_obj, const char *key) -- 2.34.1