X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fevent-fields.c;h=a93cf695c6c5a86c50c41889cd254177b4563640;hb=6c0c4a6a0759dbebd69f7ae08a5951964bd8bc39;hp=f9288f2b98f58d963345d27299f9b7cd4dfcf711;hpb=ca116246724bd6856b6291a00e304675bb166136;p=babeltrace.git diff --git a/formats/ctf/ir/event-fields.c b/formats/ctf/ir/event-fields.c index f9288f2b..a93cf695 100644 --- a/formats/ctf/ir/event-fields.c +++ b/formats/ctf/ir/event-fields.c @@ -150,7 +150,7 @@ static int increase_packet_size(struct ctf_stream_pos *pos); static -struct bt_ctf_field *(*field_create_funcs[])( +struct bt_ctf_field *(* const field_create_funcs[])( struct bt_ctf_field_type *) = { [CTF_TYPE_INTEGER] = bt_ctf_field_integer_create, [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_create, @@ -164,7 +164,7 @@ struct bt_ctf_field *(*field_create_funcs[])( }; static -void (*field_destroy_funcs[])(struct bt_ctf_field *) = { +void (* const field_destroy_funcs[])(struct bt_ctf_field *) = { [CTF_TYPE_INTEGER] = bt_ctf_field_integer_destroy, [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_destroy, [CTF_TYPE_FLOAT] = @@ -177,7 +177,7 @@ void (*field_destroy_funcs[])(struct bt_ctf_field *) = { }; static -int (*field_validate_funcs[])(struct bt_ctf_field *) = { +int (* const field_validate_funcs[])(struct bt_ctf_field *) = { [CTF_TYPE_INTEGER] = bt_ctf_field_generic_validate, [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_validate, [CTF_TYPE_FLOAT] = bt_ctf_field_generic_validate, @@ -189,7 +189,7 @@ int (*field_validate_funcs[])(struct bt_ctf_field *) = { }; static -int (*field_reset_funcs[])(struct bt_ctf_field *) = { +int (* const field_reset_funcs[])(struct bt_ctf_field *) = { [CTF_TYPE_INTEGER] = bt_ctf_field_generic_reset, [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_reset, [CTF_TYPE_FLOAT] = bt_ctf_field_generic_reset, @@ -201,7 +201,7 @@ int (*field_reset_funcs[])(struct bt_ctf_field *) = { }; static -int (*field_serialize_funcs[])(struct bt_ctf_field *, +int (* const field_serialize_funcs[])(struct bt_ctf_field *, struct ctf_stream_pos *) = { [CTF_TYPE_INTEGER] = bt_ctf_field_integer_serialize, [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_serialize, @@ -215,7 +215,8 @@ int (*field_serialize_funcs[])(struct bt_ctf_field *, }; static -int (*field_copy_funcs[])(struct bt_ctf_field *, struct bt_ctf_field *) = { +int (* const field_copy_funcs[])(struct bt_ctf_field *, + struct bt_ctf_field *) = { [CTF_TYPE_INTEGER] = bt_ctf_field_integer_copy, [CTF_TYPE_ENUM] = bt_ctf_field_enumeration_copy, [CTF_TYPE_FLOAT] = bt_ctf_field_floating_point_copy, @@ -1006,8 +1007,6 @@ struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field) goto end; } - bt_ctf_field_type_get(field->type); - copy->type = field->type; ret = field_copy_funcs[type_id](field, copy); if (ret) { bt_ctf_field_put(copy); @@ -1289,7 +1288,9 @@ void bt_ctf_field_string_destroy(struct bt_ctf_field *field) } string = container_of(field, struct bt_ctf_field_string, parent); - g_string_free(string->payload, TRUE); + if (string->payload) { + g_string_free(string->payload, TRUE); + } g_free(string); } @@ -1770,7 +1771,7 @@ int bt_ctf_field_integer_copy(struct bt_ctf_field *src, struct bt_ctf_field_integer *integer_src, *integer_dst; integer_src = container_of(src, struct bt_ctf_field_integer, parent); - integer_dst = container_of(src, struct bt_ctf_field_integer, parent); + integer_dst = container_of(dst, struct bt_ctf_field_integer, parent); memcpy(&integer_dst->definition, &integer_src->definition, sizeof(struct definition_integer)); @@ -1824,18 +1825,15 @@ static int bt_ctf_field_structure_copy(struct bt_ctf_field *src, struct bt_ctf_field *dst) { - int ret, i; + int ret = 0, i; struct bt_ctf_field_structure *struct_src, *struct_dst; struct_src = container_of(src, struct bt_ctf_field_structure, parent); struct_dst = container_of(dst, struct bt_ctf_field_structure, parent); + /* This field_name_to_index HT is owned by the structure field type */ struct_dst->field_name_to_index = struct_src->field_name_to_index; - struct_dst->fields = g_ptr_array_sized_new(struct_src->fields->len); - if (!struct_dst->fields) { - ret = -1; - goto end; - } + g_ptr_array_set_size(struct_dst->fields, struct_src->fields->len); for (i = 0; i < struct_src->fields->len; i++) { struct bt_ctf_field *field_copy = bt_ctf_field_copy( @@ -1845,7 +1843,7 @@ int bt_ctf_field_structure_copy(struct bt_ctf_field *src, ret = -1; goto end; } - g_ptr_array_add(struct_dst->fields, field_copy); + g_ptr_array_index(struct_dst->fields, i) = field_copy; } end: return ret; @@ -1889,7 +1887,7 @@ int bt_ctf_field_array_copy(struct bt_ctf_field *src, array_src = container_of(src, struct bt_ctf_field_array, parent); array_dst = container_of(dst, struct bt_ctf_field_array, parent); - array_dst->elements = g_ptr_array_sized_new(array_src->elements->len); + g_ptr_array_set_size(array_dst->elements, array_src->elements->len); for (i = 0; i < array_src->elements->len; i++) { struct bt_ctf_field *field_copy = bt_ctf_field_copy( g_ptr_array_index(array_src->elements, i)); @@ -1898,7 +1896,7 @@ int bt_ctf_field_array_copy(struct bt_ctf_field *src, ret = -1; goto end; } - g_ptr_array_add(array_dst->elements, field_copy); + g_ptr_array_index(array_dst->elements, i) = field_copy; } end: return ret; @@ -1914,7 +1912,7 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src, sequence_src = container_of(src, struct bt_ctf_field_sequence, parent); sequence_dst = container_of(dst, struct bt_ctf_field_sequence, parent); - sequence_dst->elements = g_ptr_array_sized_new( + g_ptr_array_set_size(sequence_dst->elements, sequence_src->elements->len); for (i = 0; i < sequence_src->elements->len; i++) { struct bt_ctf_field *field_copy = bt_ctf_field_copy( @@ -1924,7 +1922,7 @@ int bt_ctf_field_sequence_copy(struct bt_ctf_field *src, ret = -1; goto end; } - g_ptr_array_add(sequence_dst->elements, field_copy); + g_ptr_array_index(sequence_dst->elements, i) = field_copy; } end: return ret;