From 83509119a945fc77faff869daaf48627e1c4b3fa Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 30 Jul 2015 00:16:27 -0400 Subject: [PATCH] Unify reference counting using a common bt_object base MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/attributes.c | 29 +- formats/ctf/ir/clock.c | 31 +- formats/ctf/ir/event-fields.c | 112 ++-- formats/ctf/ir/event-types.c | 149 ++---- formats/ctf/ir/event.c | 218 +++----- formats/ctf/ir/stream-class.c | 97 ++-- formats/ctf/ir/stream.c | 153 ++---- formats/ctf/ir/trace.c | 90 ++-- formats/ctf/writer/writer.c | 33 +- include/Makefile.am | 6 +- include/babeltrace/ctf-ir/clock-internal.h | 4 +- .../babeltrace/ctf-ir/event-fields-internal.h | 4 +- include/babeltrace/ctf-ir/event-internal.h | 6 +- .../babeltrace/ctf-ir/event-types-internal.h | 4 +- .../babeltrace/ctf-ir/stream-class-internal.h | 4 +- include/babeltrace/ctf-ir/stream-internal.h | 6 +- include/babeltrace/ctf-ir/trace-internal.h | 4 +- .../babeltrace/ctf-writer/writer-internal.h | 4 +- .../common-internal.h => object-internal.h} | 29 +- include/babeltrace/ref-internal.h | 28 +- include/babeltrace/{ctf-ir => }/ref.h | 91 ++-- include/babeltrace/values.h | 70 +-- lib/Makefile.am | 3 +- lib/ref.c | 46 ++ lib/values.c | 111 ++-- tests/lib/test_bt_values.c | 146 +++--- tests/lib/test_ctf_writer.c | 482 +++++++++--------- 27 files changed, 856 insertions(+), 1104 deletions(-) rename include/babeltrace/{ctf-ir/common-internal.h => object-internal.h} (63%) rename include/babeltrace/{ctf-ir => }/ref.h (50%) create mode 100644 lib/ref.c diff --git a/formats/ctf/ir/attributes.c b/formats/ctf/ir/attributes.c index 409ae6bb..c6e8a232 100644 --- a/formats/ctf/ir/attributes.c +++ b/formats/ctf/ir/attributes.c @@ -29,7 +29,7 @@ #include #define BT_CTF_ATTR_NAME_INDEX 0 -#define BT_CTF_ATTR_VALUE_INDEX 1 +#define BT_CTF_ATTR_VALUE_INDEX 1 BT_HIDDEN struct bt_value *bt_ctf_attributes_create(void) @@ -54,7 +54,7 @@ struct bt_value *bt_ctf_attributes_create(void) BT_HIDDEN void bt_ctf_attributes_destroy(struct bt_value *attr_obj) { - bt_value_put(attr_obj); + bt_put(attr_obj); } BT_HIDDEN @@ -96,9 +96,8 @@ const char *bt_ctf_attributes_get_field_name(struct bt_value *attr_obj, } end: - BT_VALUE_PUT(attr_field_name_obj); - BT_VALUE_PUT(attr_field_obj); - + BT_PUT(attr_field_name_obj); + BT_PUT(attr_field_obj); return ret; } @@ -123,8 +122,7 @@ struct bt_value *bt_ctf_attributes_get_field_value(struct bt_value *attr_obj, BT_CTF_ATTR_VALUE_INDEX); end: - BT_VALUE_PUT(attr_field_obj); - + BT_PUT(attr_field_obj); return value_obj; } @@ -165,19 +163,19 @@ struct bt_value *bt_ctf_attributes_get_field_by_name( } if (!strcmp(field_name, name)) { - BT_VALUE_PUT(attr_field_name_obj); + BT_PUT(attr_field_name_obj); break; } - BT_VALUE_PUT(attr_field_name_obj); - BT_VALUE_PUT(value_obj); + BT_PUT(attr_field_name_obj); + BT_PUT(value_obj); } return value_obj; error: - BT_VALUE_PUT(attr_field_name_obj); - BT_VALUE_PUT(value_obj); + BT_PUT(attr_field_name_obj); + BT_PUT(value_obj); return value_obj; } @@ -219,7 +217,7 @@ int bt_ctf_attributes_set_field_value(struct bt_value *attr_obj, ret = bt_value_array_append(attr_obj, attr_field_obj); end: - BT_VALUE_PUT(attr_field_obj); + BT_PUT(attr_field_obj); return ret; } @@ -245,7 +243,7 @@ struct bt_value *bt_ctf_attributes_get_field_value_by_name( BT_CTF_ATTR_VALUE_INDEX); end: - BT_VALUE_PUT(attr_field_obj); + BT_PUT(attr_field_obj); return value_obj; } @@ -285,10 +283,9 @@ int bt_ctf_attributes_freeze(struct bt_value *attr_obj) } bt_value_freeze(obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); } end: - return ret; } diff --git a/formats/ctf/ir/clock.c b/formats/ctf/ir/clock.c index 22a5d747..723b860d 100644 --- a/formats/ctf/ir/clock.c +++ b/formats/ctf/ir/clock.c @@ -28,14 +28,14 @@ #include #include -#include -#include +#include #include +#include #include #include static -void bt_ctf_clock_destroy(struct bt_ref *ref); +void bt_ctf_clock_destroy(struct bt_object *obj); BT_HIDDEN struct bt_ctf_clock *_bt_ctf_clock_create(void) @@ -49,7 +49,7 @@ struct bt_ctf_clock *_bt_ctf_clock_create(void) clock->precision = 1; clock->frequency = 1000000000; - bt_ctf_base_init(clock, bt_ctf_clock_destroy); + bt_object_init(clock, bt_ctf_clock_destroy); end: return clock; } @@ -91,20 +91,19 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name) ret = bt_ctf_clock_set_name(clock, name); if (ret) { - goto error_destroy; + goto error; } ret = babeltrace_uuid_generate(clock->uuid); if (ret) { - goto error_destroy; + goto error; } clock->uuid_set = 1; return clock; -error_destroy: - bt_ctf_clock_destroy(&clock->base.ref_count); error: - return NULL; + BT_PUT(clock); + return clock; } const char *bt_ctf_clock_get_name(struct bt_ctf_clock *clock) @@ -347,12 +346,12 @@ end: void bt_ctf_clock_get(struct bt_ctf_clock *clock) { - bt_ctf_get(clock); + bt_get(clock); } void bt_ctf_clock_put(struct bt_ctf_clock *clock) { - bt_ctf_put(clock); + bt_put(clock); } BT_HIDDEN @@ -404,17 +403,11 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock, } static -void bt_ctf_clock_destroy(struct bt_ref *ref) +void bt_ctf_clock_destroy(struct bt_object *obj) { struct bt_ctf_clock *clock; - struct bt_ctf_base *base; - - if (!ref) { - return; - } - base = container_of(ref, struct bt_ctf_base, ref_count); - clock = container_of(base, struct bt_ctf_clock, base); + clock = container_of(obj, struct bt_ctf_clock, base); if (clock->name) { g_string_free(clock->name, TRUE); } diff --git a/formats/ctf/ir/event-fields.c b/formats/ctf/ir/event-fields.c index 2fb783c3..a3de98f6 100644 --- a/formats/ctf/ir/event-fields.c +++ b/formats/ctf/ir/event-fields.c @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include #include #define PACKET_LEN_INCREMENT (getpagesize() * 8 * CHAR_BIT) @@ -59,7 +59,7 @@ static struct bt_ctf_field *bt_ctf_field_string_create(struct bt_ctf_field_type *); static -void bt_ctf_field_destroy(struct bt_ref *); +void bt_ctf_field_destroy(struct bt_object *); static void bt_ctf_field_integer_destroy(struct bt_ctf_field *); static @@ -251,8 +251,8 @@ struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type) /* The type's declaration can't change after this point */ bt_ctf_field_type_freeze(type); - bt_ctf_field_type_get(type); - bt_ctf_base_init(field, bt_ctf_field_destroy); + bt_get(type); + bt_object_init(field, bt_ctf_field_destroy); field->type = type; error: return field; @@ -260,12 +260,12 @@ error: void bt_ctf_field_get(struct bt_ctf_field *field) { - bt_ctf_get(field); + bt_get(field); } void bt_ctf_field_put(struct bt_ctf_field *field) { - bt_ctf_put(field); + bt_put(field); } struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field) @@ -277,7 +277,7 @@ struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field) } ret = field->type; - bt_ctf_field_type_get(ret); + bt_get(ret); end: return ret; } @@ -299,7 +299,7 @@ struct bt_ctf_field *bt_ctf_field_sequence_get_length( sequence = container_of(field, struct bt_ctf_field_sequence, parent); ret = sequence->length; - bt_ctf_field_get(ret); + bt_get(ret); end: return ret; } @@ -337,7 +337,7 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field, sequence = container_of(field, struct bt_ctf_field_sequence, parent); if (sequence->elements) { g_ptr_array_free(sequence->elements, TRUE); - bt_ctf_field_put(sequence->length); + bt_put(sequence->length); } sequence->elements = g_ptr_array_sized_new((size_t)sequence_length); @@ -347,9 +347,9 @@ int bt_ctf_field_sequence_set_length(struct bt_ctf_field *field, } g_ptr_array_set_free_func(sequence->elements, - (GDestroyNotify)bt_ctf_field_put); - g_ptr_array_set_size(sequence->elements, (size_t)sequence_length); - bt_ctf_field_get(length_field); + (GDestroyNotify) bt_put); + g_ptr_array_set_size(sequence->elements, (size_t) sequence_length); + bt_get(length_field); sequence->length = length_field; end: return ret; @@ -392,10 +392,10 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field( structure->fields->pdata[index] = new_field; end: - bt_ctf_field_get(new_field); + bt_get(new_field); error: if (field_type) { - bt_ctf_field_type_put(field_type); + bt_put(field_type); } return new_field; } @@ -433,7 +433,7 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( ret = bt_ctf_field_type_structure_get_field(structure_type, &field_name, &field_type, index); - bt_ctf_field_type_put(structure_type); + bt_put(structure_type); if (ret) { goto error; } @@ -445,11 +445,9 @@ struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( structure->fields->pdata[index] = ret_field; end: - bt_ctf_field_get(ret_field); + bt_get(ret_field); error: - if (field_type) { - bt_ctf_field_type_put(field_type); - } + bt_put(field_type); return ret_field; } @@ -486,14 +484,14 @@ int bt_ctf_field_structure_set_field(struct bt_ctf_field *field, } if (structure->fields->pdata[index]) { - bt_ctf_field_put(structure->fields->pdata[index]); + bt_put(structure->fields->pdata[index]); } structure->fields->pdata[index] = value; - bt_ctf_field_get(value); + bt_get(value); end: if (expected_field_type) { - bt_ctf_field_type_put(expected_field_type); + bt_put(expected_field_type); } return ret; } @@ -525,10 +523,10 @@ struct bt_ctf_field *bt_ctf_field_array_get_field(struct bt_ctf_field *field, array->elements->pdata[(size_t)index] = new_field; end: if (field_type) { - bt_ctf_field_type_put(field_type); + bt_put(field_type); } if (new_field) { - bt_ctf_field_get(new_field); + bt_get(new_field); } return new_field; } @@ -551,19 +549,19 @@ struct bt_ctf_field *bt_ctf_field_sequence_get_field(struct bt_ctf_field *field, } field_type = bt_ctf_field_type_sequence_get_element_type(field->type); - if (sequence->elements->pdata[(size_t)index]) { - new_field = sequence->elements->pdata[(size_t)index]; + if (sequence->elements->pdata[(size_t) index]) { + new_field = sequence->elements->pdata[(size_t) index]; goto end; } new_field = bt_ctf_field_create(field_type); - sequence->elements->pdata[(size_t)index] = new_field; + sequence->elements->pdata[(size_t) index] = new_field; end: if (field_type) { - bt_ctf_field_type_put(field_type); + bt_put(field_type); } if (new_field) { - bt_ctf_field_get(new_field); + bt_get(new_field); } return new_field; } @@ -618,12 +616,12 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field, bt_ctf_field_enumeration_get_container(variant->tag); cur_tag_enum_integer = container_of(cur_tag_container, struct bt_ctf_field_integer, parent); - bt_ctf_field_put(cur_tag_container); + bt_put(cur_tag_container); cur_tag_value = cur_tag_enum_integer->definition.value._signed; if (cur_tag_value == tag_enum_value) { new_field = variant->payload; - bt_ctf_field_get(new_field); + bt_get(new_field); goto end; } } @@ -639,14 +637,14 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field, goto end; } - bt_ctf_field_put(variant->tag); - bt_ctf_field_put(variant->payload); - bt_ctf_field_get(new_field); - bt_ctf_field_get(tag_field); + bt_put(variant->tag); + bt_put(variant->payload); + bt_get(new_field); + bt_get(tag_field); variant->tag = tag_field; variant->payload = new_field; end: - bt_ctf_field_put(tag_enum); + bt_put(tag_enum); return new_field; } @@ -667,7 +665,7 @@ struct bt_ctf_field *bt_ctf_field_variant_get_current_field( if (variant->payload) { current_field = variant->payload; - bt_ctf_field_get(current_field); + bt_get(current_field); goto end; } @@ -697,7 +695,7 @@ struct bt_ctf_field *bt_ctf_field_enumeration_get_container( } container = enumeration->payload; - bt_ctf_field_get(container); + bt_get(container); end: return container; } @@ -750,9 +748,9 @@ const char *bt_ctf_field_enumeration_get_mapping_name( } error_put_container_type: - bt_ctf_field_type_put(container_type); + bt_put(container_type); error_put_container: - bt_ctf_field_put(container); + bt_put(container); end: return name; } @@ -1127,7 +1125,7 @@ struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field) copy->payload_set = field->payload_set; ret = field_copy_funcs[type_id](field, copy); if (ret) { - bt_ctf_field_put(copy); + bt_put(copy); copy = NULL; } end: @@ -1273,19 +1271,13 @@ struct bt_ctf_field *bt_ctf_field_string_create(struct bt_ctf_field_type *type) } static -void bt_ctf_field_destroy(struct bt_ref *ref) +void bt_ctf_field_destroy(struct bt_object *obj) { struct bt_ctf_field *field; - struct bt_ctf_base *base; struct bt_ctf_field_type *type; enum ctf_type_id type_id; - if (!ref) { - return; - } - - base = container_of(ref, struct bt_ctf_base, ref_count); - field = container_of(base, struct bt_ctf_field, base); + field = container_of(obj, struct bt_ctf_field, base); type = field->type; type_id = bt_ctf_field_type_get_type_id(type); if (type_id <= CTF_TYPE_UNKNOWN || @@ -1294,9 +1286,7 @@ void bt_ctf_field_destroy(struct bt_ref *ref) } field_destroy_funcs[type_id](field); - if (type) { - bt_ctf_field_type_put(type); - } + bt_put(type); } static @@ -1323,7 +1313,7 @@ void bt_ctf_field_enumeration_destroy(struct bt_ctf_field *field) enumeration = container_of(field, struct bt_ctf_field_enumeration, parent); - bt_ctf_field_put(enumeration->payload); + bt_put(enumeration->payload); g_free(enumeration); } @@ -1365,8 +1355,8 @@ void bt_ctf_field_variant_destroy(struct bt_ctf_field *field) } variant = container_of(field, struct bt_ctf_field_variant, parent); - bt_ctf_field_put(variant->tag); - bt_ctf_field_put(variant->payload); + bt_put(variant->tag); + bt_put(variant->payload); g_free(variant); } @@ -1397,7 +1387,7 @@ void bt_ctf_field_sequence_destroy(struct bt_ctf_field *field) if (sequence->elements) { g_ptr_array_free(sequence->elements, TRUE); } - bt_ctf_field_put(sequence->length); + bt_put(sequence->length); g_free(sequence); } @@ -1881,8 +1871,8 @@ int bt_ctf_field_string_serialize(struct bt_ctf_field *field, } } end: - bt_ctf_field_put(character); - bt_ctf_field_type_put(character_type); + bt_put(character); + bt_put(character_type); return ret; } @@ -2057,7 +2047,7 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src, /* copy source length */ dst_length = bt_ctf_field_copy(src_length); - bt_ctf_field_put(src_length); + bt_put(src_length); if (!dst_length) { ret = -1; @@ -2066,7 +2056,7 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src, /* this will initialize the destination sequence's internal array */ ret = bt_ctf_field_sequence_set_length(dst, dst_length); - bt_ctf_field_put(dst_length); + bt_put(dst_length); if (ret) { goto end; diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index 9d2bd39b..74fa3047 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -29,10 +29,11 @@ #include #include #include -#include -#include +#include #include #include +#include +#include #include #include #include @@ -54,7 +55,7 @@ struct range_overlap_query { }; static -void bt_ctf_field_type_destroy(struct bt_ref *); +void bt_ctf_field_type_destroy(struct bt_object *); static void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type *); static @@ -237,10 +238,7 @@ void destroy_enumeration_mapping(struct enumeration_mapping *mapping) static void destroy_structure_field(struct structure_field *field) { - if (field->type) { - bt_ctf_field_type_put(field->type); - } - + bt_put(field->type); g_free(field); } @@ -300,7 +298,7 @@ void bt_ctf_field_type_init(struct bt_ctf_field_type *type, int init_bo) assert(type && (type_id > CTF_TYPE_UNKNOWN) && (type_id < NR_CTF_TYPES)); - bt_ctf_base_init(type, bt_ctf_field_type_destroy); + bt_object_init(type, bt_ctf_field_type_destroy); type->freeze = type_freeze_funcs[type_id]; type->serialize = type_serialize_funcs[type_id]; @@ -336,7 +334,7 @@ int add_structure_field(GPtrArray *fields, goto end; } - bt_ctf_field_type_get(field_type); + bt_get(field_type); field->name = name_quark; field->type = field_type; g_hash_table_insert(field_name_to_index, @@ -348,18 +346,12 @@ end: } static -void bt_ctf_field_type_destroy(struct bt_ref *ref) +void bt_ctf_field_type_destroy(struct bt_object *obj) { struct bt_ctf_field_type *type; - struct bt_ctf_base *base; enum ctf_type_id type_id; - if (!ref) { - return; - } - - base = container_of(ref, struct bt_ctf_base, ref_count); - type = container_of(base, struct bt_ctf_field_type, base); + type = container_of(obj, struct bt_ctf_field_type, base); type_id = type->declaration->id; if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) { @@ -579,9 +571,7 @@ struct bt_ctf_clock *bt_ctf_field_type_integer_get_mapped_clock( integer = container_of(type, struct bt_ctf_field_type_integer, parent); clock = integer->mapped_clock; - if (clock) { - bt_ctf_clock_get(clock); - } + bt_get(clock); end: return clock; } @@ -599,14 +589,8 @@ int bt_ctf_field_type_integer_set_mapped_clock( } integer = container_of(type, struct bt_ctf_field_type_integer, parent); - if (integer->mapped_clock) { - bt_ctf_clock_put(integer->mapped_clock); - } - - if (clock) { - bt_ctf_clock_get(clock); - } - + bt_put(integer->mapped_clock); + bt_get(clock); integer->mapped_clock = clock; end: return ret; @@ -632,7 +616,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_create( enumeration->parent.declaration = &enumeration->declaration.p; enumeration->parent.declaration->id = CTF_TYPE_ENUM; - bt_ctf_field_type_get(integer_container_type); + bt_get(integer_container_type); enumeration->container = integer_container_type; enumeration->entries = g_ptr_array_new_with_free_func( (GDestroyNotify)destroy_enumeration_mapping); @@ -660,7 +644,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_get_container_type( enumeration_type = container_of(type, struct bt_ctf_field_type_enumeration, parent); container_type = enumeration_type->container; - bt_ctf_field_type_get(container_type); + bt_get(container_type); end: return container_type; } @@ -1225,7 +1209,7 @@ int bt_ctf_field_type_structure_get_field(struct bt_ctf_field_type *type, field = g_ptr_array_index(structure->fields, index); if (field_type) { *field_type = field->type; - bt_ctf_field_type_get(field->type); + bt_get(field->type); } if (field_name) { *field_name = g_quark_to_string(field->name); @@ -1262,7 +1246,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_structure_get_field_type_by_name( field = structure->fields->pdata[index]; field_type = field->type; - bt_ctf_field_type_get(field_type); + bt_get(field_type); end: return field_type; } @@ -1286,9 +1270,9 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_create( variant->tag_name = g_string_new(tag_name); variant->field_name_to_index = g_hash_table_new(NULL, NULL); variant->fields = g_ptr_array_new_with_free_func( - (GDestroyNotify)destroy_structure_field); + (GDestroyNotify) destroy_structure_field); if (enum_tag) { - bt_ctf_field_type_get(enum_tag); + bt_get(enum_tag); variant->tag = container_of(enum_tag, struct bt_ctf_field_type_enumeration, parent); } @@ -1317,7 +1301,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_tag_type( } tag_type = &variant->tag->parent; - bt_ctf_field_type_get(tag_type); + bt_get(tag_type); end: return tag_type; } @@ -1438,7 +1422,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type_by_name( field = g_ptr_array_index(variant->fields, index); field_type = field->type; - bt_ctf_field_type_get(field_type); + bt_get(field_type); end: return field_type; } @@ -1507,7 +1491,7 @@ int bt_ctf_field_type_variant_get_field(struct bt_ctf_field_type *type, field = g_ptr_array_index(variant->fields, index); if (field_type) { *field_type = field->type; - bt_ctf_field_type_get(field->type); + bt_get(field->type); } if (field_name) { *field_name = g_quark_to_string(field->name); @@ -1535,7 +1519,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_create( array->parent.declaration = &array->declaration.p; array->parent.declaration->id = CTF_TYPE_ARRAY; - bt_ctf_field_type_get(element_type); + bt_get(element_type); array->element_type = element_type; array->length = length; bt_ctf_field_type_init(&array->parent, FALSE); @@ -1556,7 +1540,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type( array = container_of(type, struct bt_ctf_field_type_array, parent); ret = array->element_type; - bt_ctf_field_type_get(ret); + bt_get(ret); end: return ret; } @@ -1595,7 +1579,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( sequence->parent.declaration = &sequence->declaration.p; sequence->parent.declaration->id = CTF_TYPE_SEQUENCE; - bt_ctf_field_type_get(element_type); + bt_get(element_type); sequence->element_type = element_type; sequence->length_field_name = g_string_new(length_field_name); bt_ctf_field_type_init(&sequence->parent, FALSE); @@ -1617,7 +1601,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type( sequence = container_of(type, struct bt_ctf_field_type_sequence, parent); ret = sequence->element_type; - bt_ctf_field_type_get(ret); + bt_get(ret); end: return ret; } @@ -1720,7 +1704,7 @@ int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type) } ret = bt_ctf_field_type_get_alignment(element); - bt_ctf_field_type_put(element); + bt_put(element); break; } case CTF_TYPE_ARRAY: @@ -1734,7 +1718,7 @@ int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type) } ret = bt_ctf_field_type_get_alignment(element); - bt_ctf_field_type_put(element); + bt_put(element); break; } case CTF_TYPE_STRUCT: @@ -1761,7 +1745,7 @@ int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type *type) assert(field); field_alignment = bt_ctf_field_type_get_alignment( field); - bt_ctf_field_type_put(field); + bt_put(field); if (field_alignment < 0) { ret = field_alignment; goto end; @@ -1924,12 +1908,12 @@ enum ctf_type_id bt_ctf_field_type_get_type_id( void bt_ctf_field_type_get(struct bt_ctf_field_type *type) { - bt_ctf_get(type); + bt_get(type); } void bt_ctf_field_type_put(struct bt_ctf_field_type *type) { - bt_ctf_put(type); + bt_put(type); } BT_HIDDEN @@ -2156,8 +2140,8 @@ int bt_ctf_field_type_structure_set_field_index(struct bt_ctf_field_type *type, goto end; } - bt_ctf_field_type_get(field); - bt_ctf_field_type_put(((struct structure_field *) + bt_get(field); + bt_put(((struct structure_field *) g_ptr_array_index(structure->fields, index))->type); ((struct structure_field *) structure->fields->pdata[index])->type = field; @@ -2282,9 +2266,9 @@ int bt_ctf_field_type_variant_set_tag(struct bt_ctf_field_type *type, variant = container_of(type, struct bt_ctf_field_type_variant, parent); - bt_ctf_field_type_get(tag); + bt_get(tag); if (variant->tag) { - bt_ctf_field_type_put(&variant->tag->parent); + bt_put(&variant->tag->parent); } variant->tag = container_of(tag, struct bt_ctf_field_type_enumeration, parent); @@ -2312,8 +2296,8 @@ int bt_ctf_field_type_variant_set_field_index(struct bt_ctf_field_type *type, goto end; } - bt_ctf_field_type_get(field); - bt_ctf_field_type_put(((struct structure_field *) + bt_get(field); + bt_put(((struct structure_field *) g_ptr_array_index(variant->fields, index))->type); ((struct structure_field *) variant->fields->pdata[index])->type = field; @@ -2331,9 +2315,7 @@ void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type *type) return; } - if (integer->mapped_clock) { - bt_ctf_clock_put(integer->mapped_clock); - } + bt_put(integer->mapped_clock); g_free(integer); } @@ -2348,7 +2330,7 @@ void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type *type) } g_ptr_array_free(enumeration->entries, TRUE); - bt_ctf_field_type_put(enumeration->container); + bt_put(enumeration->container); g_free(enumeration); } @@ -2393,7 +2375,7 @@ void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type *type) g_ptr_array_free(variant->fields, TRUE); g_hash_table_destroy(variant->field_name_to_index); g_string_free(variant->tag_name, TRUE); - bt_ctf_field_type_put(&variant->tag->parent); + bt_put(&variant->tag->parent); bt_ctf_field_path_destroy(variant->tag_path); g_free(variant); } @@ -2408,7 +2390,7 @@ void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type *type) return; } - bt_ctf_field_type_put(array->element_type); + bt_put(array->element_type); g_free(array); } @@ -2422,7 +2404,7 @@ void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type *type) return; } - bt_ctf_field_type_put(sequence->element_type); + bt_put(sequence->element_type); g_string_free(sequence->length_field_name, TRUE); bt_ctf_field_path_destroy(sequence->length_field_path); g_free(sequence); @@ -2675,7 +2657,7 @@ int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type *type, g_string_assign(context->field_name, ""); } error_put_container_type: - bt_ctf_field_type_put(container_type); + bt_put(container_type); end: return ret; } @@ -3017,7 +2999,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_integer_copy( parent); copy_integer->declaration = integer->declaration; if (integer->mapped_clock) { - bt_ctf_clock_get(integer->mapped_clock); + bt_get(integer->mapped_clock); copy_integer->mapped_clock = integer->mapped_clock; } end: @@ -3065,16 +3047,12 @@ struct bt_ctf_field_type *bt_ctf_field_type_enumeration_copy( copy_enumeration->declaration = enumeration->declaration; end: - if (copy_container) { - bt_ctf_field_type_put(copy_container); - } + bt_put(copy_container); return copy; error: - if (copy_container) { - bt_ctf_field_type_put(copy_container); - } - bt_ctf_field_type_put(copy); - return NULL; + bt_put(copy_container); + BT_PUT(copy); + return copy; } static @@ -3153,8 +3131,8 @@ struct bt_ctf_field_type *bt_ctf_field_type_structure_copy( end: return copy; error: - bt_ctf_field_type_put(copy); - return NULL; + BT_PUT(copy); + return copy; } static @@ -3222,18 +3200,12 @@ struct bt_ctf_field_type *bt_ctf_field_type_variant_copy( } } end: - if (copy_tag) { - bt_ctf_field_type_put(copy_tag); - } - + bt_put(copy_tag); return copy; error: - if (copy_tag) { - bt_ctf_field_type_put(copy_tag); - } - - bt_ctf_field_type_put(copy); - return NULL; + bt_put(copy_tag); + BT_PUT(copy); + return copy; } static @@ -3259,10 +3231,7 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_copy( parent); copy_array->declaration = array->declaration; end: - if (copy_element) { - bt_ctf_field_type_put(copy_element); - } - + bt_put(copy_element); return copy; } @@ -3298,16 +3267,10 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_copy( } } end: - if (copy_element) { - bt_ctf_field_type_put(copy_element); - } - + bt_put(copy_element); return copy; error: - if (copy) { - bt_ctf_field_type_put(copy); - copy = NULL; - } + BT_PUT(copy); goto end; } diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index 82499417..226251f7 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -36,15 +36,14 @@ #include #include #include -#include -#include +#include #include #include static -void bt_ctf_event_class_destroy(struct bt_ref *ref); +void bt_ctf_event_class_destroy(struct bt_object *obj); static -void bt_ctf_event_destroy(struct bt_ref *ref); +void bt_ctf_event_destroy(struct bt_object *obj); static int set_integer_field_value(struct bt_ctf_field *field, uint64_t value); @@ -63,7 +62,7 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) goto error; } - bt_ctf_base_init(event_class, bt_ctf_event_class_destroy); + bt_object_init(event_class, bt_ctf_event_class_destroy); event_class->fields = bt_ctf_field_type_structure_create(); if (!event_class->fields) { goto error; @@ -85,7 +84,7 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) goto error; } - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_string_create_init(name); if (!obj) { @@ -98,18 +97,14 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) goto error; } - BT_VALUE_PUT(obj); + BT_PUT(obj); return event_class; error: - if (event_class) { - bt_ctf_event_class_put(event_class); - } - - BT_VALUE_PUT(obj); - - return NULL; + BT_PUT(event_class); + BT_PUT(obj); + return event_class; } const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class) @@ -132,8 +127,7 @@ const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class) } end: - BT_VALUE_PUT(obj); - + BT_PUT(obj); return name; } @@ -164,8 +158,7 @@ int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class) } end: - BT_VALUE_PUT(obj); - + BT_PUT(obj); return ret; } @@ -201,8 +194,7 @@ int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, } end: - BT_VALUE_PUT(obj); - + BT_PUT(obj); return ret; } @@ -335,7 +327,7 @@ struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class( } stream_class = event_class->stream_class; - bt_ctf_stream_class_get(stream_class); + bt_get(stream_class); end: return stream_class; } @@ -349,7 +341,7 @@ struct bt_ctf_field_type *bt_ctf_event_class_get_payload_type( goto end; } - bt_ctf_field_type_get(event_class->fields); + bt_get(event_class->fields); payload = event_class->fields; end: return payload; @@ -366,8 +358,8 @@ int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class *event_class, goto end; } - bt_ctf_field_type_get(payload); - bt_ctf_field_type_put(event_class->fields); + bt_get(payload); + bt_put(event_class->fields); event_class->fields = payload; end: return ret; @@ -480,7 +472,7 @@ struct bt_ctf_field_type *bt_ctf_event_class_get_context_type( goto end; } - bt_ctf_field_type_get(event_class->context); + bt_get(event_class->context); context_type = event_class->context; end: return context_type; @@ -502,8 +494,8 @@ int bt_ctf_event_class_set_context_type( goto end; } - bt_ctf_field_type_get(context); - bt_ctf_field_type_put(event_class->context); + bt_get(context); + bt_put(event_class->context); event_class->context = context; end: return ret; @@ -512,12 +504,12 @@ end: void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class) { - bt_ctf_get(event_class); + bt_get(event_class); } void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class) { - bt_ctf_put(event_class); + bt_put(event_class); } BT_HIDDEN @@ -538,8 +530,7 @@ int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class *event_class, "stream_id", obj); end: - BT_VALUE_PUT(obj); - + BT_PUT(obj); return ret; } @@ -566,26 +557,26 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class) goto end; } - bt_ctf_base_init(event, bt_ctf_event_destroy); - bt_ctf_event_class_get(event_class); + bt_object_init(event, bt_ctf_event_destroy); + bt_get(event_class); bt_ctf_event_class_freeze(event_class); event->event_class = event_class; event->event_header = bt_ctf_field_create( event_class->stream_class->event_header_type); if (!event->event_header) { - goto error_destroy; + goto error; } if (event_class->context) { event->context_payload = bt_ctf_field_create( event_class->context); if (!event->context_payload) { - goto error_destroy; + goto error; } } event->fields_payload = bt_ctf_field_create(event_class->fields); if (!event->fields_payload) { - goto error_destroy; + goto error; } /* @@ -595,12 +586,9 @@ struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class) bt_ctf_stream_class_freeze(event_class->stream_class); end: return event; -error_destroy: - if (event) { - bt_ctf_event_destroy(&event->base.ref_count); - } - - return NULL; +error: + BT_PUT(event); + return event; } struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event) @@ -612,7 +600,7 @@ struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event) } event_class = event->event_class; - bt_ctf_event_class_get(event_class); + bt_get(event_class); end: return event_class; } @@ -626,9 +614,7 @@ struct bt_ctf_stream *bt_ctf_event_get_stream(struct bt_ctf_event *event) } stream = event->stream; - if (stream) { - bt_ctf_stream_get(stream); - } + bt_get(stream); end: return stream; } @@ -659,9 +645,9 @@ struct bt_ctf_clock *bt_ctf_event_get_clock(struct bt_ctf_event *event) } error_put_stream_class: - bt_ctf_stream_class_put(stream_class); + bt_put(stream_class); error_put_event_class: - bt_ctf_event_class_put(event_class); + bt_put(event_class); end: return clock; } @@ -685,14 +671,14 @@ int bt_ctf_event_set_payload(struct bt_ctf_event *event, payload_type = bt_ctf_field_get_type(payload); if (payload_type == event->event_class->fields) { - bt_ctf_field_put(event->fields_payload); - bt_ctf_field_get(payload); + bt_put(event->fields_payload); + bt_get(payload); event->fields_payload = payload; } else { ret = -1; } - bt_ctf_field_type_put(payload_type); + bt_put(payload_type); } end: return ret; @@ -707,7 +693,7 @@ struct bt_ctf_field *bt_ctf_event_get_payload_field(struct bt_ctf_event *event) } payload = event->fields_payload; - bt_ctf_field_get(payload); + bt_get(payload); end: return payload; } @@ -734,16 +720,12 @@ int bt_ctf_event_set_payload_field(struct bt_ctf_event *event, goto end; } - bt_ctf_field_get(payload); - if (event->fields_payload) { - bt_ctf_field_put(event->fields_payload); - } + bt_get(payload); + bt_put(event->fields_payload); event->fields_payload = payload; end: - if (payload_type) { - bt_ctf_field_type_put(payload_type); - } + bt_put(payload_type); return ret; } @@ -761,7 +743,7 @@ struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, name); } else { field = event->fields_payload; - bt_ctf_field_get(field); + bt_get(field); } end: return field; @@ -792,7 +774,7 @@ struct bt_ctf_field *bt_ctf_event_get_header( } header = event->event_header; - bt_ctf_field_get(header); + bt_get(header); end: return header; } @@ -824,13 +806,11 @@ int bt_ctf_event_set_header(struct bt_ctf_event *event, goto end; } - bt_ctf_field_get(header); - bt_ctf_field_put(event->event_header); + bt_get(header); + bt_put(event->event_header); event->event_header = header; end: - if (field_type) { - bt_ctf_field_type_put(field_type); - } + bt_put(field_type); return ret; } @@ -844,7 +824,7 @@ struct bt_ctf_field *bt_ctf_event_get_event_context( } context = event->context_payload; - bt_ctf_field_get(context); + bt_get(context); end: return context; } @@ -866,78 +846,50 @@ int bt_ctf_event_set_event_context(struct bt_ctf_event *event, goto end; } - bt_ctf_field_get(context); - bt_ctf_field_put(event->context_payload); + bt_get(context); + bt_put(event->context_payload); event->context_payload = context; end: - if (field_type) { - bt_ctf_field_type_put(field_type); - } + bt_put(field_type); return ret; } void bt_ctf_event_get(struct bt_ctf_event *event) { - bt_ctf_get(event); + bt_get(event); } void bt_ctf_event_put(struct bt_ctf_event *event) { - bt_ctf_put(event); + bt_put(event); } static -void bt_ctf_event_class_destroy(struct bt_ref *ref) +void bt_ctf_event_class_destroy(struct bt_object *obj) { struct bt_ctf_event_class *event_class; - struct bt_ctf_base *base; - - if (!ref) { - return; - } /* * Don't call put() on the stream class. See comment in * bt_ctf_event_class_set_stream_class for explanation. */ - base = container_of(ref, struct bt_ctf_base, ref_count); - event_class = container_of(base, struct bt_ctf_event_class, base); - if (event_class->attributes) { - bt_ctf_attributes_destroy(event_class->attributes); - } - if (event_class->context) { - bt_ctf_field_type_put(event_class->context); - } - if (event_class->fields) { - bt_ctf_field_type_put(event_class->fields); - } + event_class = container_of(obj, struct bt_ctf_event_class, base); + bt_ctf_attributes_destroy(event_class->attributes); + bt_put(event_class->context); + bt_put(event_class->fields); g_free(event_class); } static -void bt_ctf_event_destroy(struct bt_ref *ref) +void bt_ctf_event_destroy(struct bt_object *obj) { struct bt_ctf_event *event; - struct bt_ctf_base *base; - if (!ref) { - return; - } - - base = container_of(ref, struct bt_ctf_base, ref_count); - event = container_of(base, struct bt_ctf_event, base); - if (event->event_class) { - bt_ctf_event_class_put(event->event_class); - } - if (event->event_header) { - bt_ctf_field_put(event->event_header); - } - if (event->context_payload) { - bt_ctf_field_put(event->context_payload); - } - if (event->fields_payload) { - bt_ctf_field_put(event->fields_payload); - } + event = container_of(obj, struct bt_ctf_event, base); + bt_put(event->event_class); + bt_put(event->event_header); + bt_put(event->context_payload); + bt_put(event->fields_payload); g_free(event); } @@ -980,7 +932,7 @@ int set_integer_field_value(struct bt_ctf_field* field, uint64_t value) } } end: - bt_ctf_field_type_put(field_type); + bt_put(field_type); return ret; } @@ -1096,7 +1048,7 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, break; } - BT_VALUE_PUT(attr_value); + BT_PUT(attr_value); } if (event_class->context) { @@ -1121,7 +1073,7 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, g_string_append(context->string, "};\n\n"); end: context->current_indentation_level = 0; - BT_VALUE_PUT(attr_value); + BT_PUT(attr_value); return ret; } @@ -1219,12 +1171,12 @@ int bt_ctf_event_populate_event_header(struct bt_ctf_event *event) assert(timestamp_field_type); mapped_clock = bt_ctf_field_type_integer_get_mapped_clock( timestamp_field_type); - bt_ctf_field_type_put(timestamp_field_type); + bt_put(timestamp_field_type); if (mapped_clock) { uint64_t timestamp = bt_ctf_clock_get_time( mapped_clock); - bt_ctf_clock_put(mapped_clock); + bt_put(mapped_clock); if (timestamp == (uint64_t) -1ULL) { goto end; } @@ -1237,12 +1189,8 @@ int bt_ctf_event_populate_event_header(struct bt_ctf_event *event) } } end: - if (id_field) { - bt_ctf_field_put(id_field); - } - if (timestamp_field) { - bt_ctf_field_put(timestamp_field); - } + bt_put(id_field); + bt_put(timestamp_field); return ret; } @@ -1281,9 +1229,9 @@ struct bt_ctf_event *bt_ctf_event_copy(struct bt_ctf_event *event) goto error; } - bt_ctf_base_init(copy, bt_ctf_event_destroy); + bt_object_init(copy, bt_ctf_event_destroy); copy->event_class = event->event_class; - bt_ctf_event_class_get(copy->event_class); + bt_get(copy->event_class); copy->stream = event->stream; if (event->event_header) { @@ -1314,24 +1262,6 @@ struct bt_ctf_event *bt_ctf_event_copy(struct bt_ctf_event *event) return copy; error: - if (copy) { - if (copy->event_class) { - bt_ctf_event_class_put(copy->event_class); - } - - if (copy->event_header) { - bt_ctf_field_put(copy->event_header); - } - - if (copy->context_payload) { - bt_ctf_field_put(copy->context_payload); - } - - if (copy->fields_payload) { - bt_ctf_field_put(copy->fields_payload); - } - } - - g_free(copy); - return NULL; + BT_PUT(copy); + return copy; } diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 1b4e9eb5..573fb421 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -37,13 +37,12 @@ #include #include #include -#include -#include +#include #include #include static -void bt_ctf_stream_class_destroy(struct bt_ref *ref); +void bt_ctf_stream_class_destroy(struct bt_object *obj); static int init_event_header(struct bt_ctf_stream_class *stream_class); static @@ -65,28 +64,26 @@ struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) stream_class->name = g_string_new(name); stream_class->event_classes = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_event_class_put); + (GDestroyNotify) bt_put); if (!stream_class->event_classes) { - goto error_destroy; + goto error; } ret = init_event_header(stream_class); if (ret) { - goto error_destroy; + goto error; } ret = init_packet_context(stream_class); if (ret) { - goto error_destroy; + goto error; } - bt_ctf_base_init(stream_class, bt_ctf_stream_class_destroy); + bt_object_init(stream_class, bt_ctf_stream_class_destroy); return stream_class; -error_destroy: - bt_ctf_stream_class_destroy(&stream_class->base.ref_count); - stream_class = NULL; error: + BT_PUT(stream_class); return stream_class; } @@ -101,7 +98,7 @@ struct bt_ctf_trace *bt_ctf_stream_class_get_trace( trace = stream_class->trace; if (trace) { - bt_ctf_trace_get(trace); + bt_get(trace); } end: return trace; @@ -146,7 +143,7 @@ struct bt_ctf_clock *bt_ctf_stream_class_get_clock( } clock = stream_class->clock; - bt_ctf_clock_get(clock); + bt_get(clock); end: return clock; } @@ -175,7 +172,7 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, mapped_clock = bt_ctf_field_type_integer_get_mapped_clock( timestamp_field); if (mapped_clock) { - bt_ctf_clock_put(mapped_clock); + bt_put(mapped_clock); goto end; } @@ -187,14 +184,14 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, } if (stream_class->clock) { - bt_ctf_clock_put(stream_class->clock); + bt_put(stream_class->clock); } stream_class->clock = clock; - bt_ctf_clock_get(clock); + bt_get(clock); end: if (timestamp_field) { - bt_ctf_field_type_put(timestamp_field); + bt_put(timestamp_field); } return ret; } @@ -377,7 +374,7 @@ int bt_ctf_stream_class_add_event_class( goto end; } - bt_ctf_event_class_get(event_class); + bt_get(event_class); g_ptr_array_add(stream_class->event_classes, event_class); bt_ctf_event_class_freeze(event_class); @@ -422,7 +419,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( } event_class = g_ptr_array_index(stream_class->event_classes, index); - bt_ctf_event_class_get(event_class); + bt_get(event_class); end: return event_class; } @@ -445,7 +442,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( if (!strcmp(name, cur_event_class_name)) { event_class = cur_event_class; - bt_ctf_event_class_get(event_class); + bt_get(event_class); goto end; } } @@ -469,7 +466,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id( if (bt_ctf_event_class_get_id(current_event_class) == id) { event_class = current_event_class; - bt_ctf_event_class_get(event_class); + bt_get(event_class); goto end; } } @@ -487,7 +484,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type( } assert(stream_class->packet_context_type); - bt_ctf_field_type_get(stream_class->packet_context_type); + bt_get(stream_class->packet_context_type); ret = stream_class->packet_context_type; end: return ret; @@ -515,8 +512,8 @@ int bt_ctf_stream_class_set_packet_context_type( goto end; } - bt_ctf_field_type_put(stream_class->packet_context_type); - bt_ctf_field_type_get(packet_context_type); + bt_put(stream_class->packet_context_type); + bt_get(packet_context_type); stream_class->packet_context_type = packet_context_type; end: return ret; @@ -532,7 +529,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type( } assert(stream_class->event_header_type); - bt_ctf_field_type_get(stream_class->event_header_type); + bt_get(stream_class->event_header_type); ret = stream_class->event_header_type; end: return ret; @@ -560,8 +557,8 @@ int bt_ctf_stream_class_set_event_header_type( goto end; } - bt_ctf_field_type_put(stream_class->event_header_type); - bt_ctf_field_type_get(event_header_type); + bt_put(stream_class->event_header_type); + bt_get(event_header_type); stream_class->event_header_type = event_header_type; end: return ret; @@ -577,7 +574,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type( } assert(stream_class->event_context_type); - bt_ctf_field_type_get(stream_class->event_context_type); + bt_get(stream_class->event_context_type); ret = stream_class->event_context_type; end: return ret; @@ -601,8 +598,8 @@ int bt_ctf_stream_class_set_event_context_type( goto end; } - bt_ctf_field_type_put(stream_class->event_context_type); - bt_ctf_field_type_get(event_context_type); + bt_put(stream_class->event_context_type); + bt_get(event_context_type); stream_class->event_context_type = event_context_type; end: return ret; @@ -610,12 +607,12 @@ end: void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class) { - bt_ctf_get(stream_class); + bt_get(stream_class); } void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class) { - bt_ctf_put(stream_class); + bt_put(stream_class); } BT_HIDDEN @@ -758,18 +755,12 @@ end: } static -void bt_ctf_stream_class_destroy(struct bt_ref *ref) +void bt_ctf_stream_class_destroy(struct bt_object *obj) { struct bt_ctf_stream_class *stream_class; - struct bt_ctf_base *base; - if (!ref) { - return; - } - - base = container_of(ref, struct bt_ctf_base, ref_count); - stream_class = container_of(base, struct bt_ctf_stream_class, base); - bt_ctf_clock_put(stream_class->clock); + stream_class = container_of(obj, struct bt_ctf_stream_class, base); + bt_put(stream_class->clock); if (stream_class->event_classes) { size_t i; @@ -790,11 +781,9 @@ void bt_ctf_stream_class_destroy(struct bt_ref *ref) g_string_free(stream_class->name, TRUE); } - bt_ctf_field_type_put(stream_class->event_header_type); - bt_ctf_field_type_put(stream_class->packet_context_type); - if (stream_class->event_context_type) { - bt_ctf_field_type_put(stream_class->event_context_type); - } + bt_put(stream_class->event_header_type); + bt_put(stream_class->packet_context_type); + bt_put(stream_class->event_context_type); g_free(stream_class); } @@ -827,16 +816,16 @@ int init_event_header(struct bt_ctf_stream_class *stream_class) } if (stream_class->event_header_type) { - bt_ctf_field_type_put(stream_class->event_header_type); + bt_put(stream_class->event_header_type); } stream_class->event_header_type = event_header_type; end: if (ret) { - bt_ctf_field_type_put(event_header_type); + bt_put(event_header_type); } - bt_ctf_field_type_put(_uint32_t); - bt_ctf_field_type_put(_uint64_t); + bt_put(_uint32_t); + bt_put(_uint64_t); return ret; } @@ -888,16 +877,14 @@ int init_packet_context(struct bt_ctf_stream_class *stream_class) goto end; } - if (stream_class->packet_context_type) { - bt_ctf_field_type_put(stream_class->packet_context_type); - } + bt_put(stream_class->packet_context_type); stream_class->packet_context_type = packet_context_type; end: if (ret) { - bt_ctf_field_type_put(packet_context_type); + bt_put(packet_context_type); goto end; } - bt_ctf_field_type_put(_uint64_t); + bt_put(_uint64_t); return ret; } diff --git a/formats/ctf/ir/stream.c b/formats/ctf/ir/stream.c index 29874924..6a6a3a77 100644 --- a/formats/ctf/ir/stream.c +++ b/formats/ctf/ir/stream.c @@ -35,15 +35,14 @@ #include #include #include -#include -#include +#include #include #include #include #include static -void bt_ctf_stream_destroy(struct bt_ref *ref); +void bt_ctf_stream_destroy(struct bt_object *obj); static int set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t); @@ -92,12 +91,8 @@ int set_packet_header_magic(struct bt_ctf_stream *stream) (uint64_t) 0xC1FC1FC1); } end: - if (magic_field) { - bt_ctf_field_put(magic_field); - } - if (magic_field_type) { - bt_ctf_field_type_put(magic_field_type); - } + bt_put(magic_field); + bt_put(magic_field_type); return ret; } @@ -160,22 +155,16 @@ int set_packet_header_uuid(struct bt_ctf_stream *stream) uuid_element, (uint64_t) stream->trace->uuid[i]); } - bt_ctf_field_put(uuid_element); + bt_put(uuid_element); if (ret) { goto end; } } end: - if (uuid_field) { - bt_ctf_field_put(uuid_field); - } - if (uuid_field_type) { - bt_ctf_field_type_put(uuid_field_type); - } - if (element_field_type) { - bt_ctf_field_type_put(element_field_type); - } + bt_put(uuid_field); + bt_put(uuid_field_type); + bt_put(element_field_type); return ret; } static @@ -216,12 +205,8 @@ int set_packet_header_stream_id(struct bt_ctf_stream *stream) (uint64_t) stream_id); } end: - if (stream_id_field) { - bt_ctf_field_put(stream_id_field); - } - if (stream_id_field_type) { - bt_ctf_field_type_put(stream_id_field_type); - } + bt_put(stream_id_field); + bt_put(stream_id_field_type); return ret; } @@ -252,7 +237,7 @@ static void put_event(struct bt_ctf_event *event) { bt_ctf_event_set_stream(event, NULL); - bt_ctf_event_put(event); + bt_put(event); } BT_HIDDEN @@ -274,11 +259,11 @@ struct bt_ctf_stream *bt_ctf_stream_create( /* A stream has no ownership of its trace (weak ptr) */ stream->trace = trace; - bt_ctf_base_init(stream, bt_ctf_stream_destroy); + bt_object_init(stream, bt_ctf_stream_destroy); stream->packet_context = bt_ctf_field_create( stream_class->packet_context_type); if (!stream->packet_context) { - goto error_destroy; + goto error; } /* @@ -291,7 +276,7 @@ struct bt_ctf_stream *bt_ctf_stream_create( stream->event_context = bt_ctf_field_create( stream_class->event_context_type); if (!stream->packet_context) { - goto error_destroy; + goto error; } } @@ -299,23 +284,23 @@ struct bt_ctf_stream *bt_ctf_stream_create( ret = set_structure_field_integer(stream->packet_context, "events_discarded", 0); if (ret) { - goto error_destroy; + goto error; } stream->pos.fd = -1; stream->id = stream_class->next_stream_id++; stream->stream_class = stream_class; - bt_ctf_stream_class_get(stream_class); + bt_get(stream_class); stream->events = g_ptr_array_new_with_free_func( (GDestroyNotify) put_event); if (!stream->events) { - goto error_destroy; + goto error; } if (stream_class->event_context_type) { stream->event_contexts = g_ptr_array_new_with_free_func( (GDestroyNotify) bt_ctf_field_put); if (!stream->event_contexts) { - goto error_destroy; + goto error; } } @@ -323,7 +308,7 @@ struct bt_ctf_stream *bt_ctf_stream_create( assert(trace->packet_header_type); stream->packet_header = bt_ctf_field_create(trace->packet_header_type); if (!stream->packet_header) { - goto error_destroy; + goto error; } /* * Attempt to populate the default trace packet header fields @@ -335,13 +320,13 @@ struct bt_ctf_stream *bt_ctf_stream_create( */ ret = set_packet_header(stream); if (ret) { - goto error_destroy; + goto error; } end: return stream; -error_destroy: - bt_ctf_stream_destroy(&stream->base.ref_count); - return NULL; +error: + BT_PUT(stream); + return stream; } BT_HIDDEN @@ -370,7 +355,7 @@ struct bt_ctf_stream_class *bt_ctf_stream_get_class( } stream_class = stream->stream_class; - bt_ctf_stream_class_get(stream_class); + bt_get(stream_class); end: return stream_class; } @@ -431,12 +416,8 @@ int bt_ctf_stream_get_discarded_events_count( } } end: - if (events_discarded_field) { - bt_ctf_field_put(events_discarded_field); - } - if (events_discarded_field_type) { - bt_ctf_field_type_put(events_discarded_field_type); - } + bt_put(events_discarded_field); + bt_put(events_discarded_field_type); return ret; } @@ -494,12 +475,8 @@ void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream, } end: - if (events_discarded_field) { - bt_ctf_field_put(events_discarded_field); - } - if (events_discarded_field_type) { - bt_ctf_field_type_put(events_discarded_field_type); - } + bt_put(events_discarded_field); + bt_put(events_discarded_field_type); } int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, @@ -546,7 +523,7 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream, } } - bt_ctf_event_get(event); + bt_get(event); /* Save the new event along with its associated stream event context */ g_ptr_array_add(stream->events, event); if (event_context_copy) { @@ -570,7 +547,7 @@ struct bt_ctf_field *bt_ctf_stream_get_packet_context( packet_context = stream->packet_context; if (packet_context) { - bt_ctf_field_get(packet_context); + bt_get(packet_context); } end: return packet_context; @@ -593,9 +570,9 @@ int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, goto end; } - bt_ctf_field_type_put(field_type); - bt_ctf_field_get(field); - bt_ctf_field_put(stream->packet_context); + bt_put(field_type); + bt_get(field); + bt_put(stream->packet_context); stream->packet_context = field; end: return ret; @@ -612,7 +589,7 @@ struct bt_ctf_field *bt_ctf_stream_get_event_context( event_context = stream->event_context; if (event_context) { - bt_ctf_field_get(event_context); + bt_get(event_context); } end: return event_context; @@ -635,13 +612,11 @@ int bt_ctf_stream_set_event_context(struct bt_ctf_stream *stream, goto end; } - bt_ctf_field_get(field); - bt_ctf_field_put(stream->event_context); + bt_get(field); + bt_put(stream->event_context); stream->event_context = field; end: - if (field_type) { - bt_ctf_field_type_put(field_type); - } + bt_put(field_type); return ret; } @@ -656,7 +631,7 @@ struct bt_ctf_field *bt_ctf_stream_get_packet_header( packet_header = stream->packet_header; if (packet_header) { - bt_ctf_field_get(packet_header); + bt_get(packet_header); } end: return packet_header; @@ -679,13 +654,11 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream, goto end; } - bt_ctf_field_get(field); - bt_ctf_field_put(stream->packet_header); + bt_get(field); + bt_put(stream->packet_header); stream->packet_header = field; end: - if (field_type) { - bt_ctf_field_type_put(field_type); - } + bt_put(field_type); return ret; } @@ -728,8 +701,8 @@ int get_event_header_timestamp(struct bt_ctf_field *event_header, uint64_t *time } } end: - bt_ctf_field_put(timestamp_field); - bt_ctf_field_type_put(timestamp_field_type); + bt_put(timestamp_field); + bt_put(timestamp_field_type); return ret; } @@ -893,55 +866,41 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream) } stream->flushed_packet_count++; end: - bt_ctf_field_put(integer); + bt_put(integer); return ret; } void bt_ctf_stream_get(struct bt_ctf_stream *stream) { - bt_ctf_get(stream); + bt_get(stream); } void bt_ctf_stream_put(struct bt_ctf_stream *stream) { - bt_ctf_put(stream); + bt_put(stream); } static -void bt_ctf_stream_destroy(struct bt_ref *ref) +void bt_ctf_stream_destroy(struct bt_object *obj) { struct bt_ctf_stream *stream; - struct bt_ctf_base *base; - - if (!ref) { - return; - } - base = container_of(ref, struct bt_ctf_base, ref_count); - stream = container_of(base, struct bt_ctf_stream, base); + stream = container_of(obj, struct bt_ctf_stream, base); ctf_fini_pos(&stream->pos); if (stream->pos.fd >= 0 && close(stream->pos.fd)) { perror("close"); } - if (stream->stream_class) { - bt_ctf_stream_class_put(stream->stream_class); - } + bt_put(stream->stream_class); if (stream->events) { g_ptr_array_free(stream->events, TRUE); } if (stream->event_contexts) { g_ptr_array_free(stream->event_contexts, TRUE); } - if (stream->packet_header) { - bt_ctf_field_put(stream->packet_header); - } - if (stream->packet_context) { - bt_ctf_field_put(stream->packet_context); - } - if (stream->event_context) { - bt_ctf_field_put(stream->event_context); - } + bt_put(stream->packet_header); + bt_put(stream->packet_context); + bt_put(stream->event_context); g_free(stream); } @@ -990,11 +949,7 @@ int set_structure_field_integer(struct bt_ctf_field *structure, char *name, ret = bt_ctf_field_unsigned_integer_set_value(integer, value); } end: - if (integer) { - bt_ctf_field_put(integer); - } - if (field_type) { - bt_ctf_field_type_put(field_type); - } + bt_put(integer); + bt_put(field_type); return ret; } diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 9c3cb507..f96ce87c 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -35,16 +35,15 @@ #include #include #include -#include -#include #include #include +#include #define DEFAULT_IDENTIFIER_SIZE 128 #define DEFAULT_METADATA_STRING_SIZE 4096 static -void bt_ctf_trace_destroy(struct bt_ref *ref); +void bt_ctf_trace_destroy(struct bt_object *obj); static int init_trace_packet_header(struct bt_ctf_trace *trace); static @@ -72,7 +71,7 @@ static void put_stream_class(struct bt_ctf_stream_class *stream_class) { (void) bt_ctf_stream_class_set_trace(stream_class, NULL); - bt_ctf_stream_class_put(stream_class); + bt_put(stream_class); } struct bt_ctf_trace *bt_ctf_trace_create(void) @@ -85,49 +84,41 @@ struct bt_ctf_trace *bt_ctf_trace_create(void) } bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE); - bt_ctf_base_init(trace, bt_ctf_trace_destroy); + bt_object_init(trace, bt_ctf_trace_destroy); trace->clocks = g_ptr_array_new_with_free_func( - (GDestroyNotify) bt_ctf_clock_put); + (GDestroyNotify) bt_put); trace->streams = g_ptr_array_new_with_free_func( - (GDestroyNotify) bt_ctf_stream_put); + (GDestroyNotify) bt_put); trace->stream_classes = g_ptr_array_new_with_free_func( (GDestroyNotify) put_stream_class); if (!trace->clocks || !trace->stream_classes || !trace->streams) { - goto error_destroy; + goto error; } /* Generate a trace UUID */ uuid_generate(trace->uuid); if (init_trace_packet_header(trace)) { - goto error_destroy; + goto error; } /* Create the environment array object */ trace->environment = bt_ctf_attributes_create(); if (!trace->environment) { - goto error_destroy; + goto error; } return trace; -error_destroy: - bt_ctf_trace_destroy(&trace->base.ref_count); - trace = NULL; error: + BT_PUT(trace); return trace; } -void bt_ctf_trace_destroy(struct bt_ref *ref) +void bt_ctf_trace_destroy(struct bt_object *obj) { struct bt_ctf_trace *trace; - struct bt_ctf_base *base; - - if (!ref) { - return; - } - base = container_of(ref, struct bt_ctf_base, ref_count); - trace = container_of(base, struct bt_ctf_trace, base); + trace = container_of(obj, struct bt_ctf_trace, base); if (trace->environment) { bt_ctf_attributes_destroy(trace->environment); } @@ -144,7 +135,7 @@ void bt_ctf_trace_destroy(struct bt_ref *ref) g_ptr_array_free(trace->stream_classes, TRUE); } - bt_ctf_field_type_put(trace->packet_header_type); + bt_put(trace->packet_header_type); g_free(trace); } @@ -178,13 +169,13 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace, goto error; } - bt_ctf_stream_get(stream); + bt_get(stream); g_ptr_array_add(trace->streams, stream); return stream; error: - bt_ctf_stream_put(stream); - return NULL; + BT_PUT(stream); + return stream; } int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace, @@ -216,7 +207,7 @@ int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace, trace->environment, name); if (attribute) { - BT_VALUE_PUT(attribute); + BT_PUT(attribute); ret = -1; goto end; } @@ -252,7 +243,7 @@ int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace, trace->environment, name); if (attribute) { - BT_VALUE_PUT(attribute); + BT_PUT(attribute); ret = -1; goto end; } @@ -272,8 +263,7 @@ int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace, env_value_string_obj); end: - BT_VALUE_PUT(env_value_string_obj); - + BT_PUT(env_value_string_obj); return ret; } @@ -298,7 +288,7 @@ int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace *trace, trace->environment, name); if (attribute) { - BT_VALUE_PUT(attribute); + BT_PUT(attribute); ret = -1; goto end; } @@ -316,8 +306,7 @@ int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace *trace, bt_value_freeze(env_value_integer_obj); } end: - BT_VALUE_PUT(env_value_integer_obj); - + BT_PUT(env_value_integer_obj); return ret; } @@ -401,7 +390,7 @@ int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace, goto end; } - bt_ctf_clock_get(clock); + bt_get(clock); g_ptr_array_add(trace->clocks, clock); end: return ret; @@ -430,7 +419,7 @@ struct bt_ctf_clock *bt_ctf_trace_get_clock(struct bt_ctf_trace *trace, } clock = g_ptr_array_index(trace->clocks, index); - bt_ctf_clock_get(clock); + bt_get(clock); end: return clock; } @@ -488,7 +477,7 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, goto end; } - bt_ctf_stream_class_get(stream_class); + bt_get(stream_class); g_ptr_array_add(trace->stream_classes, stream_class); /* @@ -542,7 +531,7 @@ struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class( } stream_class = g_ptr_array_index(trace->stream_classes, index); - bt_ctf_stream_class_get(stream_class); + bt_get(stream_class); end: return stream_class; } @@ -566,7 +555,7 @@ struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id( if (bt_ctf_stream_class_get_id(stream_class_candidate) == (int64_t) id) { stream_class = stream_class_candidate; - bt_ctf_get(stream_class); + bt_get(stream_class); goto end; } } @@ -596,7 +585,7 @@ struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name( if (!strcmp(cur_clk_name, name)) { clock = cur_clk; - bt_ctf_clock_get(clock); + bt_get(clock); goto end; } } @@ -737,7 +726,7 @@ void append_env_metadata(struct bt_ctf_trace *trace, } loop_next: - BT_VALUE_PUT(env_field_value_obj); + BT_PUT(env_field_value_obj); } g_string_append(context->string, "};\n\n"); @@ -859,7 +848,7 @@ struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type( goto end; } - bt_ctf_field_type_get(trace->packet_header_type); + bt_get(trace->packet_header_type); field_type = trace->packet_header_type; end: return field_type; @@ -882,8 +871,8 @@ int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace, goto end; } - bt_ctf_field_type_get(packet_header_type); - bt_ctf_field_type_put(trace->packet_header_type); + bt_get(packet_header_type); + bt_put(trace->packet_header_type); trace->packet_header_type = packet_header_type; end: return ret; @@ -891,12 +880,12 @@ end: void bt_ctf_trace_get(struct bt_ctf_trace *trace) { - bt_ctf_get(trace); + bt_get(trace); } void bt_ctf_trace_put(struct bt_ctf_trace *trace) { - bt_ctf_put(trace); + bt_put(trace); } @@ -977,12 +966,11 @@ int init_trace_packet_header(struct bt_ctf_trace *trace) goto end; } end: - bt_ctf_field_type_put(uuid_array_type); - bt_ctf_field_type_put(_uint32_t); - bt_ctf_field_type_put(_uint8_t); - bt_ctf_field_put(magic); - bt_ctf_field_put(uuid_array); - bt_ctf_field_type_put(trace_packet_header_type); - + bt_put(uuid_array_type); + bt_put(_uint32_t); + bt_put(_uint8_t); + bt_put(magic); + bt_put(uuid_array); + bt_put(trace_packet_header_type); return ret; } diff --git a/formats/ctf/writer/writer.c b/formats/ctf/writer/writer.c index 9adfcd38..f8a36778 100644 --- a/formats/ctf/writer/writer.c +++ b/formats/ctf/writer/writer.c @@ -33,8 +33,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -45,7 +44,8 @@ #include static -void bt_ctf_writer_destroy(struct bt_ref *ref); +void bt_ctf_writer_destroy(struct bt_object *obj); + static int create_stream_file(struct bt_ctf_writer *writer, struct bt_ctf_stream *stream); @@ -63,7 +63,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) goto error; } - bt_ctf_base_init(writer, bt_ctf_writer_destroy); + bt_object_init(writer, bt_ctf_writer_destroy); writer->path = g_string_new(path); if (!writer->path) { goto error_destroy; @@ -94,23 +94,16 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) error_destroy: unlinkat(writer->trace_dir_fd, "metadata", 0); - bt_ctf_writer_destroy(&writer->base.ref_count); - writer = NULL; + BT_PUT(writer); error: return writer; } -void bt_ctf_writer_destroy(struct bt_ref *ref) +void bt_ctf_writer_destroy(struct bt_object *obj) { struct bt_ctf_writer *writer; - struct bt_ctf_base *base; - - if (!ref) { - return; - } - base = container_of(ref, struct bt_ctf_base, ref_count); - writer = container_of(base, struct bt_ctf_writer, base); + writer = container_of(obj, struct bt_ctf_writer, base); bt_ctf_writer_flush_metadata(writer); if (writer->path) { g_string_free(writer->path, TRUE); @@ -128,7 +121,7 @@ void bt_ctf_writer_destroy(struct bt_ref *ref) } } - bt_ctf_trace_put(writer->trace); + bt_put(writer->trace); g_free(writer); } @@ -141,7 +134,7 @@ struct bt_ctf_trace *bt_ctf_writer_get_trace(struct bt_ctf_writer *writer) } trace = writer->trace; - bt_ctf_trace_get(trace); + bt_get(trace); end: return trace; } @@ -170,8 +163,8 @@ struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, return stream; error: - bt_ctf_stream_put(stream); - return NULL; + BT_PUT(stream); + return stream; } int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, @@ -271,12 +264,12 @@ end: void bt_ctf_writer_get(struct bt_ctf_writer *writer) { - bt_ctf_get(writer); + bt_get(writer); } void bt_ctf_writer_put(struct bt_ctf_writer *writer) { - bt_ctf_put(writer); + bt_put(writer); } static diff --git a/include/Makefile.am b/include/Makefile.am index b852ed15..15159dd7 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -6,7 +6,8 @@ babeltraceinclude_HEADERS = \ babeltrace/trace-handle.h \ babeltrace/list.h \ babeltrace/clock-types.h \ - babeltrace/values.h + babeltrace/values.h \ + babeltrace/ref.h babeltracectfinclude_HEADERS = \ babeltrace/ctf/events.h \ @@ -27,7 +28,6 @@ babeltracectfirinclude_HEADERS = \ babeltrace/ctf-ir/event-fields.h \ babeltrace/ctf-ir/event-types.h \ babeltrace/ctf-ir/event.h \ - babeltrace/ctf-ir/ref.h \ babeltrace/ctf-ir/stream.h \ babeltrace/ctf-ir/stream-class.h \ babeltrace/ctf-ir/trace.h \ @@ -46,6 +46,7 @@ noinst_HEADERS = \ babeltrace/prio_heap.h \ babeltrace/ref-internal.h \ babeltrace/types.h \ + babeltrace/object-internal.h \ babeltrace/ctf-ir/metadata.h \ babeltrace/ctf/events-internal.h \ babeltrace/ctf/metadata.h \ @@ -55,7 +56,6 @@ noinst_HEADERS = \ babeltrace/ctf/ctf-index.h \ babeltrace/ctf-writer/writer-internal.h \ babeltrace/ctf-ir/attributes-internal.h \ - babeltrace/ctf-ir/common-internal.h \ babeltrace/ctf-ir/event-types-internal.h \ babeltrace/ctf-ir/event-fields-internal.h \ babeltrace/ctf-ir/event-internal.h \ diff --git a/include/babeltrace/ctf-ir/clock-internal.h b/include/babeltrace/ctf-ir/clock-internal.h index 7428126e..135b1c5f 100644 --- a/include/babeltrace/ctf-ir/clock-internal.h +++ b/include/babeltrace/ctf-ir/clock-internal.h @@ -29,13 +29,13 @@ #include #include -#include +#include #include #include #include struct bt_ctf_clock { - struct bt_ctf_base base; + struct bt_object base; GString *name; GString *description; uint64_t frequency; diff --git a/include/babeltrace/ctf-ir/event-fields-internal.h b/include/babeltrace/ctf-ir/event-fields-internal.h index e0214e82..4dea4a79 100644 --- a/include/babeltrace/ctf-ir/event-fields-internal.h +++ b/include/babeltrace/ctf-ir/event-fields-internal.h @@ -28,13 +28,13 @@ */ #include -#include +#include #include #include #include struct bt_ctf_field { - struct bt_ctf_base base; + struct bt_object base; struct bt_ctf_field_type *type; int payload_set; }; diff --git a/include/babeltrace/ctf-ir/event-internal.h b/include/babeltrace/ctf-ir/event-internal.h index db98771f..17695f92 100644 --- a/include/babeltrace/ctf-ir/event-internal.h +++ b/include/babeltrace/ctf-ir/event-internal.h @@ -34,14 +34,14 @@ #include #include #include -#include +#include #include #define BT_CTF_EVENT_CLASS_ATTR_ID_INDEX 0 #define BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX 1 struct bt_ctf_event_class { - struct bt_ctf_base base; + struct bt_object base; struct bt_value *attributes; /* * Weak reference; an event class does not have ownership of a @@ -56,7 +56,7 @@ struct bt_ctf_event_class { }; struct bt_ctf_event { - struct bt_ctf_base base; + struct bt_object base; struct bt_ctf_event_class *event_class; /* Weak reference; an event does not have ownership of a stream */ struct bt_ctf_stream *stream; diff --git a/include/babeltrace/ctf-ir/event-types-internal.h b/include/babeltrace/ctf-ir/event-types-internal.h index 3adae331..ed085dab 100644 --- a/include/babeltrace/ctf-ir/event-types-internal.h +++ b/include/babeltrace/ctf-ir/event-types-internal.h @@ -31,8 +31,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -62,7 +62,7 @@ struct bt_ctf_field_path { }; struct bt_ctf_field_type { - struct bt_ctf_base base; + struct bt_object base; struct bt_declaration *declaration; type_freeze_func freeze; type_serialize_func serialize; diff --git a/include/babeltrace/ctf-ir/stream-class-internal.h b/include/babeltrace/ctf-ir/stream-class-internal.h index 4338742e..2a481b08 100644 --- a/include/babeltrace/ctf-ir/stream-class-internal.h +++ b/include/babeltrace/ctf-ir/stream-class-internal.h @@ -31,13 +31,13 @@ #include #include #include -#include +#include #include #include #include struct bt_ctf_stream_class { - struct bt_ctf_base base; + struct bt_object base; GString *name; struct bt_ctf_clock *clock; GPtrArray *event_classes; /* Array of pointers to bt_ctf_event_class */ diff --git a/include/babeltrace/ctf-ir/stream-internal.h b/include/babeltrace/ctf-ir/stream-internal.h index b0011ddf..ca22eb11 100644 --- a/include/babeltrace/ctf-ir/stream-internal.h +++ b/include/babeltrace/ctf-ir/stream-internal.h @@ -28,7 +28,7 @@ */ #include -#include +#include #include #include #include @@ -37,7 +37,7 @@ #include struct bt_ctf_stream { - struct bt_ctf_base base; + struct bt_object base; /* Trace owning this stream. A stream does not own a trace. */ struct bt_ctf_trace *trace; uint32_t id; @@ -55,7 +55,7 @@ struct bt_ctf_stream { struct bt_ctf_field *event_context; }; -/* Stream class should be locked by the caller after creating a stream */ +/* Stream class should be frozen by the caller after creating a stream */ BT_HIDDEN struct bt_ctf_stream *bt_ctf_stream_create( struct bt_ctf_stream_class *stream_class, diff --git a/include/babeltrace/ctf-ir/trace-internal.h b/include/babeltrace/ctf-ir/trace-internal.h index b8a3d8c8..227120dc 100644 --- a/include/babeltrace/ctf-ir/trace-internal.h +++ b/include/babeltrace/ctf-ir/trace-internal.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -48,7 +48,7 @@ enum field_type_alias { }; struct bt_ctf_trace { - struct bt_ctf_base base; + struct bt_object base; int frozen; uuid_t uuid; int byte_order; /* A value defined in Babeltrace's "endian.h" */ diff --git a/include/babeltrace/ctf-writer/writer-internal.h b/include/babeltrace/ctf-writer/writer-internal.h index 6b1677ae..2857bdd9 100644 --- a/include/babeltrace/ctf-writer/writer-internal.h +++ b/include/babeltrace/ctf-writer/writer-internal.h @@ -33,10 +33,10 @@ #include #include #include -#include +#include struct bt_ctf_writer { - struct bt_ctf_base base; + struct bt_object base; int frozen; /* Protects attributes that can't be changed mid-trace */ struct bt_ctf_trace *trace; GString *path; diff --git a/include/babeltrace/ctf-ir/common-internal.h b/include/babeltrace/object-internal.h similarity index 63% rename from include/babeltrace/ctf-ir/common-internal.h rename to include/babeltrace/object-internal.h index 5922780b..afba4479 100644 --- a/include/babeltrace/ctf-ir/common-internal.h +++ b/include/babeltrace/object-internal.h @@ -1,11 +1,12 @@ -#ifndef BABELTRACE_CTF_IR_COMMON_INTERNAL_H -#define BABELTRACE_CTF_IR_COMMON_INTERNAL_H +#ifndef BABELTRACE_OBJECT_INTERNAL_H +#define BABELTRACE_OBJECT_INTERNAL_H /* - * Babeltrace - CTF IR: common data structures + * Babeltrace - Base object * - * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation - * Copyright (c) 2015 Philippe Proulx + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,20 +29,20 @@ #include -/* - * bt_ctf_trace must be the base class of _all_ CTF IR classes and is assumed - * to be the first member of all bt_ctf_* structures. +/** + * All objects publicly exposed by Babeltrace APIs must contain this structure + * as their first member. This allows the unification of all ref counting + * mechanism and may be used to provide more base functionality to all + * objects. */ -struct bt_ctf_base { +struct bt_object { struct bt_ref ref_count; }; static inline -void bt_ctf_base_init(void *obj, bt_ref_release_func_t release_func) +void bt_object_init(void *obj, bt_object_release_func release) { - struct bt_ctf_base *base = obj; - - bt_ref_init(&base->ref_count, release_func); + bt_ref_init(&((struct bt_object *) obj)->ref_count, release); } -#endif /* BABELTRACE_CTF_IR_COMMON_INTERNAL_H */ +#endif /* BABELTRACE_OBJECT_INTERNAL_H */ diff --git a/include/babeltrace/ref-internal.h b/include/babeltrace/ref-internal.h index a8eec330..224e9229 100644 --- a/include/babeltrace/ref-internal.h +++ b/include/babeltrace/ref-internal.h @@ -2,7 +2,7 @@ #define BABELTRACE_REF_INTERNAL_H /* - * Babeltrace - reference counting + * Babeltrace - Reference Counting * * Copyright 2013, 2014 Jérémie Galarneau * @@ -27,40 +27,40 @@ * SOFTWARE. */ +#include #include -struct bt_ref; - -typedef void (*bt_ref_release_func_t)(struct bt_ref *); +struct bt_object; +typedef void (*bt_object_release_func)(struct bt_object *); struct bt_ref { - long refcount; - bt_ref_release_func_t release_func; + long count; + bt_object_release_func release; }; static inline -void bt_ref_init(struct bt_ref *ref, - bt_ref_release_func_t release_func) +void bt_ref_init(struct bt_ref *ref, bt_object_release_func release) { assert(ref); - ref->refcount = 1; - ref->release_func = release_func; + ref->count = 1; + ref->release = release; } static inline void bt_ref_get(struct bt_ref *ref) { assert(ref); - ref->refcount++; + ref->count++; } static inline void bt_ref_put(struct bt_ref *ref) { assert(ref); - assert(ref->release_func); - if ((--ref->refcount) == 0) { - ref->release_func(ref); + /* Only assert if the object has opted-in for reference counting. */ + assert(!ref->release || ref->count > 0); + if ((--ref->count) == 0 && ref->release) { + ref->release((struct bt_object *) ref); } } diff --git a/include/babeltrace/ctf-ir/ref.h b/include/babeltrace/ref.h similarity index 50% rename from include/babeltrace/ctf-ir/ref.h rename to include/babeltrace/ref.h index acc89d17..a667f6f2 100644 --- a/include/babeltrace/ctf-ir/ref.h +++ b/include/babeltrace/ref.h @@ -1,11 +1,12 @@ -#ifndef BABELTRACE_CTF_IR_REF_H -#define BABELTRACE_CTF_IR_REF_H +#ifndef BABELTRACE_REF_H +#define BABELTRACE_REF_H /* - * BabelTrace - CTF IR: common reference counting + * BabelTrace: common reference counting * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx + * Copyright (c) 2015 Jérémie Galarneau * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,89 +27,67 @@ * SOFTWARE. */ -#include -#include -#include - /* - * BT_CTF_PUT: calls bt_ctf_put() with a variable, then sets this - * variable to NULL. + * BT_PUT: calls bt_put() with a variable, then sets this variable to NULL. * - * A common action with CTF IR objects is to create or get one, do - * something with it, and then put it. To avoid putting it a second time + * A common action with Babeltrace objects is to create or get one, perform + * an action with it, and then put it. To avoid putting it a second time * later (if an error occurs, for example), the variable is often reset * to NULL after putting the object it points to. Since this is so - * common, you can use the BT_CTF_PUT() macro, which does just that. + * common, the BT_PUT() macro can be used to do just that. * * It is safe to call this function with a NULL object. * - * @param obj CTF IR object. + * @param obj Babeltrace object. */ -#define BT_CTF_PUT(_obj) \ - do { \ - bt_ctf_put(_obj); \ - (_obj) = NULL; \ +#define BT_PUT(_obj) \ + do { \ + bt_put(_obj); \ + (_obj) = NULL; \ } while (0) /* - * BT_CTF_MOVE: moves the ownership of a CTF object, setting the old - * owner to NULL. + * BT_MOVE: transfers the ownership of an object, setting the old owner to NULL. * * This macro sets the variable _dst to the value of the variable _src, - * then sets _src to NULL, effectively moving the ownership of a CTF + * then sets _src to NULL, effectively moving the ownership of an * object from one variable to the other. * - * @param obj CTF IR object. + * @param obj Babeltrace object. */ -#define BT_CTF_MOVE(_dst, _src) \ - do { \ - (_dst) = (_src); \ - (_src) = NULL; \ +#define BT_MOVE(_dst, _src) \ + do { \ + (_dst) = (_src);\ + (_src) = NULL; \ } while (0) /* - * bt_ctf_get: increments the reference count of a CTF IR object. + * bt_get: increments the reference count of a Babeltrace object. * - * The same number of bt_ctf_get() and bt_ctf_put() (plus one extra - * bt_ctf_put() to release the initial reference done at creation) have - * to be done to destroy a CTF IR object. + * The same number of bt_get() and bt_put() (plus one extra bt_put() to release + * the initial reference acquired at creation) have to be performed to destroy a + * Babeltrace object. * * It is safe to call this function with a NULL object. * - * @param obj CTF IR object. + * @param obj Babeltrace object. */ -static inline -void bt_ctf_get(void *obj) -{ - if (obj) { - struct bt_ctf_base *base = obj; - - bt_ref_get(&base->ref_count); - } -} +void bt_get(void *obj); /* - * bt_ctf_put: decrements the reference count of a CTF IR object. + * bt_put: decrements the reference count of a Babeltrace object. * - * The same number of bt_ctf_get() and bt_ctf_put() (plus one extra - * bt_ctf_put() to release the initial reference done at creation) have - * to be done to destroy a CTF IR object. + * The same number of bt_get() and bt_put() (plus one extra bt_put() to release + * bt_put() to release the initial reference done at creation) have to be + * performed to destroy a Babeltrace object. * - * When the object's reference count is decremented to 0 by a call to - * bt_ctf_put(), the object is freed. + * The object is feed when its reference count is decremented to 0 by a call to + * bt_put(). * * It is safe to call this function with a NULL object. * - * @param obj CTF IR object. + * @param obj Babeltrace object. */ -static inline -void bt_ctf_put(void *obj) -{ - if (obj) { - struct bt_ctf_base *base = obj; - - bt_ref_put(&base->ref_count); - } -} +void bt_put(void *obj); -#endif /* BABELTRACE_CTF_IR_REF_H */ +#endif /* BABELTRACE_REF_H */ diff --git a/include/babeltrace/values.h b/include/babeltrace/values.h index c0a3fa45..7e7cf64a 100644 --- a/include/babeltrace/values.h +++ b/include/babeltrace/values.h @@ -52,9 +52,8 @@ * \link bt_value_map_insert() inserting a value object into a map * value object\endlink, its reference count is incremented, as well as * when getting a value object back from those structures. The - * bt_value_get() and bt_value_put() functions exist to deal with - * reference counting. Once you are done with a value object, pass it to - * bt_value_put(). + * bt_get() and bt_put() functions are to be used to handle reference counting + * Once you are done with a value object, pass it to bt_put(). * * Most functions of this API return a status code, one of the values in * #bt_value_status. @@ -75,6 +74,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -158,7 +158,7 @@ extern struct bt_value *bt_value_null; * User function type for bt_value_map_foreach(). * * \p object is a \em weak reference; you must pass it to - * bt_value_get() to get your own reference. + * bt_get() to get your own reference. * * Return \c true to continue the loop, or \c false to break it. * @@ -170,68 +170,12 @@ extern struct bt_value *bt_value_null; typedef bool (* bt_value_map_foreach_cb)(const char *key, struct bt_value *object, void *data); -/** - * Puts the value object \p _object (calls bt_value_put() on it), and - * resets the variable to \c NULL. - * - * This is something that is often done when putting a value object; - * resetting the variable to \c NULL makes sure it cannot be put a - * second time later. - * - * @param _object Value object to put - * - * @see BT_VALUE_MOVE() (moves a value object from one variable to the - * other without putting it) - */ -#define BT_VALUE_PUT(_object) \ - do { \ - bt_value_put(_object); \ - (_object) = NULL; \ - } while (0) - -/** - * Moves the value object referenced by the variable \p _src_object to - * the \p _dst_object variable, then resets \p _src_object to \c NULL. - * - * The value object's reference count is not changed. Resetting - * \p _src_object to \c NULL ensures the value object will not be put - * twice later; its ownership is indeed \em moved from the source - * variable to the destination variable. - * - * @param _src_object Source value object variable - * @param _dst_object Destination value object variable - */ -#define BT_VALUE_MOVE(_dst_object, _src_object) \ - do { \ - (_dst_object) = (_src_object); \ - (_src_object) = NULL; \ - } while (0) - -/** - * Increments the reference count of \p object. - * - * @param object Value object of which to increment the reference count - * - * @see bt_value_put() - */ -extern void bt_value_get(struct bt_value *object); - -/** - * Decrements the reference count of \p object, destroying it when this - * count reaches 0. - * - * @param object Value object of which to decrement the reference count - * - * @see bt_value_get() - */ -extern void bt_value_put(struct bt_value *object); - /** * Recursively freezes the value object \p object. * * A frozen value object cannot be modified; it is considered immutable. * Reference counting still works on a frozen value object though: you - * may pass a frozen value object to bt_value_get() and bt_value_put(). + * may pass a frozen value object to bt_get() and bt_put(). * * @param object Value object to freeze * @returns One of #bt_value_status values; if \p object @@ -810,8 +754,8 @@ extern struct bt_value *bt_value_map_get(const struct bt_value *map_obj, * value object \p map_obj. * * The value object passed to the user function is a - * weak reference: you must call bt_value_get() on it to obtain - * your own reference. + * weak reference: you must call bt_get() on it to obtain your own + * reference. * * The key passed to the user function is only valid in the scope of * this user function call. diff --git a/lib/Makefile.am b/lib/Makefile.am index 54d065fb..ef1bcf9b 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -10,7 +10,8 @@ libbabeltrace_la_SOURCES = babeltrace.c \ trace-handle.c \ trace-collection.c \ registry.c \ - values.c + values.c \ + ref.c libbabeltrace_la_LDFLAGS = -version-info $(BABELTRACE_LIBRARY_VERSION) diff --git a/lib/ref.c b/lib/ref.c new file mode 100644 index 00000000..0ac1014c --- /dev/null +++ b/lib/ref.c @@ -0,0 +1,46 @@ +/* + * ref.c: reference counting + * + * Babeltrace Library + * + * Copyright (c) 2015 Jérémie Galarneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +void bt_get(void *obj) +{ + if (obj) { + struct bt_object *base = obj; + + bt_ref_get(&base->ref_count); + } +} + +void bt_put(void *obj) +{ + if (obj) { + struct bt_object *base = obj; + + bt_ref_put(&base->ref_count); + } +} diff --git a/lib/values.c b/lib/values.c index f926ccbf..5778528b 100644 --- a/lib/values.c +++ b/lib/values.c @@ -1,5 +1,5 @@ /* - * values.c: value objects + * Values.c: value objects * * Babeltrace Library * @@ -29,8 +29,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -43,8 +44,8 @@ #define BT_VALUE_TO_MAP(_base) ((struct bt_value_map *) (_base)) struct bt_value { + struct bt_object base; enum bt_value_type type; - struct bt_ref ref_count; bool is_frozen; }; @@ -87,7 +88,7 @@ struct bt_value_map { }; static -void bt_value_destroy(struct bt_ref *ref_count); +void bt_value_destroy(struct bt_object *obj); static void bt_value_string_destroy(struct bt_value *object) @@ -180,23 +181,23 @@ struct bt_value *bt_value_array_copy(const struct bt_value *array_obj) struct bt_value *element_obj = bt_value_array_get(array_obj, i); if (!element_obj) { - BT_VALUE_PUT(copy_obj); + BT_PUT(copy_obj); goto end; } element_obj_copy = bt_value_copy(element_obj); - BT_VALUE_PUT(element_obj); + BT_PUT(element_obj); if (!element_obj_copy) { - BT_VALUE_PUT(copy_obj); + BT_PUT(copy_obj); goto end; } ret = bt_value_array_append(copy_obj, element_obj_copy); - BT_VALUE_PUT(element_obj_copy); + BT_PUT(element_obj_copy); if (ret) { - BT_VALUE_PUT(copy_obj); + BT_PUT(copy_obj); goto end; } } @@ -230,15 +231,15 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj) element_obj_copy = bt_value_copy(element_obj); if (!element_obj_copy) { - BT_VALUE_PUT(copy_obj); + BT_PUT(copy_obj); goto end; } ret = bt_value_map_insert(copy_obj, key_str, element_obj_copy); - BT_VALUE_PUT(element_obj_copy); + BT_PUT(element_obj_copy); if (ret) { - BT_VALUE_PUT(copy_obj); + BT_PUT(copy_obj); goto end; } } @@ -324,14 +325,14 @@ bool bt_value_array_compare(const struct bt_value *object_a, element_obj_b = bt_value_array_get(object_b, i); if (!bt_value_compare(element_obj_a, element_obj_b)) { - BT_VALUE_PUT(element_obj_a); - BT_VALUE_PUT(element_obj_b); + BT_PUT(element_obj_a); + BT_PUT(element_obj_b); ret = false; goto end; } - BT_VALUE_PUT(element_obj_a); - BT_VALUE_PUT(element_obj_b); + BT_PUT(element_obj_a); + BT_PUT(element_obj_b); } end: @@ -361,12 +362,12 @@ bool bt_value_map_compare(const struct bt_value *object_a, element_obj_b = bt_value_map_get(object_b, key_str); if (!bt_value_compare(element_obj_a, element_obj_b)) { - BT_VALUE_PUT(element_obj_b); + BT_PUT(element_obj_b); ret = false; goto end; } - BT_VALUE_PUT(element_obj_b); + BT_PUT(element_obj_b); } end: @@ -437,38 +438,22 @@ void (* const freeze_funcs[])(struct bt_value *) = { }; static -void bt_value_destroy(struct bt_ref *ref_count) +void bt_value_destroy(struct bt_object *obj) { - struct bt_value *object; + struct bt_value *value; - object = container_of(ref_count, struct bt_value, ref_count); - assert(object->type != BT_VALUE_TYPE_UNKNOWN); + value = container_of(obj, struct bt_value, base); + assert(value->type != BT_VALUE_TYPE_UNKNOWN); - if (bt_value_is_null(object)) { + if (bt_value_is_null(value)) { return; } - if (destroy_funcs[object->type]) { - destroy_funcs[object->type](object); + if (destroy_funcs[value->type]) { + destroy_funcs[value->type](value); } - g_free(object); -} - -void bt_value_get(struct bt_value *object) -{ - if (object && !bt_value_is_null(object)) { - bt_ref_get(&object->ref_count); - } - - return; -} - -void bt_value_put(struct bt_value *object) -{ - if (object && !bt_value_is_null(object)) { - bt_ref_put(&object->ref_count); - } + g_free(value); } enum bt_value_status bt_value_freeze(struct bt_value *object) @@ -507,7 +492,7 @@ struct bt_value bt_value_create_base(enum bt_value_type type) base.type = type; base.is_frozen = false; - bt_ref_init(&base.ref_count, bt_value_destroy); + bt_object_init(&base, bt_value_destroy); return base; } @@ -622,7 +607,7 @@ struct bt_value *bt_value_array_create(void) array_obj->base = bt_value_create_base(BT_VALUE_TYPE_ARRAY); array_obj->garray = g_ptr_array_new_full(0, - (GDestroyNotify) bt_value_put); + (GDestroyNotify) bt_put); if (!array_obj->garray) { g_free(array_obj); @@ -646,7 +631,7 @@ struct bt_value *bt_value_map_create(void) map_obj->base = bt_value_create_base(BT_VALUE_TYPE_MAP); map_obj->ght = g_hash_table_new_full(g_direct_hash, g_direct_equal, - NULL, (GDestroyNotify) bt_value_put); + NULL, (GDestroyNotify) bt_put); if (!map_obj->ght) { g_free(map_obj); @@ -855,7 +840,7 @@ struct bt_value *bt_value_array_get(const struct bt_value *array_obj, } ret = g_ptr_array_index(typed_array_obj->garray, index); - bt_value_get(ret); + bt_get(ret); end: return ret; @@ -879,7 +864,7 @@ enum bt_value_status bt_value_array_append(struct bt_value *array_obj, } g_ptr_array_add(typed_array_obj->garray, element_obj); - bt_value_get(element_obj); + bt_get(element_obj); end: return ret; @@ -893,7 +878,7 @@ enum bt_value_status bt_value_array_append_bool(struct bt_value *array_obj, bool_obj = bt_value_bool_create_init(val); ret = bt_value_array_append(array_obj, bool_obj); - bt_value_put(bool_obj); + bt_put(bool_obj); return ret; } @@ -906,7 +891,7 @@ enum bt_value_status bt_value_array_append_integer( integer_obj = bt_value_integer_create_init(val); ret = bt_value_array_append(array_obj, integer_obj); - bt_value_put(integer_obj); + bt_put(integer_obj); return ret; } @@ -919,7 +904,7 @@ enum bt_value_status bt_value_array_append_float(struct bt_value *array_obj, float_obj = bt_value_float_create_init(val); ret = bt_value_array_append(array_obj, float_obj); - bt_value_put(float_obj); + bt_put(float_obj); return ret; } @@ -932,7 +917,7 @@ enum bt_value_status bt_value_array_append_string(struct bt_value *array_obj, string_obj = bt_value_string_create_init(val); ret = bt_value_array_append(array_obj, string_obj); - bt_value_put(string_obj); + bt_put(string_obj); return ret; } @@ -944,7 +929,7 @@ enum bt_value_status bt_value_array_append_array(struct bt_value *array_obj) empty_array_obj = bt_value_array_create(); ret = bt_value_array_append(array_obj, empty_array_obj); - bt_value_put(empty_array_obj); + bt_put(empty_array_obj); return ret; } @@ -956,7 +941,7 @@ enum bt_value_status bt_value_array_append_map(struct bt_value *array_obj) map_obj = bt_value_map_create(); ret = bt_value_array_append(array_obj, map_obj); - bt_value_put(map_obj); + bt_put(map_obj); return ret; } @@ -979,9 +964,9 @@ enum bt_value_status bt_value_array_set(struct bt_value *array_obj, goto end; } - bt_value_put(g_ptr_array_index(typed_array_obj->garray, index)); + bt_put(g_ptr_array_index(typed_array_obj->garray, index)); g_ptr_array_index(typed_array_obj->garray, index) = element_obj; - bt_value_get(element_obj); + bt_get(element_obj); end: return ret; @@ -1024,7 +1009,7 @@ struct bt_value *bt_value_map_get(const struct bt_value *map_obj, ret = g_hash_table_lookup(typed_map_obj->ght, GUINT_TO_POINTER(quark)); if (ret) { - bt_value_get(ret); + bt_get(ret); } end: @@ -1070,7 +1055,7 @@ enum bt_value_status bt_value_map_insert(struct bt_value *map_obj, quark = g_quark_from_string(key); g_hash_table_insert(typed_map_obj->ght, GUINT_TO_POINTER(quark), element_obj); - bt_value_get(element_obj); + bt_get(element_obj); end: return ret; @@ -1084,7 +1069,7 @@ enum bt_value_status bt_value_map_insert_bool(struct bt_value *map_obj, bool_obj = bt_value_bool_create_init(val); ret = bt_value_map_insert(map_obj, key, bool_obj); - bt_value_put(bool_obj); + bt_put(bool_obj); return ret; } @@ -1097,7 +1082,7 @@ enum bt_value_status bt_value_map_insert_integer(struct bt_value *map_obj, integer_obj = bt_value_integer_create_init(val); ret = bt_value_map_insert(map_obj, key, integer_obj); - bt_value_put(integer_obj); + bt_put(integer_obj); return ret; } @@ -1110,7 +1095,7 @@ enum bt_value_status bt_value_map_insert_float(struct bt_value *map_obj, float_obj = bt_value_float_create_init(val); ret = bt_value_map_insert(map_obj, key, float_obj); - bt_value_put(float_obj); + bt_put(float_obj); return ret; } @@ -1123,7 +1108,7 @@ enum bt_value_status bt_value_map_insert_string(struct bt_value *map_obj, string_obj = bt_value_string_create_init(val); ret = bt_value_map_insert(map_obj, key, string_obj); - bt_value_put(string_obj); + bt_put(string_obj); return ret; } @@ -1136,7 +1121,7 @@ enum bt_value_status bt_value_map_insert_array(struct bt_value *map_obj, array_obj = bt_value_array_create(); ret = bt_value_map_insert(map_obj, key, array_obj); - bt_value_put(array_obj); + bt_put(array_obj); return ret; } @@ -1149,7 +1134,7 @@ enum bt_value_status bt_value_map_insert_map(struct bt_value *map_obj, empty_map_obj = bt_value_map_create(); ret = bt_value_map_insert(map_obj, key, empty_map_obj); - bt_value_put(empty_map_obj); + bt_put(empty_map_obj); return ret; } diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index 4f563960..284f9e68 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -32,14 +32,14 @@ void test_null(void) ok(bt_value_null, "bt_value_null is not NULL"); ok(bt_value_is_null(bt_value_null), "bt_value_null is a null value object"); - bt_value_get(bt_value_null); + bt_get(bt_value_null); pass("getting bt_value_null does not cause a crash"); - bt_value_put(bt_value_null); + bt_put(bt_value_null); pass("putting bt_value_null does not cause a crash"); - bt_value_get(NULL); + bt_get(NULL); pass("getting NULL does not cause a crash"); - bt_value_put(NULL); + bt_put(NULL); pass("putting NULL does not cause a crash"); ok(bt_value_get_type(NULL) == BT_VALUE_TYPE_UNKNOWN, @@ -77,7 +77,7 @@ void test_bool(void) ret = bt_value_bool_get(obj, &value); ok(!ret && value, "bt_value_bool_set() works"); - BT_VALUE_PUT(obj); + BT_PUT(obj); pass("putting an existing boolean value object does not cause a crash") value = false; @@ -96,7 +96,7 @@ void test_bool(void) ok(!ret && value, "bt_value_bool_set() does not alter a frozen floating point number value object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); } static @@ -129,7 +129,7 @@ void test_integer(void) ret = bt_value_integer_get(obj, &value); ok(!ret && value == -98765, "bt_value_integer_set() works"); - BT_VALUE_PUT(obj); + BT_PUT(obj); pass("putting an existing integer value object does not cause a crash") obj = bt_value_integer_create_init(321456987); @@ -147,7 +147,7 @@ void test_integer(void) ok(!ret && value == 321456987, "bt_value_integer_set() does not alter a frozen integer value object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); } static @@ -181,7 +181,7 @@ void test_float(void) ret = bt_value_float_get(obj, &value); ok(!ret && value == -3.1416, "bt_value_float_set() works"); - BT_VALUE_PUT(obj); + BT_PUT(obj); pass("putting an existing floating point number value object does not cause a crash") obj = bt_value_float_create_init(33.1649758); @@ -199,7 +199,7 @@ void test_float(void) ok(!ret && value == 33.1649758, "bt_value_float_set() does not alter a frozen floating point number value object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); } static @@ -236,7 +236,7 @@ void test_string(void) ok(!ret && value && !strcmp(value, "hello worldz"), "bt_value_string_get() works"); - BT_VALUE_PUT(obj); + BT_PUT(obj); pass("putting an existing string value object does not cause a crash") obj = bt_value_string_create_init(NULL); @@ -256,7 +256,7 @@ void test_string(void) ok(!ret && value && !strcmp(value, "initial value"), "bt_value_string_set() does not alter a frozen string value object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); } static @@ -288,13 +288,13 @@ void test_array(void) obj = bt_value_integer_create_init(345); ret = bt_value_array_append(array_obj, obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_float_create_init(-17.45); ret |= bt_value_array_append(array_obj, obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_bool_create_init(true); ret |= bt_value_array_append(array_obj, obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); ret |= bt_value_array_append(array_obj, bt_value_null); ok(!ret, "bt_value_array_append() succeeds"); ok(bt_value_array_size(array_obj) == 4, @@ -314,21 +314,21 @@ void test_array(void) ret = bt_value_integer_get(obj, &int_value); ok(!ret && int_value == 345, "bt_value_array_get() returns an value object with the appropriate value (integer)"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 1); ok(obj && bt_value_is_float(obj), "bt_value_array_get() returns an value object with the appropriate type (floating point number)"); ret = bt_value_float_get(obj, &float_value); ok(!ret && float_value == -17.45, "bt_value_array_get() returns an value object with the appropriate value (floating point number)"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 2); ok(obj && bt_value_is_bool(obj), "bt_value_array_get() returns an value object with the appropriate type (boolean)"); ret = bt_value_bool_get(obj, &bool_value); ok(!ret && bool_value, "bt_value_array_get() returns an value object with the appropriate value (boolean)"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 3); ok(obj == bt_value_null, "bt_value_array_get() returns an value object with the appropriate type (null)"); @@ -345,7 +345,7 @@ void test_array(void) assert(obj); ok(!bt_value_array_set(array_obj, 2, obj), "bt_value_array_set() succeeds"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 2); ok(obj && bt_value_is_integer(obj), "bt_value_array_set() inserts an value object with the appropriate type"); @@ -353,7 +353,7 @@ void test_array(void) assert(!ret); ok(int_value == 1001, "bt_value_array_set() inserts an value object with the appropriate value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); ret = bt_value_array_append_bool(array_obj, false); ok(!ret, "bt_value_array_append_bool() succeeds"); @@ -394,40 +394,40 @@ void test_array(void) ret = bt_value_bool_get(obj, &bool_value); ok(!ret && !bool_value, "bt_value_array_append_bool() appends the appropriate value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 5); ok(obj && bt_value_is_integer(obj), "bt_value_array_append_integer() appends an integer value object"); ret = bt_value_integer_get(obj, &int_value); ok(!ret && int_value == 98765, "bt_value_array_append_integer() appends the appropriate value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 6); ok(obj && bt_value_is_float(obj), "bt_value_array_append_float() appends a floating point number value object"); ret = bt_value_float_get(obj, &float_value); ok(!ret && float_value == 2.49578, "bt_value_array_append_float() appends the appropriate value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 7); ok(obj && bt_value_is_string(obj), "bt_value_array_append_string() appends a string value object"); ret = bt_value_string_get(obj, &string_value); ok(!ret && string_value && !strcmp(string_value, "bt_value"), "bt_value_array_append_string() appends the appropriate value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 8); ok(obj && bt_value_is_array(obj), "bt_value_array_append_array() appends an array value object"); ok(bt_value_array_is_empty(obj), "bt_value_array_append_array() an empty array value object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_array_get(array_obj, 9); ok(obj && bt_value_is_map(obj), "bt_value_array_append_map() appends a map value object"); ok(bt_value_map_is_empty(obj), "bt_value_array_append_map() an empty map value object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); assert(!bt_value_freeze(array_obj)); ok(bt_value_array_append(array_obj, bt_value_null) == @@ -461,9 +461,9 @@ void test_array(void) assert(obj); ok(bt_value_float_set(obj, 14.52) == BT_VALUE_STATUS_FROZEN, "freezing an array value object also freezes its elements"); - BT_VALUE_PUT(obj); + BT_PUT(obj); - BT_VALUE_PUT(array_obj); + BT_PUT(array_obj); pass("putting an existing array value object does not cause a crash") } @@ -678,13 +678,13 @@ void test_map(void) obj = bt_value_integer_create_init(19457); ret = bt_value_map_insert(map_obj, "int", obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_float_create_init(5.444); ret |= bt_value_map_insert(map_obj, "float", obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_bool_create(); ret |= bt_value_map_insert(map_obj, "bool", obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); ret |= bt_value_map_insert(map_obj, "null", bt_value_null); ok(!ret, "bt_value_map_insert() succeeds"); ok(bt_value_map_size(map_obj) == 4, @@ -692,7 +692,7 @@ void test_map(void) obj = bt_value_bool_create_init(true); ret = bt_value_map_insert(map_obj, "bool", obj); - BT_VALUE_PUT(obj); + BT_PUT(obj); ok(!ret, "bt_value_map_insert() accepts an existing key"); obj = bt_value_map_get(map_obj, NULL); @@ -708,14 +708,14 @@ void test_map(void) ret = bt_value_float_get(obj, &float_value); ok(!ret && float_value == 5.444, "bt_value_map_get() returns an value object with the appropriate value (float)"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_map_get(map_obj, "int"); ok(obj && bt_value_is_integer(obj), "bt_value_map_get() returns an value object with the appropriate type (integer)"); ret = bt_value_integer_get(obj, &int_value); ok(!ret && int_value == 19457, "bt_value_map_get() returns an value object with the appropriate value (integer)"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_map_get(map_obj, "null"); ok(obj && bt_value_is_null(obj), "bt_value_map_get() returns an value object with the appropriate type (null)"); @@ -725,7 +725,7 @@ void test_map(void) ret = bt_value_bool_get(obj, &bool_value); ok(!ret && bool_value, "bt_value_map_get() returns an value object with the appropriate value (boolean)"); - BT_VALUE_PUT(obj); + BT_PUT(obj); ret = bt_value_map_insert_bool(map_obj, "bool2", true); ok(!ret, "bt_value_map_insert_bool() succeeds"); @@ -828,7 +828,7 @@ void test_map(void) ok(bt_value_map_size(map_obj) == 10, "appending to a frozen map value object does not change its size"); - BT_VALUE_PUT(map_obj); + BT_PUT(map_obj); pass("putting an existing map value object does not cause a crash") } @@ -870,9 +870,9 @@ void test_compare_bool(void) ok(bt_value_compare(bool1, bool3), "integer value objects are equivalent (false and false)"); - BT_VALUE_PUT(bool1); - BT_VALUE_PUT(bool2); - BT_VALUE_PUT(bool3); + BT_PUT(bool1); + BT_PUT(bool2); + BT_PUT(bool3); } static @@ -890,9 +890,9 @@ void test_compare_integer(void) ok(bt_value_compare(int1, int3), "integer value objects are equivalent (10 and 10)"); - BT_VALUE_PUT(int1); - BT_VALUE_PUT(int2); - BT_VALUE_PUT(int3); + BT_PUT(int1); + BT_PUT(int2); + BT_PUT(int3); } static @@ -911,9 +911,9 @@ void test_compare_float(void) ok(bt_value_compare(float1, float3), "floating point number value objects are equivalent (17.38 and 17.38)"); - BT_VALUE_PUT(float1); - BT_VALUE_PUT(float2); - BT_VALUE_PUT(float3); + BT_PUT(float1); + BT_PUT(float2); + BT_PUT(float3); } static @@ -932,9 +932,9 @@ void test_compare_string(void) ok(bt_value_compare(string1, string3), "string value objects are equivalent (\"hello\" and \"hello\")"); - BT_VALUE_PUT(string1); - BT_VALUE_PUT(string2); - BT_VALUE_PUT(string3); + BT_PUT(string1); + BT_PUT(string2); + BT_PUT(string3); } static @@ -969,9 +969,9 @@ void test_compare_array(void) ok(bt_value_compare(array1, array3), "array value objects are equivalent ([23, 14.2, false] and [23, 14.2, false])"); - BT_VALUE_PUT(array1); - BT_VALUE_PUT(array2); - BT_VALUE_PUT(array3); + BT_PUT(array1); + BT_PUT(array2); + BT_PUT(array3); } static @@ -1006,9 +1006,9 @@ void test_compare_map(void) ok(bt_value_compare(map1, map3), "map value objects are equivalent"); - BT_VALUE_PUT(map1); - BT_VALUE_PUT(map2); - BT_VALUE_PUT(map3); + BT_PUT(map1); + BT_PUT(map2); + BT_PUT(map3); } static @@ -1092,18 +1092,18 @@ void test_copy(void) ok(bt_value_compare(map_obj, map_copy_obj), "source and destination value objects have the same content"); - BT_VALUE_PUT(bool_copy_obj); - BT_VALUE_PUT(integer_copy_obj); - BT_VALUE_PUT(float_copy_obj); - BT_VALUE_PUT(string_copy_obj); - BT_VALUE_PUT(array_copy_obj); - BT_VALUE_PUT(map_copy_obj); - BT_VALUE_PUT(bool_obj); - BT_VALUE_PUT(integer_obj); - BT_VALUE_PUT(float_obj); - BT_VALUE_PUT(string_obj); - BT_VALUE_PUT(array_obj); - BT_VALUE_PUT(map_obj); + BT_PUT(bool_copy_obj); + BT_PUT(integer_copy_obj); + BT_PUT(float_copy_obj); + BT_PUT(string_copy_obj); + BT_PUT(array_copy_obj); + BT_PUT(map_copy_obj); + BT_PUT(bool_obj); + BT_PUT(integer_obj); + BT_PUT(float_obj); + BT_PUT(string_obj); + BT_PUT(array_obj); + BT_PUT(map_obj); } static @@ -1114,17 +1114,17 @@ void test_macros(void) struct bt_value *dst; assert(obj); - BT_VALUE_PUT(obj); - ok(!obj, "BT_VALUE_PUT() resets the variable to NULL"); + BT_PUT(obj); + ok(!obj, "BT_PUT() resets the variable to NULL"); obj = bt_value_bool_create(); assert(obj); src = obj; - BT_VALUE_MOVE(dst, src); - ok(!src, "BT_VALUE_MOVE() resets the source variable to NULL"); - ok(dst == obj, "BT_VALUE_MOVE() moves the ownership"); + BT_MOVE(dst, src); + ok(!src, "BT_MOVE() resets the source variable to NULL"); + ok(dst == obj, "BT_MOVE() moves the ownership"); - BT_VALUE_PUT(dst); + BT_PUT(dst); } static @@ -1150,7 +1150,7 @@ void test_freeze(void) ok(bt_value_is_frozen(obj), "bt_value_is_frozen() returns true with a frozen value object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); } int main(void) diff --git a/tests/lib/test_ctf_writer.c b/tests/lib/test_ctf_writer.c index db1eeab5..e50b213d 100644 --- a/tests/lib/test_ctf_writer.c +++ b/tests/lib/test_ctf_writer.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -299,8 +299,8 @@ void event_copy_tests(struct bt_ctf_event *event) copy_event_class = bt_ctf_event_get_class(copy); ok(orig_event_class == copy_event_class, "original and copied events share the same event class pointer"); - bt_ctf_put(orig_event_class); - bt_ctf_put(copy_event_class); + bt_put(orig_event_class); + bt_put(copy_event_class); /* validate stream */ orig_stream = bt_ctf_event_get_stream(event); @@ -312,8 +312,8 @@ void event_copy_tests(struct bt_ctf_event *event) ok(orig_stream == copy_stream, "original and copied events share the same stream pointer"); } - bt_ctf_put(orig_stream); - bt_ctf_put(copy_stream); + bt_put(orig_stream); + bt_put(copy_stream); /* header */ orig_field = bt_ctf_event_get_header(event); @@ -326,8 +326,8 @@ void event_copy_tests(struct bt_ctf_event *event) "original and copied events headers are different pointers"); } - bt_ctf_put(orig_field); - bt_ctf_put(copy_field); + bt_put(orig_field); + bt_put(copy_field); /* context */ orig_field = bt_ctf_event_get_event_context(event); @@ -340,8 +340,8 @@ void event_copy_tests(struct bt_ctf_event *event) "original and copied events contexts are different pointers"); } - bt_ctf_put(orig_field); - bt_ctf_put(copy_field); + bt_put(orig_field); + bt_put(copy_field); /* payload */ orig_field = bt_ctf_event_get_payload_field(event); @@ -354,10 +354,10 @@ void event_copy_tests(struct bt_ctf_event *event) "original and copied events payloads are different pointers"); } - bt_ctf_put(orig_field); - bt_ctf_put(copy_field); + bt_put(orig_field); + bt_put(copy_field); - bt_ctf_put(copy); + bt_put(copy); } void append_simple_event(struct bt_ctf_stream_class *stream_class, @@ -412,7 +412,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, ok(!bt_ctf_field_type_enumeration_get_container_type(NULL), "bt_ctf_field_type_enumeration_get_container_type handles NULL correctly"); ok(!bt_ctf_field_type_enumeration_create(enum_type), "bt_ctf_field_enumeration_type_create rejects non-integer container field types"); - bt_ctf_put(returned_type); + bt_put(returned_type); bt_ctf_field_type_set_alignment(float_type, 32); ok(bt_ctf_field_type_get_alignment(NULL) < 0, @@ -560,7 +560,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, returned_type = bt_ctf_event_class_get_context_type(simple_event_class); ok(returned_type == event_context_type, "bt_ctf_event_class_get_context_type returns the appropriate type"); - bt_ctf_put(returned_type); + bt_put(returned_type); bt_ctf_stream_class_add_event_class(stream_class, simple_event_class); @@ -575,7 +575,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, ret_event_class = bt_ctf_stream_class_get_event_class(stream_class, 0); ok(ret_event_class == simple_event_class, "bt_ctf_stream_class_get_event_class returns the correct event class"); - bt_ctf_put(ret_event_class); + bt_put(ret_event_class); ok(!bt_ctf_stream_class_get_event_class_by_id(NULL, 0), "bt_ctf_stream_class_get_event_class_by_id handles NULL correctly"); ok(!bt_ctf_stream_class_get_event_class_by_id(stream_class, 2), @@ -584,7 +584,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, bt_ctf_stream_class_get_event_class_by_id(stream_class, 13); ok(ret_event_class == simple_event_class, "bt_ctf_stream_class_get_event_class_by_id returns a correct event class"); - bt_ctf_put(ret_event_class); + bt_put(ret_event_class); ok(bt_ctf_stream_class_get_event_class_by_name(NULL, "some event name") == NULL, "bt_ctf_stream_class_get_event_class_by_name handles a NULL stream class correctly"); @@ -595,7 +595,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, ret_event_class = bt_ctf_stream_class_get_event_class_by_name(stream_class, "Simple Event"); ok(ret_event_class == simple_event_class, "bt_ctf_stream_class_get_event_class_by_name returns a correct event class"); - bt_ctf_put(ret_event_class); + bt_put(ret_event_class); simple_event = bt_ctf_event_create(simple_event_class); ok(simple_event, @@ -606,7 +606,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, ret_clock = bt_ctf_event_get_clock(simple_event); ok(ret_clock == clock, "bt_ctf_event_get_clock returns a correct clock"); - bt_ctf_put(clock); + bt_put(clock); integer_field = bt_ctf_field_create(uint_12_type); bt_ctf_field_unsigned_integer_set_value(integer_field, 42); @@ -697,7 +697,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, "packet_size"); ok(packet_context_field, "Packet context contains the default packet_size field."); - bt_ctf_put(packet_context_field); + bt_put(packet_context_field); packet_context_field = bt_ctf_field_structure_get_field(packet_context, "custom_packet_context_field"); ok(bt_ctf_field_unsigned_integer_set_value(packet_context_field, 8) == 0, @@ -713,27 +713,27 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class, ok(bt_ctf_stream_flush(stream) == 0, "Flush trace stream with one event"); - bt_ctf_put(simple_event_class); - bt_ctf_put(simple_event); - bt_ctf_put(uint_12_type); - bt_ctf_put(int_64_type); - bt_ctf_put(float_type); - bt_ctf_put(enum_type); - bt_ctf_put(enum_type_unsigned); - bt_ctf_put(returned_type); - bt_ctf_put(event_context_type); - bt_ctf_put(integer_field); - bt_ctf_put(float_field); - bt_ctf_put(enum_field); - bt_ctf_put(enum_field_unsigned); - bt_ctf_put(enum_container_field); - bt_ctf_put(enum_container_field_unsigned); - bt_ctf_put(packet_context); - bt_ctf_put(packet_context_field); - bt_ctf_put(stream_event_context); - bt_ctf_put(stream_event_context_field); - bt_ctf_put(event_context); - bt_ctf_put(event_context_field); + bt_put(simple_event_class); + bt_put(simple_event); + bt_put(uint_12_type); + bt_put(int_64_type); + bt_put(float_type); + bt_put(enum_type); + bt_put(enum_type_unsigned); + bt_put(returned_type); + bt_put(event_context_type); + bt_put(integer_field); + bt_put(float_field); + bt_put(enum_field); + bt_put(enum_field_unsigned); + bt_put(enum_container_field); + bt_put(enum_container_field_unsigned); + bt_put(packet_context); + bt_put(packet_context_field); + bt_put(stream_event_context); + bt_put(stream_event_context_field); + bt_put(event_context); + bt_put(event_context_field); } void append_complex_event(struct bt_ctf_stream_class *stream_class, @@ -814,7 +814,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, array_type); ok(ret_field_type == int_16_type, "bt_ctf_field_type_array_get_element_type returns the correct type"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ok(bt_ctf_field_type_array_get_length(NULL) < 0, "bt_ctf_field_type_array_get_length handles NULL correctly"); @@ -866,7 +866,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ret_field_type = bt_ctf_field_type_variant_get_tag_type(variant_type); ok(ret_field_type == enum_variant_type, "bt_ctf_field_type_variant_get_tag_type returns a correct tag type"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ok(bt_ctf_field_type_variant_get_tag_name(NULL) == NULL, "bt_ctf_field_type_variant_get_tag_name handles NULL correctly"); @@ -883,7 +883,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, variant_type, "INT16_TYPE"); ok(ret_field_type == int_16_type, "bt_ctf_field_type_variant_get_field_type_by_name returns a correct field type"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ok(bt_ctf_field_type_variant_get_field_count(NULL) < 0, "bt_ctf_field_type_variant_get_field_count handles NULL correctly"); @@ -894,7 +894,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, "bt_ctf_field_type_variant_get_field handles a NULL type correctly"); ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) == 0, "bt_ctf_field_type_variant_get_field handles a NULL field name correctly"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) == 0, "bt_ctf_field_type_variant_get_field handles a NULL field type correctly"); ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 200) < 0, @@ -905,7 +905,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, "bt_ctf_field_type_variant_get_field returns a correct field name"); ok(ret_field_type == int_16_type, "bt_ctf_field_type_variant_get_field returns a correct field type"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); bt_ctf_field_type_structure_add_field(complex_structure_type, enum_variant_type, "variant_selector"); @@ -971,13 +971,13 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ret &= bt_ctf_event_class_set_attribute(event_class, "model.emf.uri", obj); ok(ret, "bt_ctf_event_class_set_attribute cannot set \"name\" or \"model.emf.uri\" to an integer value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_integer_create_init(5); assert(obj); ok(!bt_ctf_event_class_set_attribute(event_class, "loglevel", obj), "bt_ctf_event_class_set_attribute succeeds in setting the \"loglevel\" attribute"); - BT_VALUE_PUT(obj); + BT_PUT(obj); ok(!bt_ctf_event_class_get_attribute_value_by_name(NULL, "loglevel"), "bt_ctf_event_class_get_attribute_value_by_name handles a NULL event class correctly"); ok(!bt_ctf_event_class_get_attribute_value_by_name(event_class, NULL), @@ -990,7 +990,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ret = bt_value_integer_get(obj, &int64_value); ok(obj && !ret && int64_value == 5, "bt_ctf_event_class_get_attribute_value_by_name returns the correct value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); assert(obj = bt_value_string_create_init("nu name")); assert(!bt_ctf_event_class_set_attribute(event_class, "name", obj)); @@ -1001,11 +1001,11 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ret &= bt_ctf_event_class_set_attribute(event_class, "loglevel", obj); ok(ret, "bt_ctf_event_class_set_attribute cannot set \"id\" or \"loglevel\" to a string value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_value_string_create_init("http://kernel.org/"); assert(obj); assert(!bt_ctf_event_class_set_attribute(event_class, "model.emf.uri", obj)); - BT_VALUE_PUT(obj); + BT_PUT(obj); ok(bt_ctf_event_class_get_attribute_count(NULL), "bt_ctf_event_class_get_attribute_count handles a NULL event class"); @@ -1052,7 +1052,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, attrs_count.unknown++; } - BT_VALUE_PUT(obj); + BT_PUT(obj); } ok(attrs_count.unknown == 0, "event class has no unknown attributes"); @@ -1071,7 +1071,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ret_stream_class = bt_ctf_event_class_get_stream_class(event_class); ok(ret_stream_class == stream_class, "bt_ctf_event_class_get_stream_class returns the correct stream class"); - bt_ctf_put(ret_stream_class); + bt_put(ret_stream_class); ok(bt_ctf_event_class_get_field_count(NULL) < 0, "bt_ctf_event_class_get_field_count handles NULL correctly"); @@ -1084,7 +1084,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ok(bt_ctf_event_class_get_field(event_class, NULL, &ret_field_type, 0) == 0, "bt_ctf_event_class_get_field handles a NULL field name correctly"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ok(bt_ctf_event_class_get_field(event_class, &ret_string, NULL, 0) == 0, "bt_ctf_event_class_get_field handles a NULL field type correctly"); @@ -1096,7 +1096,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, "bt_ctf_event_class_get_field returns a field"); ok(ret_field_type == uint_35_type, "bt_ctf_event_class_get_field returns a correct field type"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ok(!strcmp(ret_string, "uint_35"), "bt_ctf_event_class_get_field returns a correct field name"); ok(bt_ctf_event_class_get_field_by_name(NULL, "") == NULL, @@ -1109,7 +1109,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, "complex_structure"); ok(ret_field_type == complex_structure_type, "bt_ctf_event_class_get_field_by_name returns a correct field type"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); event = bt_ctf_event_create(event_class); ok(event, "Instanciate a complex event"); @@ -1119,7 +1119,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ret_event_class = bt_ctf_event_get_class(event); ok(ret_event_class == event_class, "bt_ctf_event_get_class returns the correct event class"); - bt_ctf_put(ret_event_class); + bt_put(ret_event_class); uint_35_field = bt_ctf_event_get_payload(event, "uint_35"); if (!uint_35_field) { @@ -1140,7 +1140,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ok(bt_ctf_field_signed_integer_get_value(uint_35_field, &ret_signed_int) < 0, "bt_ctf_field_signed_integer_get_value fails on an unsigned field"); - bt_ctf_put(uint_35_field); + bt_put(uint_35_field); int_16_field = bt_ctf_event_get_payload(event, "int_16"); bt_ctf_field_signed_integer_set_value(int_16_field, -12345); @@ -1156,7 +1156,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ok(bt_ctf_field_unsigned_integer_get_value(int_16_field, &ret_unsigned_int) < 0, "bt_ctf_field_unsigned_integer_get_value fails on a signed field"); - bt_ctf_put(int_16_field); + bt_put(int_16_field); complex_structure_field = bt_ctf_event_get_payload(event, "complex_structure"); @@ -1168,10 +1168,10 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, inner_structure_field = bt_ctf_field_structure_get_field_by_index( complex_structure_field, 3); ret_field_type = bt_ctf_field_get_type(inner_structure_field); - bt_ctf_put(inner_structure_field); + bt_put(inner_structure_field); ok(ret_field_type == inner_structure_type, "bt_ctf_field_structure_get_field_by_index returns a correct field"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); inner_structure_field = bt_ctf_field_structure_get_field( complex_structure_field, "inner_structure"); @@ -1194,7 +1194,7 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, int_16_field = bt_ctf_field_variant_get_field(variant_field, enum_variant_field); bt_ctf_field_signed_integer_set_value(int_16_field, -200); - bt_ctf_put(int_16_field); + bt_put(int_16_field); ok(!bt_ctf_field_string_get_value(a_string_field), "bt_ctf_field_string_get_value returns NULL on an unset field"); bt_ctf_field_string_set_value(a_string_field, @@ -1252,14 +1252,14 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, int_16_field = bt_ctf_field_sequence_get_field( a_sequence_field, i); bt_ctf_field_signed_integer_set_value(int_16_field, 4 - i); - bt_ctf_put(int_16_field); + bt_put(int_16_field); } for (i = 0; i < ARRAY_TEST_LENGTH; i++) { int_16_field = bt_ctf_field_array_get_field( an_array_field, i); bt_ctf_field_signed_integer_set_value(int_16_field, i); - bt_ctf_put(int_16_field); + bt_put(int_16_field); } bt_ctf_clock_set_time(clock, ++current_time); @@ -1278,31 +1278,31 @@ void append_complex_event(struct bt_ctf_stream_class *stream_class, ok(bt_ctf_stream_flush(stream) == 0, "Flush a stream containing a complex event"); - bt_ctf_put(uint_35_field); - bt_ctf_put(a_string_field); - bt_ctf_put(inner_structure_field); - bt_ctf_put(complex_structure_field); - bt_ctf_put(a_sequence_field); - bt_ctf_put(an_array_field); - bt_ctf_put(enum_variant_field); - bt_ctf_put(enum_container_field); - bt_ctf_put(variant_field); - bt_ctf_put(ret_field); - bt_ctf_put(packet_context_field); - bt_ctf_put(packet_context); - bt_ctf_put(uint_35_type); - bt_ctf_put(int_16_type); - bt_ctf_put(string_type); - bt_ctf_put(sequence_type); - bt_ctf_put(array_type); - bt_ctf_put(inner_structure_type); - bt_ctf_put(complex_structure_type); - bt_ctf_put(uint_3_type); - bt_ctf_put(enum_variant_type); - bt_ctf_put(variant_type); - bt_ctf_put(ret_field_type); - bt_ctf_put(event_class); - bt_ctf_put(event); + bt_put(uint_35_field); + bt_put(a_string_field); + bt_put(inner_structure_field); + bt_put(complex_structure_field); + bt_put(a_sequence_field); + bt_put(an_array_field); + bt_put(enum_variant_field); + bt_put(enum_container_field); + bt_put(variant_field); + bt_put(ret_field); + bt_put(packet_context_field); + bt_put(packet_context); + bt_put(uint_35_type); + bt_put(int_16_type); + bt_put(string_type); + bt_put(sequence_type); + bt_put(array_type); + bt_put(inner_structure_type); + bt_put(complex_structure_type); + bt_put(uint_3_type); + bt_put(enum_variant_type); + bt_put(variant_type); + bt_put(ret_field_type); + bt_put(event_class); + bt_put(event); } static void field_copy_tests_validate_same_type(struct bt_ctf_field *field, @@ -1313,7 +1313,7 @@ static void field_copy_tests_validate_same_type(struct bt_ctf_field *field, copy_type = bt_ctf_field_get_type(field); ok(copy_type == expected_type, "bt_ctf_field_copy does not copy the type (%s)", name); - bt_ctf_put(copy_type); + bt_put(copy_type); } static void field_copy_tests_validate_diff_ptrs(struct bt_ctf_field *field_a, @@ -1512,7 +1512,7 @@ void field_copy_tests() v_selected_cur = bt_ctf_field_variant_get_current_field(v); ok(v_selected_cur == v_selected, "bt_ctf_field_variant_get_current_field returns the current field"); - bt_ctf_put(v_selected_cur); + bt_put(v_selected_cur); /* set selected v field */ ret = bt_ctf_field_sequence_set_length(v_selected, len); @@ -1719,7 +1719,7 @@ void field_copy_tests() assert(!ret); ok(uint64_t_val == 7, "bt_ctf_field_copy creates a sequence field copy with the proper length"); - bt_ctf_put(v_selected_copy_len); + bt_put(v_selected_copy_len); v_selected_copy_len = NULL; /* validate v_selected copy fields */ @@ -1777,59 +1777,59 @@ void field_copy_tests() "bt_ctf_field_copy creates a valid array field element copy (a_4)"); /* put everything */ - bt_ctf_put(len_type); - bt_ctf_put(fp_type); - bt_ctf_put(s_type); - bt_ctf_put(e_int_type); - bt_ctf_put(e_type); - bt_ctf_put(v_type); - bt_ctf_put(v_label1_type); - bt_ctf_put(v_label1_array_type); - bt_ctf_put(v_label2_type); - bt_ctf_put(v_label2_seq_type); - bt_ctf_put(strct_type); - bt_ctf_put(len); - bt_ctf_put(fp); - bt_ctf_put(s); - bt_ctf_put(e_int); - bt_ctf_put(e); - bt_ctf_put(v); - bt_ctf_put(v_selected); - bt_ctf_put(v_selected_0); - bt_ctf_put(v_selected_1); - bt_ctf_put(v_selected_2); - bt_ctf_put(v_selected_3); - bt_ctf_put(v_selected_4); - bt_ctf_put(v_selected_5); - bt_ctf_put(v_selected_6); - bt_ctf_put(a); - bt_ctf_put(a_0); - bt_ctf_put(a_1); - bt_ctf_put(a_2); - bt_ctf_put(a_3); - bt_ctf_put(a_4); - bt_ctf_put(strct); - bt_ctf_put(len_copy); - bt_ctf_put(fp_copy); - bt_ctf_put(s_copy); - bt_ctf_put(e_int_copy); - bt_ctf_put(e_copy); - bt_ctf_put(v_copy); - bt_ctf_put(v_selected_copy); - bt_ctf_put(v_selected_0_copy); - bt_ctf_put(v_selected_1_copy); - bt_ctf_put(v_selected_2_copy); - bt_ctf_put(v_selected_3_copy); - bt_ctf_put(v_selected_4_copy); - bt_ctf_put(v_selected_5_copy); - bt_ctf_put(v_selected_6_copy); - bt_ctf_put(a_copy); - bt_ctf_put(a_0_copy); - bt_ctf_put(a_1_copy); - bt_ctf_put(a_2_copy); - bt_ctf_put(a_3_copy); - bt_ctf_put(a_4_copy); - bt_ctf_put(strct_copy); + bt_put(len_type); + bt_put(fp_type); + bt_put(s_type); + bt_put(e_int_type); + bt_put(e_type); + bt_put(v_type); + bt_put(v_label1_type); + bt_put(v_label1_array_type); + bt_put(v_label2_type); + bt_put(v_label2_seq_type); + bt_put(strct_type); + bt_put(len); + bt_put(fp); + bt_put(s); + bt_put(e_int); + bt_put(e); + bt_put(v); + bt_put(v_selected); + bt_put(v_selected_0); + bt_put(v_selected_1); + bt_put(v_selected_2); + bt_put(v_selected_3); + bt_put(v_selected_4); + bt_put(v_selected_5); + bt_put(v_selected_6); + bt_put(a); + bt_put(a_0); + bt_put(a_1); + bt_put(a_2); + bt_put(a_3); + bt_put(a_4); + bt_put(strct); + bt_put(len_copy); + bt_put(fp_copy); + bt_put(s_copy); + bt_put(e_int_copy); + bt_put(e_copy); + bt_put(v_copy); + bt_put(v_selected_copy); + bt_put(v_selected_0_copy); + bt_put(v_selected_1_copy); + bt_put(v_selected_2_copy); + bt_put(v_selected_3_copy); + bt_put(v_selected_4_copy); + bt_put(v_selected_5_copy); + bt_put(v_selected_6_copy); + bt_put(a_copy); + bt_put(a_0_copy); + bt_put(a_1_copy); + bt_put(a_2_copy); + bt_put(a_3_copy); + bt_put(a_4_copy); + bt_put(strct_copy); } void type_field_tests() @@ -1956,7 +1956,7 @@ void type_field_tests() sequence_type); ok(returned_type == int_16_type, "bt_ctf_field_type_sequence_get_element_type returns the correct type"); - bt_ctf_put(returned_type); + bt_put(returned_type); string_type = bt_ctf_field_type_string_create(); ok(string_type, "Create a string type"); @@ -2000,7 +2000,7 @@ void type_field_tests() ok(bt_ctf_field_type_structure_get_field(structure_seq_type, NULL, &returned_type, 1) == 0, "bt_ctf_field_type_structure_get_field handles a NULL name correctly"); - bt_ctf_put(returned_type); + bt_put(returned_type); ok(bt_ctf_field_type_structure_get_field(structure_seq_type, &ret_string, NULL, 1) == 0, "bt_ctf_field_type_structure_get_field handles a NULL return type correctly"); @@ -2014,7 +2014,7 @@ void type_field_tests() "bt_ctf_field_type_structure_get_field returns a correct field name"); ok(returned_type == sequence_type, "bt_ctf_field_type_structure_get_field returns a correct field type"); - bt_ctf_put(returned_type); + bt_put(returned_type); ok(bt_ctf_field_type_structure_get_field_type_by_name(NULL, "a_sequence") == NULL, "bt_ctf_field_type_structure_get_field_type_by_name handles a NULL structure correctly"); @@ -2024,7 +2024,7 @@ void type_field_tests() structure_seq_type, "a_sequence"); ok(returned_type == sequence_type, "bt_ctf_field_type_structure_get_field_type_by_name returns the correct field type"); - bt_ctf_put(returned_type); + bt_put(returned_type); composite_structure_type = bt_ctf_field_type_structure_create(); ok(bt_ctf_field_type_structure_add_field(composite_structure_type, @@ -2044,7 +2044,7 @@ void type_field_tests() structure_seq_type, "a_sequence"); ok(returned_type == sequence_type, "bt_ctf_field_type_structure_get_field_type_by_name returns a correct type"); - bt_ctf_put(returned_type); + bt_put(returned_type); int_16 = bt_ctf_field_create(int_16_type); ok(int_16, "Instanciate a signed 16-bit integer"); @@ -2109,21 +2109,21 @@ void type_field_tests() ok(!enumeration, "Check enumeration types are validated before instantiation"); - bt_ctf_put(string); - bt_ctf_put(uint_12); - bt_ctf_put(int_16); - bt_ctf_put(enumeration); - bt_ctf_put(composite_structure_type); - bt_ctf_put(structure_seq_type); - bt_ctf_put(string_type); - bt_ctf_put(sequence_type); - bt_ctf_put(uint_8_type); - bt_ctf_put(int_16_type); - bt_ctf_put(uint_12_type); - bt_ctf_put(enumeration_type); - bt_ctf_put(enumeration_sequence_type); - bt_ctf_put(enumeration_array_type); - bt_ctf_put(returned_type); + bt_put(string); + bt_put(uint_12); + bt_put(int_16); + bt_put(enumeration); + bt_put(composite_structure_type); + bt_put(structure_seq_type); + bt_put(string_type); + bt_put(sequence_type); + bt_put(uint_8_type); + bt_put(int_16_type); + bt_put(uint_12_type); + bt_put(enumeration_type); + bt_put(enumeration_sequence_type); + bt_put(enumeration_array_type); + bt_put(returned_type); } void packet_resize_test(struct bt_ctf_stream_class *stream_class, @@ -2165,14 +2165,14 @@ void packet_resize_test(struct bt_ctf_stream_class *stream_class, ret_field_type = bt_ctf_field_get_type(ret_field); ok(ret_field_type == integer_type, "bt_ctf_event_get_payload_by_index returns a correct field"); - bt_ctf_put(ret_field_type); - bt_ctf_put(ret_field); + bt_put(ret_field_type); + bt_put(ret_field); ok(bt_ctf_event_get_payload_by_index(NULL, 0) == NULL, "bt_ctf_event_get_payload_by_index handles NULL correctly"); ok(bt_ctf_event_get_payload_by_index(event, 4) == NULL, "bt_ctf_event_get_payload_by_index handles an invalid index correctly"); - bt_ctf_put(event); + bt_put(event); ok(bt_ctf_stream_get_event_context(NULL) == NULL, "bt_ctf_stream_get_event_context handles NULL correctly"); @@ -2188,7 +2188,7 @@ void packet_resize_test(struct bt_ctf_stream_class *stream_class, ret_field = bt_ctf_field_create(integer_type); ok(bt_ctf_stream_set_event_context(stream, ret_field) < 0, "bt_ctf_stream_set_event_context rejects an event context of incorrect type"); - bt_ctf_put(ret_field); + bt_put(ret_field); for (i = 0; i < PACKET_RESIZE_TEST_LENGTH; i++) { event = bt_ctf_event_create(event_class); @@ -2201,21 +2201,21 @@ void packet_resize_test(struct bt_ctf_stream_class *stream_class, ret |= bt_ctf_field_unsigned_integer_set_value(integer, i); ret |= bt_ctf_event_set_payload(event, "field_1", integer); - bt_ctf_put(integer); + bt_put(integer); ret |= bt_ctf_field_string_set_value(string, "This is a test"); ret |= bt_ctf_event_set_payload(event, "a_string", string); - bt_ctf_put(string); + bt_put(string); /* Populate stream event context */ integer = bt_ctf_field_structure_get_field(event_context, "common_event_context"); ret |= bt_ctf_field_unsigned_integer_set_value(integer, i % 42); - bt_ctf_put(integer); + bt_put(integer); ret |= bt_ctf_stream_append_event(stream, event); - bt_ctf_put(event); + bt_put(event); if (ret) { break; @@ -2252,12 +2252,12 @@ end: ret = bt_ctf_stream_get_discarded_events_count(stream, &ret_uint64); ok(ret == 0 && ret_uint64 == 1000, "bt_ctf_stream_get_discarded_events_count returns a correct number of discarded events after a flush"); - bt_ctf_put(integer_type); - bt_ctf_put(string_type); - bt_ctf_put(packet_context); - bt_ctf_put(packet_context_field); - bt_ctf_put(event_context); - bt_ctf_put(event_class); + bt_put(integer_type); + bt_put(string_type); + bt_put(packet_context); + bt_put(packet_context_field); + bt_put(event_context); + bt_put(event_class); } void test_empty_stream(struct bt_ctf_writer *writer) @@ -2299,10 +2299,10 @@ void test_empty_stream(struct bt_ctf_writer *writer) end: ok(ret == 0, "Created a stream class with default attributes and an empty stream"); - bt_ctf_put(trace); - bt_ctf_put(ret_trace); - bt_ctf_put(stream); - bt_ctf_put(stream_class); + bt_put(trace); + bt_put(ret_trace); + bt_put(stream); + bt_put(stream_class); } void test_custom_event_header_stream(struct bt_ctf_writer *writer) @@ -2426,7 +2426,7 @@ void test_custom_event_header_stream(struct bt_ctf_writer *writer) fail("Failed to set custom_trace_packet_header_field value"); goto end; } - bt_ctf_put(integer); + bt_put(integer); event = bt_ctf_event_create(event_class); if (!event) { @@ -2465,7 +2465,7 @@ void test_custom_event_header_stream(struct bt_ctf_writer *writer) fail("Failed to set sequence length"); goto end; } - bt_ctf_put(integer); + bt_put(integer); for (i = 0; i < 2; i++) { integer = bt_ctf_field_sequence_get_field(sequence, i); @@ -2480,7 +2480,7 @@ void test_custom_event_header_stream(struct bt_ctf_writer *writer) goto end; } - bt_ctf_put(integer); + bt_put(integer); integer = NULL; } @@ -2495,19 +2495,19 @@ void test_custom_event_header_stream(struct bt_ctf_writer *writer) fail("Failed to flush custom_event_header stream"); } end: - bt_ctf_put(clock); - bt_ctf_put(trace); - bt_ctf_put(stream); - bt_ctf_put(stream_class); - bt_ctf_put(event_class); - bt_ctf_put(event); - bt_ctf_put(integer); - bt_ctf_put(sequence); - bt_ctf_put(event_header); - bt_ctf_put(packet_header); - bt_ctf_put(sequence_type); - bt_ctf_put(integer_type); - bt_ctf_put(event_header_type); + bt_put(clock); + bt_put(trace); + bt_put(stream); + bt_put(stream_class); + bt_put(event_class); + bt_put(event); + bt_put(integer); + bt_put(sequence); + bt_put(event_header); + bt_put(packet_header); + bt_put(sequence_type); + bt_put(integer_type); + bt_put(event_header_type); } void test_instanciate_event_before_stream(struct bt_ctf_writer *writer) @@ -2615,15 +2615,15 @@ void test_instanciate_event_before_stream(struct bt_ctf_writer *writer) end: ok(ret == 0, "Create an event before instanciating its associated stream"); - bt_ctf_put(trace); - bt_ctf_put(stream); - bt_ctf_put(ret_stream); - bt_ctf_put(stream_class); - bt_ctf_put(event_class); - bt_ctf_put(event); - bt_ctf_put(integer_type); - bt_ctf_put(integer); - bt_ctf_put(clock); + bt_put(trace); + bt_put(stream); + bt_put(ret_stream); + bt_put(stream_class); + bt_put(event_class); + bt_put(event); + bt_put(integer_type); + bt_put(integer); + bt_put(clock); } void append_existing_event_class(struct bt_ctf_stream_class *stream_class) @@ -2633,14 +2633,14 @@ void append_existing_event_class(struct bt_ctf_stream_class *stream_class) assert(event_class = bt_ctf_event_class_create("Simple Event")); ok(bt_ctf_stream_class_add_event_class(stream_class, event_class), "two event classes with the same name cannot cohabit within the same stream class"); - bt_ctf_put(event_class); + bt_put(event_class); event_class = bt_ctf_event_class_create("different name, ok"); assert(event_class); assert(!bt_ctf_event_class_set_id(event_class, 11)); ok(bt_ctf_stream_class_add_event_class(stream_class, event_class), "two event classes with the same ID cannot cohabit within the same stream class"); - bt_ctf_put(event_class); + bt_put(event_class); } int main(int argc, char **argv) @@ -2736,14 +2736,14 @@ int main(int argc, char **argv) "bt_ctf_trace_set_environment_field handles a NULL value correctly"); ok(!bt_ctf_trace_set_environment_field(trace, "test_env_int_obj", obj), "bt_ctf_trace_set_environment_field succeeds in adding an integer object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); /* Test bt_ctf_trace_set_environment_field with a string object */ obj = bt_value_string_create_init("the value"); assert(obj); ok(!bt_ctf_trace_set_environment_field(trace, "test_env_str_obj", obj), "bt_ctf_trace_set_environment_field succeeds in adding a string object"); - BT_VALUE_PUT(obj); + BT_PUT(obj); /* Test bt_ctf_trace_set_environment_field_integer */ ok(bt_ctf_trace_set_environment_field_integer(NULL, "test_env_int", @@ -2808,12 +2808,12 @@ int main(int argc, char **argv) ret = bt_value_integer_get(obj, &ret_int64_t); ok(!ret && ret_int64_t == 23, "bt_ctf_trace_get_environment_field_value succeeds in getting an integer value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); obj = bt_ctf_trace_get_environment_field_value(trace, 2); ret = bt_value_string_get(obj, &ret_string); ok(!ret && ret_string && !strcmp(ret_string, "the value"), "bt_ctf_trace_get_environment_field_value succeeds in getting a string value"); - BT_VALUE_PUT(obj); + BT_PUT(obj); /* Test bt_ctf_trace_get_environment_field_value_by_name */ ok(!bt_ctf_trace_get_environment_field_value_by_name(NULL, @@ -2828,7 +2828,7 @@ int main(int argc, char **argv) ret = bt_value_string_get(obj, &ret_string); ok(!ret && ret_string && !strcmp(ret_string, "oh yeah"), "bt_ctf_trace_get_environment_field_value_by_name succeeds in getting an existing field"); - BT_VALUE_PUT(obj); + BT_PUT(obj); /* Test environment field replacement */ ok(!bt_ctf_trace_set_environment_field_integer(trace, "test_env_int", @@ -2840,7 +2840,7 @@ int main(int argc, char **argv) ret = bt_value_integer_get(obj, &ret_int64_t); ok(!ret && ret_int64_t == 654321, "bt_ctf_trace_get_environment_field_value successfully replaces an existing field"); - BT_VALUE_PUT(obj); + BT_PUT(obj); if (uname(&name)) { perror("uname"); @@ -2946,7 +2946,7 @@ int main(int argc, char **argv) ret_clock = bt_ctf_trace_get_clock(trace, 0); ok(ret_clock == clock, "bt_ctf_trace_get_clock returns the right clock instance"); - bt_ctf_put(ret_clock); + bt_put(ret_clock); ok(!bt_ctf_trace_get_clock_by_name(trace, NULL), "bt_ctf_trace_get_clock_by_name correctly handles NULL (trace)"); ok(!bt_ctf_trace_get_clock_by_name(NULL, clock_name), @@ -2956,7 +2956,7 @@ int main(int argc, char **argv) ret_clock = bt_ctf_trace_get_clock_by_name(trace, clock_name); ok(ret_clock == clock, "bt_ctf_trace_get_clock_by_name returns the right clock instance"); - bt_ctf_put(ret_clock); + bt_put(ret_clock); ok(!bt_ctf_trace_get_clock_by_name(trace, "random"), "bt_ctf_trace_get_clock_by_name fails when the requested clock doesn't exist"); @@ -3034,7 +3034,7 @@ int main(int argc, char **argv) ret_clock = bt_ctf_stream_class_get_clock(stream_class); ok(ret_clock == clock, "bt_ctf_stream_class_get_clock returns a correct clock"); - bt_ctf_put(ret_clock); + bt_put(ret_clock); /* Test the event fields and event types APIs */ type_field_tests(); @@ -3070,7 +3070,7 @@ int main(int argc, char **argv) ok(bt_ctf_field_type_get_type_id( event_header_field_type) == CTF_TYPE_INTEGER, "Default event header \"id\" field is an integer"); - bt_ctf_put(event_header_field_type); + bt_put(event_header_field_type); event_header_field_type = bt_ctf_field_type_structure_get_field_type_by_name( ret_field_type, "timestamp"); @@ -3079,8 +3079,8 @@ int main(int argc, char **argv) ok(bt_ctf_field_type_get_type_id( event_header_field_type) == CTF_TYPE_INTEGER, "Default event header \"timestamp\" field is an integer"); - bt_ctf_put(event_header_field_type); - bt_ctf_put(ret_field_type); + bt_put(event_header_field_type); + bt_put(ret_field_type); /* Add a custom trace packet header field */ ok(bt_ctf_trace_get_packet_header_type(NULL) == NULL, @@ -3093,15 +3093,15 @@ int main(int argc, char **argv) ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name( packet_header_type, "magic"); ok(ret_field_type, "Default packet header type contains a \"magic\" field"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name( packet_header_type, "uuid"); ok(ret_field_type, "Default packet header type contains a \"uuid\" field"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); ret_field_type = bt_ctf_field_type_structure_get_field_type_by_name( packet_header_type, "stream_id"); ok(ret_field_type, "Default packet header type contains a \"stream_id\" field"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); packet_header_field_type = bt_ctf_field_type_integer_create(22); ok(!bt_ctf_field_type_structure_add_field(packet_header_type, @@ -3168,7 +3168,7 @@ int main(int argc, char **argv) stream_class); ok(ret_field_type == stream_event_context_type, "bt_ctf_stream_class_get_event_context_type returns the correct field type."); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); /* Instantiate a stream and append events */ stream1 = bt_ctf_writer_create_stream(writer, stream_class); @@ -3222,7 +3222,7 @@ int main(int argc, char **argv) ret_field_type = bt_ctf_field_get_type(packet_header); ok(ret_field_type == packet_header_type, "Stream returns a packet header of the appropriate type"); - bt_ctf_put(ret_field_type); + bt_put(ret_field_type); packet_header_field = bt_ctf_field_structure_get_field(packet_header, "custom_trace_packet_header_field"); ok(packet_header_field, @@ -3265,25 +3265,25 @@ int main(int argc, char **argv) validate_metadata(argv[1], metadata_path); validate_trace(argv[2], trace_path); - bt_ctf_put(clock); - bt_ctf_put(ret_stream_class); - bt_ctf_put(writer); - bt_ctf_put(stream1); - bt_ctf_put(packet_context_type); - bt_ctf_put(packet_context_field_type); - bt_ctf_put(integer_type); - bt_ctf_put(stream_event_context_type); - bt_ctf_put(ret_field_type); - bt_ctf_put(packet_header_type); - bt_ctf_put(packet_header_field_type); - bt_ctf_put(packet_header); - bt_ctf_put(packet_header_field); - bt_ctf_put(trace); + bt_put(clock); + bt_put(ret_stream_class); + bt_put(writer); + bt_put(stream1); + bt_put(packet_context_type); + bt_put(packet_context_field_type); + bt_put(integer_type); + bt_put(stream_event_context_type); + bt_put(ret_field_type); + bt_put(packet_header_type); + bt_put(packet_header_field_type); + bt_put(packet_header); + bt_put(packet_header_field); + bt_put(trace); free(metadata_string); ok(bt_ctf_stream_class_get_trace(stream_class) == NULL, "bt_ctf_stream_class_get_trace returns NULL after its trace has been reclaimed"); - bt_ctf_put(stream_class); + bt_put(stream_class); /* Remove all trace files and delete temporary trace directory */ DIR *trace_dir = opendir(trace_path); -- 2.34.1