From: Mathieu Desnoyers Date: Fri, 29 Nov 2013 06:19:33 +0000 (+0100) Subject: Merge branch 'master' into bindings/python X-Git-Tag: v1.2.0-rc1~39 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=024e61817685a20caceb4e3ef3bdc019a7af6b6e;hp=-c Merge branch 'master' into bindings/python Signed-off-by: Mathieu Desnoyers --- 024e61817685a20caceb4e3ef3bdc019a7af6b6e diff --combined formats/ctf/types/array.c index 04801d4f,b1e8d6c5..979f7a3d --- a/formats/ctf/types/array.c +++ b/formats/ctf/types/array.c @@@ -48,7 -48,8 +48,8 @@@ int ctf_array_read(struct bt_stream_po if (integer_declaration->len == CHAR_BIT && integer_declaration->p.alignment == CHAR_BIT) { - ctf_align_pos(pos, integer_declaration->p.alignment); + if (!ctf_align_pos(pos, integer_declaration->p.alignment)) + return -EFAULT; if (!ctf_pos_access_ok(pos, array_declaration->len * CHAR_BIT)) return -EFAULT; @@@ -56,6 -57,9 +57,11 @@@ g_string_insert_len(array_definition->string, 0, (char *) ctf_get_pos_addr(pos), array_declaration->len); - if (!ctf_move_pos(pos, array_declaration->len * CHAR_BIT)) - return -EFAULT; - return 0; ++ /* ++ * We want to populate both the string ++ * and the underlying values, so carry ++ * on calling bt_array_rw(). ++ */ } } } @@@ -82,14 -86,16 +88,16 @@@ int ctf_array_write(struct bt_stream_po if (integer_declaration->len == CHAR_BIT && integer_declaration->p.alignment == CHAR_BIT) { - ctf_align_pos(pos, integer_declaration->p.alignment); + if (!ctf_align_pos(pos, integer_declaration->p.alignment)) + return -EFAULT; if (!ctf_pos_access_ok(pos, array_declaration->len * CHAR_BIT)) return -EFAULT; memcpy((char *) ctf_get_pos_addr(pos), array_definition->string->str, array_declaration->len); - ctf_move_pos(pos, array_declaration->len * CHAR_BIT); + if (!ctf_move_pos(pos, array_declaration->len * CHAR_BIT)) + return -EFAULT; return 0; } } diff --combined formats/ctf/types/float.c index 9c60b737,5fcae004..b82f68db --- a/formats/ctf/types/float.c +++ b/formats/ctf/types/float.c @@@ -200,8 -200,11 +200,11 @@@ int ctf_float_read(struct bt_stream_po ctf_init_pos(&destp, NULL, -1, O_RDWR); mmap_align_set_addr(&mma, (char *) u.bits); destp.base_mma = &mma; - destp.packet_size = sizeof(u) * CHAR_BIT; - ctf_align_pos(pos, float_declaration->p.alignment); + destp.content_size = destp.packet_size = sizeof(u) * CHAR_BIT; + if (!ctf_align_pos(pos, float_declaration->p.alignment)) { + ret = -EFAULT; + goto end_unref; + } ret = _ctf_float_copy(&destp.parent, tmpfloat, ppos, float_definition); switch (float_declaration->mantissa->len + 1) { case FLT_MANT_DIG: @@@ -256,7 -259,7 +259,7 @@@ int ctf_float_write(struct bt_stream_po ctf_init_pos(&srcp, NULL, -1, O_RDONLY); mmap_align_set_addr(&mma, (char *) u.bits); srcp.base_mma = &mma; - srcp.packet_size = sizeof(u) * CHAR_BIT; + srcp.content_size = srcp.packet_size = sizeof(u) * CHAR_BIT; switch (float_declaration->mantissa->len + 1) { case FLT_MANT_DIG: u.vf = float_definition->value; @@@ -268,7 -271,10 +271,10 @@@ ret = -EINVAL; goto end_unref; } - ctf_align_pos(pos, float_declaration->p.alignment); + if (!ctf_align_pos(pos, float_declaration->p.alignment)) { + ret = -EFAULT; + goto end_unref; + } ret = _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat); end_unref: @@@ -278,14 -284,6 +284,14 @@@ end return ret; } +double bt_get_float(const struct bt_definition *field) +{ + struct definition_float *definition = + container_of(field, struct definition_float, p); + + return definition->value; +} + static void __attribute__((constructor)) ctf_float_init(void) { diff --combined formats/ctf/writer/event-fields.c index 7a37aaf9,c2ad4c24..c4d1b968 --- a/formats/ctf/writer/event-fields.c +++ b/formats/ctf/writer/event-fields.c @@@ -179,8 -179,8 +179,8 @@@ struct bt_ctf_field *bt_ctf_field_creat } type_id = bt_ctf_field_type_get_type_id(type); - if (type_id <= CTF_TYPE_UNKNOWN || - type_id >= NR_CTF_TYPES) { + if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES || + bt_ctf_field_type_validate(type)) { goto error; } @@@ -247,13 -247,14 +247,14 @@@ int bt_ctf_field_sequence_set_length(st bt_ctf_field_put(sequence->length); } - sequence->elements = g_ptr_array_new_full((size_t)sequence_length, - (GDestroyNotify)bt_ctf_field_put); + sequence->elements = g_ptr_array_sized_new((size_t)sequence_length); if (!sequence->elements) { ret = -1; goto end; } + 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); sequence->length = length_field; @@@ -768,12 -769,13 +769,13 @@@ struct bt_ctf_field *bt_ctf_field_array array_type = container_of(type, struct bt_ctf_field_type_array, parent); array_length = array_type->length; - array->elements = g_ptr_array_new_full(array_length, - (GDestroyNotify)bt_ctf_field_put); + array->elements = g_ptr_array_sized_new(array_length); if (!array->elements) { goto error; } + g_ptr_array_set_free_func(array->elements, + (GDestroyNotify)bt_ctf_field_put); g_ptr_array_set_size(array->elements, array_length); return &array->parent; error: @@@ -939,7 -941,7 +941,7 @@@ void bt_ctf_field_string_destroy(struc static int bt_ctf_field_generic_validate(struct bt_ctf_field *field) { - return !(field && field->payload_set); + return (field && field->payload_set) ? 0 : -1; } static @@@ -1123,10 -1125,16 +1125,16 @@@ int bt_ctf_field_structure_serialize(st while (!ctf_pos_access_ok(pos, offset_align(pos->offset, field->type->declaration->alignment))) { - increase_packet_size(pos); + ret = increase_packet_size(pos); + if (ret) { + goto end; + } } - ctf_align_pos(pos, field->type->declaration->alignment); + if (!ctf_align_pos(pos, field->type->declaration->alignment)) { + ret = -1; + goto end; + } for (i = 0; i < structure->fields->len; i++) { struct bt_ctf_field *field = g_ptr_array_index( @@@ -1137,7 -1145,7 +1145,7 @@@ break; } } - + end: return ret; } diff --combined lib/iterator.c index 966a0001,3280f4a8..a2a7bb57 --- a/lib/iterator.c +++ b/lib/iterator.c @@@ -65,6 -65,9 +65,9 @@@ static int stream_read_event(struct ctf ret = sin->pos.parent.event_cb(&sin->pos.parent, &sin->parent); if (ret == EOF) return EOF; + else if (ret == EAGAIN) + /* Stream is inactive for now (live reading). */ + return EAGAIN; else if (ret) { fprintf(stderr, "[error] Reading event failed.\n"); return ret; @@@ -702,21 -705,27 +705,21 @@@ int bt_iter_init(struct bt_iter *iter for (filenr = 0; filenr < stream->streams->len; filenr++) { struct ctf_file_stream *file_stream; + struct bt_iter_pos pos; file_stream = g_ptr_array_index(stream->streams, filenr); if (!file_stream) continue; - if (begin_pos) { - ret = babeltrace_filestream_seek( - file_stream, - begin_pos, - stream_id); - } else { - struct bt_iter_pos pos; - pos.type = BT_SEEK_BEGIN; - ret = babeltrace_filestream_seek( - file_stream, &pos, - stream_id); - } + + pos.type = BT_SEEK_BEGIN; + ret = babeltrace_filestream_seek(file_stream, + &pos, stream_id); + if (ret == EOF) { ret = 0; continue; - } else if (ret) { + } else if (ret != 0 && ret != EAGAIN) { goto error; } /* Add to heap */ @@@ -728,11 -737,7 +731,11 @@@ } ctx->current_iterator = iter; - return 0; + if (begin_pos && begin_pos->type != BT_SEEK_BEGIN) { + ret = bt_iter_set_pos(iter, begin_pos); + } + + return ret; error: bt_heap_free(iter->stream_heap); @@@ -801,13 -806,28 +804,28 @@@ int bt_iter_next(struct bt_iter *iter assert(removed == file_stream); ret = 0; goto end; + } else if (ret == EAGAIN) { + /* + * The stream is inactive for now, we just updated the timestamp_end + * to skip over this stream up to a certain point in time. + */ + goto reinsert; } else if (ret) { goto end; } + + reinsert: /* Reinsert the file stream into the heap, and rebalance. */ removed = bt_heap_replace_max(iter->stream_heap, file_stream); assert(removed == file_stream); + file_stream = bt_heap_maximum(iter->stream_heap); + if (file_stream->pos.content_size == 0) { + ret = EAGAIN; + } else { + ret = 0; + } + end: return ret; }