Merge branch 'master' into bindings/python
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 29 Nov 2013 06:19:33 +0000 (07:19 +0100)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 29 Nov 2013 06:19:33 +0000 (07:19 +0100)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
1  2 
formats/ctf/types/array.c
formats/ctf/types/float.c
formats/ctf/writer/event-fields.c
lib/iterator.c

index 04801d4f05455df71160f85b4cd0ed6d58c9d180,b1e8d6c5af7b316110b31920a7a61ed125ac4c98..979f7a3dc313895d29085e6de09e7ad904b675c0
@@@ -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;
  
                                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;
                        }
                }
index 9c60b737815ab587444a8a46b9ae12a63d003e3d,5fcae00451697bcd520fa6034f3471e84ccd7612..b82f68db91fbd901859ee3a8004ed6794c07b3a1
@@@ -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;
                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)
  {
index 7a37aaf989f4bd92607863b6b91b469662f50175,c2ad4c2447537b2370823b21f5dee2f238e53f58..c4d1b968587e33f00f24f8efe0c0658c201e6ba6
@@@ -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(
                        break;
                }
        }
+ end:
        return ret;
  }
  
diff --combined lib/iterator.c
index 966a00010e3e82a8393987f72f78b9e4d820c70f,3280f4a816c3a88468dfb99dd320111c24ded54d..a2a7bb578adca29313b9bda620382bfe67b8248c
@@@ -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 */
        }
  
        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;
  }
This page took 0.029414 seconds and 4 git commands to generate.