X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fevent-types.c;h=450f8d58d219f8e3e6f083c32c20363feadc46d6;hb=de3dd40e6fcad56e227f5fc8a8290fbaa88b4e07;hp=df117474561098864e2bd38a550bb4e46a24089e;hpb=59acd4f59c7172487c08bcdb59974fce25ca242e;p=babeltrace.git diff --git a/formats/ctf/ir/event-types.c b/formats/ctf/ir/event-types.c index df117474..450f8d58 100644 --- a/formats/ctf/ir/event-types.c +++ b/formats/ctf/ir/event-types.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -52,26 +54,26 @@ struct range_overlap_query { }; static -void bt_ctf_field_type_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_destroy(struct bt_ref *); static -void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type *); static -void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type *); static -void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type *); static -void bt_ctf_field_type_structure_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type *); static -void bt_ctf_field_type_variant_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type *); static -void bt_ctf_field_type_array_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type *); static -void bt_ctf_field_type_sequence_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type *); static -void bt_ctf_field_type_string_destroy(struct bt_ctf_ref *); +void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type *); static -void (* const type_destroy_funcs[])(struct bt_ctf_ref *) = { +void (* const type_destroy_funcs[])(struct bt_ctf_field_type *) = { [CTF_TYPE_INTEGER] = bt_ctf_field_type_integer_destroy, [CTF_TYPE_ENUM] = bt_ctf_field_type_enumeration_destroy, @@ -298,7 +300,7 @@ void bt_ctf_field_type_init(struct bt_ctf_field_type *type, int init_bo) assert(type && (type_id > CTF_TYPE_UNKNOWN) && (type_id < NR_CTF_TYPES)); - bt_ctf_ref_init(&type->ref_count); + bt_ctf_base_init(type, bt_ctf_field_type_destroy); type->freeze = type_freeze_funcs[type_id]; type->serialize = type_serialize_funcs[type_id]; @@ -346,23 +348,25 @@ end: } static -void bt_ctf_field_type_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_destroy(struct bt_ref *ref) { struct bt_ctf_field_type *type; + struct bt_ctf_base *base; enum ctf_type_id type_id; if (!ref) { return; } - type = container_of(ref, struct bt_ctf_field_type, ref_count); + base = container_of(ref, struct bt_ctf_base, ref_count); + type = container_of(base, struct bt_ctf_field_type, base); type_id = type->declaration->id; if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) { return; } - type_destroy_funcs[type_id](ref); + type_destroy_funcs[type_id](type); } BT_HIDDEN @@ -1780,14 +1784,20 @@ end: return ret; } +static inline +int is_power_of_two(unsigned int value) +{ + return ((value & (value - 1)) == 0) && value > 0; +} + int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, unsigned int alignment) { int ret = 0; enum ctf_type_id type_id; - /* Alignment must be bit-aligned (1) or byte aligned */ - if (!type || type->frozen || (alignment != 1 && (alignment & 0x7))) { + /* Alignment must be a power of two */ + if (!type || type->frozen || !is_power_of_two(alignment)) { ret = -1; goto end; } @@ -1804,8 +1814,8 @@ int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type *type, goto end; } - if (type_id == CTF_TYPE_STRUCT || type_id == CTF_TYPE_VARIANT || - type_id == CTF_TYPE_SEQUENCE || type_id == CTF_TYPE_ARRAY) { + if (type_id == CTF_TYPE_VARIANT || type_id == CTF_TYPE_SEQUENCE || + type_id == CTF_TYPE_ARRAY) { /* Setting an alignment on these types makes no sense */ ret = -1; goto end; @@ -1914,20 +1924,12 @@ enum ctf_type_id bt_ctf_field_type_get_type_id( void bt_ctf_field_type_get(struct bt_ctf_field_type *type) { - if (!type) { - return; - } - - bt_ctf_ref_get(&type->ref_count); + bt_ctf_get(type); } void bt_ctf_field_type_put(struct bt_ctf_field_type *type) { - if (!type) { - return; - } - - bt_ctf_ref_put(&type->ref_count, bt_ctf_field_type_destroy); + bt_ctf_put(type); } BT_HIDDEN @@ -2296,17 +2298,15 @@ end: } static -void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_integer_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_integer *integer; + struct bt_ctf_field_type_integer *integer = + (struct bt_ctf_field_type_integer *) type; - if (!ref) { + if (!type) { return; } - integer = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_integer, parent); if (integer->mapped_clock) { bt_ctf_clock_put(integer->mapped_clock); } @@ -2314,66 +2314,58 @@ void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref) } static -void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_enumeration_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_enumeration *enumeration; + struct bt_ctf_field_type_enumeration *enumeration = + (struct bt_ctf_field_type_enumeration *) type; - if (!ref) { + if (!type) { return; } - enumeration = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_enumeration, parent); g_ptr_array_free(enumeration->entries, TRUE); bt_ctf_field_type_put(enumeration->container); g_free(enumeration); } static -void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_floating_point_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_floating_point *floating_point; + struct bt_ctf_field_type_floating_point *floating_point = + (struct bt_ctf_field_type_floating_point *) type; - if (!ref) { + if (!type) { return; } - floating_point = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_floating_point, parent); g_free(floating_point); } static -void bt_ctf_field_type_structure_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_structure_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_structure *structure; + struct bt_ctf_field_type_structure *structure = + (struct bt_ctf_field_type_structure *) type; - if (!ref) { + if (!type) { return; } - structure = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_structure, parent); g_ptr_array_free(structure->fields, TRUE); g_hash_table_destroy(structure->field_name_to_index); g_free(structure); } static -void bt_ctf_field_type_variant_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_variant_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_variant *variant; + struct bt_ctf_field_type_variant *variant = + (struct bt_ctf_field_type_variant *) type; - if (!ref) { + if (!type) { return; } - variant = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_variant, parent); g_ptr_array_free(variant->fields, TRUE); g_hash_table_destroy(variant->field_name_to_index); g_string_free(variant->tag_name, TRUE); @@ -2383,33 +2375,29 @@ void bt_ctf_field_type_variant_destroy(struct bt_ctf_ref *ref) } static -void bt_ctf_field_type_array_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_array_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_array *array; + struct bt_ctf_field_type_array *array = + (struct bt_ctf_field_type_array *) type; - if (!ref) { + if (!type) { return; } - array = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_array, parent); bt_ctf_field_type_put(array->element_type); g_free(array); } static -void bt_ctf_field_type_sequence_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_sequence_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_sequence *sequence; + struct bt_ctf_field_type_sequence *sequence = + (struct bt_ctf_field_type_sequence *) type; - if (!ref) { + if (!type) { return; } - sequence = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_sequence, parent); bt_ctf_field_type_put(sequence->element_type); g_string_free(sequence->length_field_name, TRUE); bt_ctf_field_path_destroy(sequence->length_field_path); @@ -2417,17 +2405,15 @@ void bt_ctf_field_type_sequence_destroy(struct bt_ctf_ref *ref) } static -void bt_ctf_field_type_string_destroy(struct bt_ctf_ref *ref) +void bt_ctf_field_type_string_destroy(struct bt_ctf_field_type *type) { - struct bt_ctf_field_type_string *string; + struct bt_ctf_field_type_string *string = + (struct bt_ctf_field_type_string *) type; - if (!ref) { + if (!type) { return; } - string = container_of( - container_of(ref, struct bt_ctf_field_type, ref_count), - struct bt_ctf_field_type_string, parent); g_free(string); }