#include <babeltrace/values.h>
#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)
BT_HIDDEN
void bt_ctf_attributes_destroy(struct bt_value *attr_obj)
{
- bt_value_put(attr_obj);
+ bt_put(attr_obj);
}
BT_HIDDEN
}
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;
}
BT_CTF_ATTR_VALUE_INDEX);
end:
- BT_VALUE_PUT(attr_field_obj);
-
+ BT_PUT(attr_field_obj);
return value_obj;
}
}
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;
}
ret = bt_value_array_append(attr_obj, attr_field_obj);
end:
- BT_VALUE_PUT(attr_field_obj);
+ BT_PUT(attr_field_obj);
return ret;
}
BT_CTF_ATTR_VALUE_INDEX);
end:
- BT_VALUE_PUT(attr_field_obj);
+ BT_PUT(attr_field_obj);
return value_obj;
}
}
bt_value_freeze(obj);
- BT_VALUE_PUT(obj);
+ BT_PUT(obj);
}
end:
-
return ret;
}
#include <babeltrace/ctf-ir/clock-internal.h>
#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf-ir/common-internal.h>
-#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ref.h>
#include <babeltrace/ctf-writer/writer-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/compiler.h>
#include <inttypes.h>
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)
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;
}
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)
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
}
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);
}
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-ir/event-fields-internal.h>
#include <babeltrace/ctf-ir/event-types-internal.h>
-#include <babeltrace/ctf-ir/common-internal.h>
-#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/ref.h>
#include <babeltrace/compiler.h>
#define PACKET_LEN_INCREMENT (getpagesize() * 8 * CHAR_BIT)
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
/* 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;
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)
}
ret = field->type;
- bt_ctf_field_type_get(ret);
+ bt_get(ret);
end:
return ret;
}
sequence = container_of(field, struct bt_ctf_field_sequence, parent);
ret = sequence->length;
- bt_ctf_field_get(ret);
+ bt_get(ret);
end:
return ret;
}
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);
}
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;
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;
}
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;
}
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;
}
}
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;
}
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;
}
}
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;
}
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;
}
}
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;
}
if (variant->payload) {
current_field = variant->payload;
- bt_ctf_field_get(current_field);
+ bt_get(current_field);
goto end;
}
}
container = enumeration->payload;
- bt_ctf_field_get(container);
+ bt_get(container);
end:
return container;
}
}
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;
}
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:
}
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 ||
}
field_destroy_funcs[type_id](field);
- if (type) {
- bt_ctf_field_type_put(type);
- }
+ bt_put(type);
}
static
enumeration = container_of(field, struct bt_ctf_field_enumeration,
parent);
- bt_ctf_field_put(enumeration->payload);
+ bt_put(enumeration->payload);
g_free(enumeration);
}
}
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);
}
if (sequence->elements) {
g_ptr_array_free(sequence->elements, TRUE);
}
- bt_ctf_field_put(sequence->length);
+ bt_put(sequence->length);
g_free(sequence);
}
}
}
end:
- bt_ctf_field_put(character);
- bt_ctf_field_type_put(character_type);
+ bt_put(character);
+ bt_put(character_type);
return ret;
}
/* 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;
/* 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;
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-ir/event-types-internal.h>
#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf-ir/ref.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/ref.h>
#include <babeltrace/ctf-ir/clock.h>
#include <babeltrace/ctf-writer/writer-internal.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/ref.h>
#include <babeltrace/compiler.h>
#include <babeltrace/endian.h>
#include <float.h>
};
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
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);
}
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];
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,
}
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) {
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;
}
}
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;
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);
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;
}
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);
field = structure->fields->pdata[index];
field_type = field->type;
- bt_ctf_field_type_get(field_type);
+ bt_get(field_type);
end:
return field_type;
}
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);
}
}
tag_type = &variant->tag->parent;
- bt_ctf_field_type_get(tag_type);
+ bt_get(tag_type);
end:
return tag_type;
}
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;
}
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);
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);
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;
}
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);
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;
}
}
ret = bt_ctf_field_type_get_alignment(element);
- bt_ctf_field_type_put(element);
+ bt_put(element);
break;
}
case CTF_TYPE_ARRAY:
}
ret = bt_ctf_field_type_get_alignment(element);
- bt_ctf_field_type_put(element);
+ bt_put(element);
break;
}
case CTF_TYPE_STRUCT:
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;
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
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;
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);
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;
return;
}
- if (integer->mapped_clock) {
- bt_ctf_clock_put(integer->mapped_clock);
- }
+ bt_put(integer->mapped_clock);
g_free(integer);
}
}
g_ptr_array_free(enumeration->entries, TRUE);
- bt_ctf_field_type_put(enumeration->container);
+ bt_put(enumeration->container);
g_free(enumeration);
}
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);
}
return;
}
- bt_ctf_field_type_put(array->element_type);
+ bt_put(array->element_type);
g_free(array);
}
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);
g_string_assign(context->field_name, "");
}
error_put_container_type:
- bt_ctf_field_type_put(container_type);
+ bt_put(container_type);
end:
return ret;
}
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:
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
end:
return copy;
error:
- bt_ctf_field_type_put(copy);
- return NULL;
+ BT_PUT(copy);
+ return copy;
}
static
}
}
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
parent);
copy_array->declaration = array->declaration;
end:
- if (copy_element) {
- bt_ctf_field_type_put(copy_element);
- }
-
+ bt_put(copy_element);
return 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;
}
#include <babeltrace/ctf-ir/stream-class-internal.h>
#include <babeltrace/ctf-ir/trace-internal.h>
#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf-ir/common-internal.h>
-#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ref.h>
#include <babeltrace/ctf-ir/attributes-internal.h>
#include <babeltrace/compiler.h>
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);
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;
goto error;
}
- BT_VALUE_PUT(obj);
+ BT_PUT(obj);
obj = bt_value_string_create_init(name);
if (!obj) {
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)
}
end:
- BT_VALUE_PUT(obj);
-
+ BT_PUT(obj);
return name;
}
}
end:
- BT_VALUE_PUT(obj);
-
+ BT_PUT(obj);
return ret;
}
}
end:
- BT_VALUE_PUT(obj);
-
+ BT_PUT(obj);
return ret;
}
}
stream_class = event_class->stream_class;
- bt_ctf_stream_class_get(stream_class);
+ bt_get(stream_class);
end:
return stream_class;
}
goto end;
}
- bt_ctf_field_type_get(event_class->fields);
+ bt_get(event_class->fields);
payload = event_class->fields;
end:
return payload;
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;
goto end;
}
- bt_ctf_field_type_get(event_class->context);
+ bt_get(event_class->context);
context_type = event_class->context;
end:
return 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;
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
"stream_id", obj);
end:
- BT_VALUE_PUT(obj);
-
+ BT_PUT(obj);
return ret;
}
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;
}
/*
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)
}
event_class = event->event_class;
- bt_ctf_event_class_get(event_class);
+ bt_get(event_class);
end:
return event_class;
}
}
stream = event->stream;
- if (stream) {
- bt_ctf_stream_get(stream);
- }
+ bt_get(stream);
end:
return stream;
}
}
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;
}
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;
}
payload = event->fields_payload;
- bt_ctf_field_get(payload);
+ bt_get(payload);
end:
return payload;
}
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;
}
name);
} else {
field = event->fields_payload;
- bt_ctf_field_get(field);
+ bt_get(field);
}
end:
return field;
}
header = event->event_header;
- bt_ctf_field_get(header);
+ bt_get(header);
end:
return header;
}
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;
}
}
context = event->context_payload;
- bt_ctf_field_get(context);
+ bt_get(context);
end:
return context;
}
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);
}
}
}
end:
- bt_ctf_field_type_put(field_type);
+ bt_put(field_type);
return ret;
}
break;
}
- BT_VALUE_PUT(attr_value);
+ BT_PUT(attr_value);
}
if (event_class->context) {
g_string_append(context->string, "};\n\n");
end:
context->current_indentation_level = 0;
- BT_VALUE_PUT(attr_value);
+ BT_PUT(attr_value);
return ret;
}
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;
}
}
}
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;
}
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) {
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;
}
#include <babeltrace/ctf-ir/visitor-internal.h>
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf-ir/ref.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/ref.h>
#include <babeltrace/compiler.h>
#include <babeltrace/align.h>
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
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;
}
trace = stream_class->trace;
if (trace) {
- bt_ctf_trace_get(trace);
+ bt_get(trace);
}
end:
return trace;
}
clock = stream_class->clock;
- bt_ctf_clock_get(clock);
+ bt_get(clock);
end:
return clock;
}
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;
}
}
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;
}
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);
}
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;
}
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;
}
}
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;
}
}
}
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;
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;
}
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;
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;
}
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;
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;
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
}
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;
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);
}
}
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;
}
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;
}
#include <babeltrace/ctf-ir/stream.h>
#include <babeltrace/ctf-ir/stream-internal.h>
#include <babeltrace/ctf-ir/stream-class-internal.h>
-#include <babeltrace/ctf-ir/ref.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/ref.h>
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/compiler.h>
#include <babeltrace/align.h>
#include <babeltrace/ctf/ctf-index.h>
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);
(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;
}
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
(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;
}
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
/* 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;
}
/*
stream->event_context = bt_ctf_field_create(
stream_class->event_context_type);
if (!stream->packet_context) {
- goto error_destroy;
+ goto error;
}
}
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;
}
}
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
*/
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
}
stream_class = stream->stream_class;
- bt_ctf_stream_class_get(stream_class);
+ bt_get(stream_class);
end:
return stream_class;
}
}
}
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;
}
}
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,
}
}
- 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) {
packet_context = stream->packet_context;
if (packet_context) {
- bt_ctf_field_get(packet_context);
+ bt_get(packet_context);
}
end:
return packet_context;
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;
event_context = stream->event_context;
if (event_context) {
- bt_ctf_field_get(event_context);
+ bt_get(event_context);
}
end:
return event_context;
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;
}
packet_header = stream->packet_header;
if (packet_header) {
- bt_ctf_field_get(packet_header);
+ bt_get(packet_header);
}
end:
return packet_header;
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;
}
}
}
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;
}
}
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);
}
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;
}
#include <babeltrace/ctf-ir/attributes-internal.h>
#include <babeltrace/ctf-ir/visitor-internal.h>
#include <babeltrace/ctf-ir/utils.h>
-#include <babeltrace/ctf-ir/ref.h>
-#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/compiler.h>
#include <babeltrace/values.h>
+#include <babeltrace/ref.h>
#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
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)
}
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);
}
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);
}
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,
trace->environment, name);
if (attribute) {
- BT_VALUE_PUT(attribute);
+ BT_PUT(attribute);
ret = -1;
goto end;
}
trace->environment, name);
if (attribute) {
- BT_VALUE_PUT(attribute);
+ BT_PUT(attribute);
ret = -1;
goto end;
}
env_value_string_obj);
end:
- BT_VALUE_PUT(env_value_string_obj);
-
+ BT_PUT(env_value_string_obj);
return ret;
}
trace->environment, name);
if (attribute) {
- BT_VALUE_PUT(attribute);
+ BT_PUT(attribute);
ret = -1;
goto end;
}
bt_value_freeze(env_value_integer_obj);
}
end:
- BT_VALUE_PUT(env_value_integer_obj);
-
+ BT_PUT(env_value_integer_obj);
return ret;
}
goto end;
}
- bt_ctf_clock_get(clock);
+ bt_get(clock);
g_ptr_array_add(trace->clocks, clock);
end:
return ret;
}
clock = g_ptr_array_index(trace->clocks, index);
- bt_ctf_clock_get(clock);
+ bt_get(clock);
end:
return clock;
}
goto end;
}
- bt_ctf_stream_class_get(stream_class);
+ bt_get(stream_class);
g_ptr_array_add(trace->stream_classes, 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;
}
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;
}
}
if (!strcmp(cur_clk_name, name)) {
clock = cur_clk;
- bt_ctf_clock_get(clock);
+ bt_get(clock);
goto end;
}
}
}
loop_next:
- BT_VALUE_PUT(env_field_value_obj);
+ BT_PUT(env_field_value_obj);
}
g_string_append(context->string, "};\n\n");
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;
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;
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);
}
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;
}
#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/ctf-ir/stream-class-internal.h>
#include <babeltrace/ctf-ir/stream-internal.h>
-#include <babeltrace/ctf-ir/ref.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/ref.h>
#include <babeltrace/compiler.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
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);
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;
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);
}
}
- bt_ctf_trace_put(writer->trace);
+ bt_put(writer->trace);
g_free(writer);
}
}
trace = writer->trace;
- bt_ctf_trace_get(trace);
+ bt_get(trace);
end:
return trace;
}
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,
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
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 \
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 \
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 \
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 \
#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-ir/trace-internal.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <glib.h>
#include <babeltrace/compat/uuid.h>
struct bt_ctf_clock {
- struct bt_ctf_base base;
+ struct bt_object base;
GString *name;
GString *description;
uint64_t frequency;
+++ /dev/null
-#ifndef BABELTRACE_CTF_IR_COMMON_INTERNAL_H
-#define BABELTRACE_CTF_IR_COMMON_INTERNAL_H
-
-/*
- * Babeltrace - CTF IR: common data structures
- *
- * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
- * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
- *
- * 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 <babeltrace/ref-internal.h>
-
-/*
- * 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.
- */
-struct bt_ctf_base {
- struct bt_ref ref_count;
-};
-
-static inline
-void bt_ctf_base_init(void *obj, bt_ref_release_func_t release_func)
-{
- struct bt_ctf_base *base = obj;
-
- bt_ref_init(&base->ref_count, release_func);
-}
-
-#endif /* BABELTRACE_CTF_IR_COMMON_INTERNAL_H */
*/
#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/ctf/types.h>
#include <glib.h>
struct bt_ctf_field {
- struct bt_ctf_base base;
+ struct bt_object base;
struct bt_ctf_field_type *type;
int payload_set;
};
#include <babeltrace/ctf/types.h>
#include <babeltrace/ctf-ir/stream-class.h>
#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/object-internal.h>
#include <glib.h>
#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
};
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;
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-writer/writer.h>
#include <babeltrace/ctf-ir/trace-internal.h>
-#include <babeltrace/ctf-ir/common-internal.h>
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/ctf/events.h>
#include <glib.h>
};
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;
+++ /dev/null
-#ifndef BABELTRACE_CTF_IR_REF_H
-#define BABELTRACE_CTF_IR_REF_H
-
-/*
- * BabelTrace - CTF IR: common reference counting
- *
- * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
- * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
- *
- * 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 <assert.h>
-#include <babeltrace/ref-internal.h>
-#include <babeltrace/ctf-ir/common-internal.h>
-
-/*
- * BT_CTF_PUT: calls bt_ctf_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
- * 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.
- *
- * It is safe to call this function with a NULL object.
- *
- * @param obj CTF IR object.
- */
-#define BT_CTF_PUT(_obj) \
- do { \
- bt_ctf_put(_obj); \
- (_obj) = NULL; \
- } while (0)
-
-/*
- * BT_CTF_MOVE: moves the ownership of a CTF 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
- * object from one variable to the other.
- *
- * @param obj CTF IR object.
- */
-#define BT_CTF_MOVE(_dst, _src) \
- do { \
- (_dst) = (_src); \
- (_src) = NULL; \
- } while (0)
-
-/*
- * bt_ctf_get: increments the reference count of a CTF IR 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.
- *
- * It is safe to call this function with a NULL object.
- *
- * @param obj CTF IR object.
- */
-static inline
-void bt_ctf_get(void *obj)
-{
- if (obj) {
- struct bt_ctf_base *base = obj;
-
- bt_ref_get(&base->ref_count);
- }
-}
-
-/*
- * bt_ctf_put: decrements the reference count of a CTF IR 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.
- *
- * When the object's reference count is decremented to 0 by a call to
- * bt_ctf_put(), the object is freed.
- *
- * It is safe to call this function with a NULL object.
- *
- * @param obj CTF IR object.
- */
-static inline
-void bt_ctf_put(void *obj)
-{
- if (obj) {
- struct bt_ctf_base *base = obj;
-
- bt_ref_put(&base->ref_count);
- }
-}
-
-#endif /* BABELTRACE_CTF_IR_REF_H */
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/ctf/types.h>
#include <glib.h>
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 */
*/
#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-writer/event-types.h>
#include <glib.h>
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;
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,
#include <babeltrace/ctf-ir/trace.h>
#include <babeltrace/ctf-ir/event-types.h>
#include <babeltrace/ctf-ir/event-fields.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/values.h>
#include <glib.h>
};
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" */
#include <dirent.h>
#include <sys/types.h>
#include <babeltrace/ctf-ir/trace.h>
-#include <babeltrace/ctf-ir/common-internal.h>
+#include <babeltrace/object-internal.h>
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;
--- /dev/null
+#ifndef BABELTRACE_OBJECT_INTERNAL_H
+#define BABELTRACE_OBJECT_INTERNAL_H
+
+/*
+ * Babeltrace - Base object
+ *
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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 <babeltrace/ref-internal.h>
+
+/**
+ * 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_object {
+ struct bt_ref ref_count;
+};
+
+static inline
+void bt_object_init(void *obj, bt_object_release_func release)
+{
+ bt_ref_init(&((struct bt_object *) obj)->ref_count, release);
+}
+
+#endif /* BABELTRACE_OBJECT_INTERNAL_H */
#define BABELTRACE_REF_INTERNAL_H
/*
- * Babeltrace - reference counting
+ * Babeltrace - Reference Counting
*
* Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* SOFTWARE.
*/
+#include <babeltrace/babeltrace-internal.h>
#include <assert.h>
-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);
}
}
--- /dev/null
+#ifndef BABELTRACE_REF_H
+#define BABELTRACE_REF_H
+
+/*
+ * BabelTrace: common reference counting
+ *
+ * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
+ * Copyright (c) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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.
+ */
+
+/*
+ * BT_PUT: calls bt_put() with a variable, then sets this variable to NULL.
+ *
+ * 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, the BT_PUT() macro can be used to do just that.
+ *
+ * It is safe to call this function with a NULL object.
+ *
+ * @param obj Babeltrace object.
+ */
+#define BT_PUT(_obj) \
+ do { \
+ bt_put(_obj); \
+ (_obj) = NULL; \
+ } while (0)
+
+/*
+ * 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 an
+ * object from one variable to the other.
+ *
+ * @param obj Babeltrace object.
+ */
+#define BT_MOVE(_dst, _src) \
+ do { \
+ (_dst) = (_src);\
+ (_src) = NULL; \
+ } while (0)
+
+/*
+ * bt_get: increments the reference count of a Babeltrace 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 Babeltrace object.
+ */
+void bt_get(void *obj);
+
+/*
+ * bt_put: decrements the reference count of a Babeltrace 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.
+ *
+ * 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 Babeltrace object.
+ */
+void bt_put(void *obj);
+
+#endif /* BABELTRACE_REF_H */
* \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.
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
+#include <babeltrace/ref.h>
#ifdef __cplusplus
extern "C" {
* 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.
*
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 <b>not changed</b>. 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
* value object \p map_obj.
*
* The value object passed to the user function is a
- * <b>weak reference</b>: you must call bt_value_get() on it to obtain
- * your own reference.
+ * <b>weak reference</b>: 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.
trace-handle.c \
trace-collection.c \
registry.c \
- values.c
+ values.c \
+ ref.c
libbabeltrace_la_LDFLAGS = -version-info $(BABELTRACE_LIBRARY_VERSION)
--- /dev/null
+/*
+ * ref.c: reference counting
+ *
+ * Babeltrace Library
+ *
+ * Copyright (c) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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 <babeltrace/ref-internal.h>
+#include <babeltrace/object-internal.h>
+
+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);
+ }
+}
/*
- * values.c: value objects
+ * Values.c: value objects
*
* Babeltrace Library
*
#include <string.h>
#include <assert.h>
#include <string.h>
-#include <babeltrace/ref-internal.h>
#include <babeltrace/compiler.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/ref.h>
#include <babeltrace/values.h>
#include <glib.h>
#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;
};
};
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)
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;
}
}
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;
}
}
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:
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:
};
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)
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;
}
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);
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);
}
ret = g_ptr_array_index(typed_array_obj->garray, index);
- bt_value_get(ret);
+ bt_get(ret);
end:
return ret;
}
g_ptr_array_add(typed_array_obj->garray, element_obj);
- bt_value_get(element_obj);
+ bt_get(element_obj);
end:
return ret;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
ret = g_hash_table_lookup(typed_map_obj->ght, GUINT_TO_POINTER(quark));
if (ret) {
- bt_value_get(ret);
+ bt_get(ret);
}
end:
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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,
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;
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
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);
ok(!ret && value == 321456987,
"bt_value_integer_set() does not alter a frozen integer value object");
- BT_VALUE_PUT(obj);
+ BT_PUT(obj);
}
static
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);
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
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);
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
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,
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)");
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");
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");
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) ==
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")
}
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,
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);
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)");
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");
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")
}
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
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
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
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
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
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
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
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
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)
#include <babeltrace/ctf-writer/event-types.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-ir/stream-class.h>
-#include <babeltrace/ctf-ir/ref.h>
+#include <babeltrace/ref.h>
#include <babeltrace/ctf/events.h>
#include <babeltrace/values.h>
#include <unistd.h>
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);
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);
"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);
"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);
"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,
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,
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);
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),
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");
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,
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);
"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,
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,
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");
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");
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");
"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,
"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");
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),
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));
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");
attrs_count.unknown++;
}
- BT_VALUE_PUT(obj);
+ BT_PUT(obj);
}
ok(attrs_count.unknown == 0, "event class has no unknown attributes");
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");
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");
"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,
"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");
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) {
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);
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");
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");
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,
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);
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,
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,
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);
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 */
"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()
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");
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");
"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");
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,
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");
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,
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");
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);
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;
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)
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)
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) {
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);
goto end;
}
- bt_ctf_put(integer);
+ bt_put(integer);
integer = NULL;
}
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)
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)
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)
"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",
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,
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",
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");
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),
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");
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();
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");
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,
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,
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);
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,
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);