#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/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_ctf_ref *);
+void bt_ctf_field_destroy(struct bt_ref *);
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_ref_init(&field->ref_count);
+ bt_ctf_base_init(field, bt_ctf_field_destroy);
field->type = type;
error:
return field;
void bt_ctf_field_get(struct bt_ctf_field *field)
{
- if (field) {
- bt_ctf_ref_get(&field->ref_count);
- }
+ bt_ctf_get(field);
}
void bt_ctf_field_put(struct bt_ctf_field *field)
{
- if (field) {
- bt_ctf_ref_put(&field->ref_count, bt_ctf_field_destroy);
- }
+ bt_ctf_put(field);
}
struct bt_ctf_field_type *bt_ctf_field_get_type(struct bt_ctf_field *field)
return new_field;
}
+struct bt_ctf_field *bt_ctf_field_variant_get_current_field(
+ struct bt_ctf_field *variant_field)
+{
+ struct bt_ctf_field *current_field = NULL;
+ struct bt_ctf_field_variant *variant;
+
+ if (!variant_field ||
+ bt_ctf_field_type_get_type_id(variant_field->type) !=
+ CTF_TYPE_VARIANT) {
+ goto end;
+ }
+
+ variant = container_of(variant_field, struct bt_ctf_field_variant,
+ parent);
+
+ if (variant->payload) {
+ current_field = variant->payload;
+ bt_ctf_field_get(current_field);
+ goto end;
+ }
+
+end:
+ return current_field;
+}
+
struct bt_ctf_field *bt_ctf_field_enumeration_get_container(
struct bt_ctf_field *field)
{
}
static
-void bt_ctf_field_destroy(struct bt_ctf_ref *ref)
+void bt_ctf_field_destroy(struct bt_ref *ref)
{
struct bt_ctf_field *field;
+ struct bt_ctf_base *base;
struct bt_ctf_field_type *type;
enum ctf_type_id type_id;
return;
}
- field = container_of(ref, struct bt_ctf_field, ref_count);
+ base = container_of(ref, struct bt_ctf_base, ref_count);
+ field = container_of(base, struct bt_ctf_field, base);
type = field->type;
type_id = bt_ctf_field_type_get_type_id(type);
if (type_id <= CTF_TYPE_UNKNOWN ||
}
sequence = container_of(field, struct bt_ctf_field_sequence, parent);
- g_ptr_array_free(sequence->elements, TRUE);
+ if (sequence->elements) {
+ g_ptr_array_free(sequence->elements, TRUE);
+ }
bt_ctf_field_put(sequence->length);
g_free(sequence);
}