lib: remove clock class priority map, use default clock value
[babeltrace.git] / include / babeltrace / ctf-ir / fields-internal.h
index c616328cd4cbb61f2cd0a5a2e6be6129c9908d86..b7aff55eb43fff7d8e0a6da52453a6613b95e81d 100644 (file)
@@ -35,6 +35,7 @@
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/types.h>
 #include <stdint.h>
+#include <string.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <glib.h>
@@ -50,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;
@@ -149,7 +150,8 @@ struct bt_field_common_sequence {
 
 struct bt_field_common_string {
        struct bt_field_common common;
-       GString *payload;
+       GArray *buf;
+       size_t size;
 };
 
 struct bt_field_enumeration {
@@ -162,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);
@@ -170,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);
@@ -178,18 +180,24 @@ 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);
 
+BT_HIDDEN
+int bt_field_common_string_initialize(struct bt_field_common *field,
+               struct bt_field_type_common *type,
+               bool is_shared, bt_object_release_func release_func,
+               struct bt_field_common_methods *methods);
+
 BT_HIDDEN
 int bt_field_common_generic_validate(struct bt_field_common *field);
 
@@ -220,9 +228,6 @@ void bt_field_common_array_reset_recursive(struct bt_field_common *field);
 BT_HIDDEN
 void bt_field_common_sequence_reset_recursive(struct bt_field_common *field);
 
-BT_HIDDEN
-void bt_field_common_string_reset(struct bt_field_common *field);
-
 BT_HIDDEN
 void bt_field_common_generic_set_is_frozen(struct bt_field_common *field,
                bool is_frozen);
@@ -278,12 +283,12 @@ bt_bool bt_field_common_sequence_is_set_recursive(struct bt_field_common *field)
 # define bt_field_common_validate_recursive(_field)    (-1)
 # define bt_field_common_set_is_frozen_recursive(_field, _is_frozen)
 # define bt_field_common_is_set_recursive(_field)      (BT_FALSE)
-# define bt_field_common_reset_recursive(_field)       (BT_TRUE)
+# define bt_field_common_reset_recursive(_field)
 # define bt_field_common_set(_field, _val)
 # define bt_field_validate_recursive(_field)           (-1)
 # define bt_field_set_is_frozen_recursive(_field, _is_frozen)
 # define bt_field_is_set_recursive(_field)             (BT_FALSE)
-# define bt_field_reset_recursive(_field)              (BT_TRUE)
+# define bt_field_reset_recursive(_field)
 # define bt_field_set(_field, _val)
 #endif
 
@@ -350,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);
 }
@@ -391,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;
@@ -645,49 +653,19 @@ const char *bt_field_common_string_get_value(struct bt_field_common *field)
        BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field, "String field");
        BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field,
                BT_FIELD_TYPE_ID_STRING, "Field");
-       return string->payload->str;
-}
-
-static inline
-int bt_field_common_string_set_value(struct bt_field_common *field,
-               const char *value)
-{
-       struct bt_field_common_string *string = 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");
-
-       if (string->payload) {
-               g_string_assign(string->payload, value);
-       } else {
-               string->payload = g_string_new(value);
-       }
-
-       bt_field_common_set(field, true);
-       return 0;
+       return (const char *) string->buf->data;
 }
 
 static inline
-int bt_field_common_string_append(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_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");
-
-       if (string_field->payload) {
-               g_string_append(string_field->payload, value);
-       } else {
-               string_field->payload = g_string_new(value);
-       }
-
+       string_field->size = 0;
        bt_field_common_set(field, true);
        return 0;
 }
@@ -697,6 +675,8 @@ int bt_field_common_string_append_len(struct bt_field_common *field,
                const char *value, unsigned int length)
 {
        struct bt_field_common_string *string_field = BT_FROM_COMMON(field);
+       char *data;
+       size_t new_size;
 
        BT_ASSERT_PRE_NON_NULL(field, "String field");
        BT_ASSERT_PRE_NON_NULL(value, "Value");
@@ -704,39 +684,46 @@ int bt_field_common_string_append_len(struct bt_field_common *field,
        BT_ASSERT_PRE_FIELD_COMMON_HAS_TYPE_ID(field,
                BT_FIELD_TYPE_ID_STRING, "Field");
 
-       /* make sure no null bytes are appended */
+       /* Make sure no null bytes are appended */
        BT_ASSERT_PRE(memchr(value, '\0', length) == NULL,
                "String value to append contains a null character: "
                "partial-value=\"%.32s\", length=%u", value, length);
 
-       if (string_field->payload) {
-               g_string_append_len(string_field->payload, value, length);
-       } else {
-               string_field->payload = g_string_new_len(value, length);
+       new_size = string_field->size + length;
+
+       if (unlikely(new_size + 1 > string_field->buf->len)) {
+               g_array_set_size(string_field->buf, new_size + 1);
        }
 
+       data = string_field->buf->data;
+       memcpy(data + string_field->size, value, length);
+       ((char *) string_field->buf->data)[new_size] = '\0';
+       string_field->size = new_size;
        bt_field_common_set(field, true);
        return 0;
 }
 
 static inline
-int bt_field_common_string_clear(struct bt_field_common *field)
+int bt_field_common_string_append(struct bt_field_common *field,
+               const char *value)
 {
-       struct bt_field_common_string *string_field = BT_FROM_COMMON(field);
+       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_set_value(struct bt_field_common *field,
+               const char *value)
+{
        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");
-
-       if (string_field->payload) {
-               g_string_set_size(string_field->payload, 0);
-       } else {
-               string_field->payload = g_string_new(NULL);
-       }
-
-       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
@@ -859,8 +846,8 @@ void bt_field_common_string_finalize(struct bt_field_common *field)
        BT_LOGD("Finalizing common string field object: addr=%p", field);
        bt_field_common_finalize(field);
 
-       if (string->payload) {
-               g_string_free(string->payload, TRUE);
+       if (string->buf) {
+               g_array_free(string->buf, TRUE);
        }
 }
 
This page took 0.026609 seconds and 4 git commands to generate.