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;
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().
++ */
}
}
}
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;
}
}
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:
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;
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:
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)
{
}
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;
}
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;
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:
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
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(
break;
}
}
-
+ end:
return ret;
}
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;
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 */
}
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);
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;
}