lib: remove clock class priority map, use default clock value
[babeltrace.git] / include / babeltrace / ctf-ir / fields-internal.h
index 2a4c78b0b8bfe4617756ac1291a5d6b853ff9ca6..b7aff55eb43fff7d8e0a6da52453a6613b95e81d 100644 (file)
@@ -51,7 +51,7 @@
                _name " is not set: %!+_f", (_field))
 
 #define BT_ASSERT_PRE_FIELD_COMMON_HOT(_field, _name)                  \
-       BT_ASSERT_PRE_HOT((_field), (_name), ": +%!+_f", (_field))
+       BT_ASSERT_PRE_HOT((_field), (_name), ": %!+_f", (_field))
 
 struct bt_field;
 struct bt_field_common;
@@ -164,7 +164,7 @@ struct bt_field_common *bt_field_common_copy(struct bt_field_common *field);
 BT_HIDDEN
 int bt_field_common_structure_initialize(struct bt_field_common *field,
                struct bt_field_type_common *type,
-               bt_object_release_func release_func,
+               bool is_shared, bt_object_release_func release_func,
                struct bt_field_common_methods *methods,
                bt_field_common_create_func field_create_func,
                GDestroyNotify field_release_func);
@@ -172,7 +172,7 @@ int bt_field_common_structure_initialize(struct bt_field_common *field,
 BT_HIDDEN
 int bt_field_common_array_initialize(struct bt_field_common *field,
                struct bt_field_type_common *type,
-               bt_object_release_func release_func,
+               bool is_shared, bt_object_release_func release_func,
                struct bt_field_common_methods *methods,
                bt_field_common_create_func field_create_func,
                GDestroyNotify field_destroy_func);
@@ -180,14 +180,14 @@ int bt_field_common_array_initialize(struct bt_field_common *field,
 BT_HIDDEN
 int bt_field_common_sequence_initialize(struct bt_field_common *field,
                struct bt_field_type_common *type,
-               bt_object_release_func release_func,
+               bool is_shared, bt_object_release_func release_func,
                struct bt_field_common_methods *methods,
                GDestroyNotify field_destroy_func);
 
 BT_HIDDEN
 int bt_field_common_variant_initialize(struct bt_field_common *field,
                struct bt_field_type_common *type,
-               bt_object_release_func release_func,
+               bool is_shared, bt_object_release_func release_func,
                struct bt_field_common_methods *methods,
                bt_field_common_create_func field_create_func,
                GDestroyNotify field_release_func);
@@ -195,7 +195,7 @@ int bt_field_common_variant_initialize(struct bt_field_common *field,
 BT_HIDDEN
 int bt_field_common_string_initialize(struct bt_field_common *field,
                struct bt_field_type_common *type,
-               bt_object_release_func release_func,
+               bool is_shared, bt_object_release_func release_func,
                struct bt_field_common_methods *methods);
 
 BT_HIDDEN
@@ -355,13 +355,13 @@ end:
 
 static inline
 void bt_field_common_initialize(struct bt_field_common *field,
-               struct bt_field_type_common *ft,
+               struct bt_field_type_common *ft, bool is_shared,
                bt_object_release_func release_func,
                struct bt_field_common_methods *methods)
 {
        BT_ASSERT(field);
        BT_ASSERT(ft);
-       bt_object_init(field, release_func);
+       bt_object_init(&field->base, is_shared, release_func);
        field->methods = methods;
        field->type = bt_get(ft);
 }
@@ -396,9 +396,12 @@ int bt_field_common_sequence_set_length(struct bt_field_common *field,
        struct bt_field_common_sequence *sequence = BT_FROM_COMMON(field);
 
        BT_ASSERT_PRE_NON_NULL(field, "Sequence field");
+       BT_ASSERT_PRE(((int64_t) length) >= 0,
+               "Invalid sequence length (too large): length=%" PRId64,
+               length);
        BT_ASSERT_PRE_FIELD_COMMON_HOT(field, "Sequence field");
 
-       if (length > sequence->elements->len) {
+       if (unlikely(length > sequence->elements->len)) {
                /* Make more room */
                struct bt_field_type_common_sequence *sequence_ft;
                uint64_t cur_len = sequence->elements->len;
@@ -654,27 +657,15 @@ const char *bt_field_common_string_get_value(struct bt_field_common *field)
 }
 
 static inline
-int bt_field_common_string_set_value(struct bt_field_common *field,
-               const char *value)
+int bt_field_common_string_clear(struct bt_field_common *field)
 {
-       struct bt_field_common_string *string = BT_FROM_COMMON(field);
-       size_t str_len;
+       struct bt_field_common_string *string_field = BT_FROM_COMMON(field);
 
        BT_ASSERT_PRE_NON_NULL(field, "String field");
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
        BT_ASSERT_PRE_FIELD_COMMON_HOT(field, "String field");
        BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field,
                BT_FIELD_TYPE_ID_STRING, "Field");
-
-       str_len = strlen(value);
-
-       if (str_len + 1 > string->buf->len) {
-               g_array_set_size(string->buf, str_len + 1);
-       }
-
-       memcpy(string->buf->data, value, str_len);
-       ((char *) string->buf->data)[str_len] = '\0';
-       string->size = str_len;
+       string_field->size = 0;
        bt_field_common_set(field, true);
        return 0;
 }
@@ -700,7 +691,7 @@ int bt_field_common_string_append_len(struct bt_field_common *field,
 
        new_size = string_field->size + length;
 
-       if (new_size + 1 > string_field->buf->len) {
+       if (unlikely(new_size + 1 > string_field->buf->len)) {
                g_array_set_size(string_field->buf, new_size + 1);
        }
 
@@ -717,23 +708,22 @@ int bt_field_common_string_append(struct bt_field_common *field,
                const char *value)
 {
        BT_ASSERT_PRE_NON_NULL(value, "Value");
-
        return bt_field_common_string_append_len(field, value,
                strlen(value));
 }
 
 static inline
-int bt_field_common_string_clear(struct bt_field_common *field)
+int bt_field_common_string_set_value(struct bt_field_common *field,
+               const char *value)
 {
-       struct bt_field_common_string *string_field = BT_FROM_COMMON(field);
-
        BT_ASSERT_PRE_NON_NULL(field, "String field");
+       BT_ASSERT_PRE_NON_NULL(value, "Value");
        BT_ASSERT_PRE_FIELD_COMMON_HOT(field, "String field");
        BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field,
                BT_FIELD_TYPE_ID_STRING, "Field");
-       string_field->size = 0;
-       bt_field_common_set(field, true);
-       return 0;
+       bt_field_common_string_clear(field);
+       return bt_field_common_string_append_len(field,
+               value, strlen(value));
 }
 
 static inline
This page took 0.027066 seconds and 4 git commands to generate.