ir: rename ctf_string_encoding -> bt_ctf_string_encoding
[babeltrace.git] / formats / ctf / ir / event-fields.c
index a3de98f617063a121e9f9b75da79ed3ad1bc6395..4383e2a33783ee221af1115a493bf1845ff46c6a 100644 (file)
@@ -32,6 +32,7 @@
 #include <babeltrace/object-internal.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/compiler.h>
+#include <babeltrace/compat/fcntl.h>
 
 #define PACKET_LEN_INCREMENT   (getpagesize() * 8 * CHAR_BIT)
 
@@ -233,14 +234,22 @@ struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type)
 {
        struct bt_ctf_field *field = NULL;
        enum ctf_type_id type_id;
+       int ret;
 
        if (!type) {
                goto error;
        }
 
        type_id = bt_ctf_field_type_get_type_id(type);
-       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES ||
-               bt_ctf_field_type_validate(type)) {
+       if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) {
+               goto error;
+       }
+
+       /* Field class MUST be valid */
+       ret = bt_ctf_field_type_validate(type);
+
+       if (ret) {
+               /* Invalid */
                goto error;
        }
 
@@ -282,6 +291,59 @@ end:
        return ret;
 }
 
+enum ctf_type_id bt_ctf_field_get_type_id(struct bt_ctf_field *field)
+{
+       enum ctf_type_id ret = CTF_TYPE_UNKNOWN;
+
+       if (!field) {
+               goto end;
+       }
+
+       ret = bt_ctf_field_type_get_type_id(field->type);
+end:
+       return ret;
+}
+
+int bt_ctf_field_is_integer(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_INTEGER;
+}
+
+int bt_ctf_field_is_floating_point(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_FLOAT;
+}
+
+int bt_ctf_field_is_enumeration(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_ENUM;
+}
+
+int bt_ctf_field_is_string(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_STRING;
+}
+
+int bt_ctf_field_is_structure(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_STRUCT;
+}
+
+int bt_ctf_field_is_array(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_ARRAY;
+}
+
+int bt_ctf_field_is_sequence(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_SEQUENCE;
+}
+
+int bt_ctf_field_is_variant(struct bt_ctf_field *field)
+{
+       return bt_ctf_field_get_type_id(field) == CTF_TYPE_VARIANT;
+}
+
 struct bt_ctf_field *bt_ctf_field_sequence_get_length(
                struct bt_ctf_field *field)
 {
@@ -473,7 +535,8 @@ int bt_ctf_field_structure_set_field(struct bt_ctf_field *field,
        expected_field_type =
                bt_ctf_field_type_structure_get_field_type_by_name(field->type,
                name);
-       if (expected_field_type != value->type) {
+
+       if (bt_ctf_field_type_compare(expected_field_type, value->type)) {
                ret = -1;
                goto end;
        }
@@ -614,6 +677,7 @@ struct bt_ctf_field *bt_ctf_field_variant_get_field(struct bt_ctf_field *field,
 
                cur_tag_container =
                        bt_ctf_field_enumeration_get_container(variant->tag);
+               assert(cur_tag_container);
                cur_tag_enum_integer = container_of(cur_tag_container,
                        struct bt_ctf_field_integer, parent);
                bt_put(cur_tag_container);
@@ -1204,7 +1268,7 @@ struct bt_ctf_field *bt_ctf_field_structure_create(
                struct bt_ctf_field_structure, 1);
        struct bt_ctf_field *field = NULL;
 
-       if (!structure || !structure_type->fields->len) {
+       if (!structure) {
                goto end;
        }
 
@@ -2117,9 +2181,13 @@ int increase_packet_size(struct ctf_stream_pos *pos)
        }
 
        pos->packet_size += PACKET_LEN_INCREMENT;
-       ret = posix_fallocate(pos->fd, pos->mmap_offset,
-               pos->packet_size / CHAR_BIT);
+       do {
+               ret = bt_posix_fallocate(pos->fd, pos->mmap_offset,
+                       pos->packet_size / CHAR_BIT);
+       } while (ret == EINTR);
        if (ret) {
+               errno = EINTR;
+               ret = -1;
                goto end;
        }
 
This page took 0.025722 seconds and 4 git commands to generate.