X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fir%2Ftrace.c;h=9c3cb5072a593b0e5cde93425eda3ae5b004c6fe;hp=073e4abffb83c8ba11f802e5ce29d0949e312fa1;hb=4841ccc167f5f99267a0c129a1e79214b60f553c;hpb=bc37ae52aa6face901440bf7eb2171104b5343d8 diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 073e4abf..9c3cb507 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -32,24 +32,23 @@ #include #include #include +#include +#include +#include +#include +#include #include +#include #define DEFAULT_IDENTIFIER_SIZE 128 #define DEFAULT_METADATA_STRING_SIZE 4096 static -void environment_variable_destroy(struct environment_variable *var); -static -void bt_ctf_trace_destroy(struct bt_ctf_ref *ref); +void bt_ctf_trace_destroy(struct bt_ref *ref); static int init_trace_packet_header(struct bt_ctf_trace *trace); - static -const char * const reserved_keywords_str[] = {"align", "callsite", - "const", "char", "clock", "double", "enum", "env", "event", - "floating_point", "float", "integer", "int", "long", "short", "signed", - "stream", "string", "struct", "trace", "typealias", "typedef", - "unsigned", "variant", "void" "_Bool", "_Complex", "_Imaginary"}; +int bt_ctf_trace_freeze(struct bt_ctf_trace *trace); static const unsigned int field_type_aliases_alignments[] = { @@ -69,9 +68,12 @@ const unsigned int field_type_aliases_sizes[] = { [FIELD_TYPE_ALIAS_UINT64_T] = 64, }; -static GHashTable *reserved_keywords_set; -static int init_done; -static int global_data_refcount; +static +void put_stream_class(struct bt_ctf_stream_class *stream_class) +{ + (void) bt_ctf_stream_class_set_trace(stream_class, NULL); + bt_ctf_stream_class_put(stream_class); +} struct bt_ctf_trace *bt_ctf_trace_create(void) { @@ -83,17 +85,14 @@ struct bt_ctf_trace *bt_ctf_trace_create(void) } bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE); - bt_ctf_ref_init(&trace->ref_count); - trace->environment = g_ptr_array_new_with_free_func( - (GDestroyNotify)environment_variable_destroy); + bt_ctf_base_init(trace, bt_ctf_trace_destroy); trace->clocks = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_clock_put); + (GDestroyNotify) bt_ctf_clock_put); trace->streams = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_stream_put); + (GDestroyNotify) bt_ctf_stream_put); trace->stream_classes = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_stream_class_put); - if (!trace->environment || !trace->clocks || - !trace->stream_classes || !trace->streams) { + (GDestroyNotify) put_stream_class); + if (!trace->clocks || !trace->stream_classes || !trace->streams) { goto error_destroy; } @@ -103,26 +102,34 @@ struct bt_ctf_trace *bt_ctf_trace_create(void) goto error_destroy; } + /* Create the environment array object */ + trace->environment = bt_ctf_attributes_create(); + if (!trace->environment) { + goto error_destroy; + } + return trace; error_destroy: - bt_ctf_trace_destroy(&trace->ref_count); + bt_ctf_trace_destroy(&trace->base.ref_count); trace = NULL; error: return trace; } -void bt_ctf_trace_destroy(struct bt_ctf_ref *ref) +void bt_ctf_trace_destroy(struct bt_ref *ref) { struct bt_ctf_trace *trace; + struct bt_ctf_base *base; if (!ref) { return; } - trace = container_of(ref, struct bt_ctf_trace, ref_count); + base = container_of(ref, struct bt_ctf_base, ref_count); + trace = container_of(base, struct bt_ctf_trace, base); if (trace->environment) { - g_ptr_array_free(trace->environment, TRUE); + bt_ctf_attributes_destroy(trace->environment); } if (trace->clocks) { @@ -137,8 +144,7 @@ void bt_ctf_trace_destroy(struct bt_ctf_ref *ref) g_ptr_array_free(trace->stream_classes, TRUE); } - bt_ctf_field_type_put(trace->trace_packet_header_type); - bt_ctf_field_put(trace->trace_packet_header); + bt_ctf_field_type_put(trace->packet_header_type); g_free(trace); } @@ -154,18 +160,6 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace, goto error; } - ret = bt_ctf_stream_class_set_byte_order(stream_class, - trace->byte_order == LITTLE_ENDIAN ? - BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN); - if (ret) { - goto error; - } - - stream = bt_ctf_stream_create(stream_class); - if (!stream) { - goto error; - } - for (i = 0; i < trace->stream_classes->len; i++) { if (trace->stream_classes->pdata[i] == stream_class) { stream_class_found = 1; @@ -173,88 +167,219 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace, } if (!stream_class_found) { - int64_t stream_id = bt_ctf_stream_class_get_id(stream_class); - - if (stream_id < 0) { - /* Try to assign a new stream id */ - if (bt_ctf_stream_class_set_id(stream->stream_class, - trace->next_stream_id++)) { - goto error; - } + ret = bt_ctf_trace_add_stream_class(trace, stream_class); + if (ret) { + goto error; } + } - for (i = 0; i < trace->stream_classes->len; i++) { - if (stream_id == bt_ctf_stream_class_get_id( - trace->stream_classes->pdata[i])) { - /* Duplicate stream id found */ - goto error; - } - } - bt_ctf_stream_class_get(stream->stream_class); - g_ptr_array_add(trace->stream_classes, stream->stream_class); + stream = bt_ctf_stream_create(stream_class, trace); + if (!stream) { + goto error; } bt_ctf_stream_get(stream); g_ptr_array_add(trace->streams, stream); - trace->frozen = 1; - return stream; + return stream; error: bt_ctf_stream_put(stream); return NULL; } -int bt_ctf_trace_add_environment_field(struct bt_ctf_trace *trace, - const char *name, - const char *value) +int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace, + const char *name, struct bt_value *value) { - struct environment_variable *var = NULL; - char *escaped_value = NULL; int ret = 0; - if (!trace || !name || !value || validate_identifier(name)) { + if (!trace || !name || !value || + bt_ctf_validate_identifier(name) || + !(bt_value_is_integer(value) || bt_value_is_string(value))) { ret = -1; - goto error; + goto end; } if (strchr(name, ' ')) { ret = -1; - goto error; + goto end; + } + + if (trace->frozen) { + /* + * New environment fields may be added to a frozen trace, + * but existing fields may not be changed. + * + * The object passed is frozen like all other attributes. + */ + struct bt_value *attribute = + bt_ctf_attributes_get_field_value_by_name( + trace->environment, name); + + if (attribute) { + BT_VALUE_PUT(attribute); + ret = -1; + goto end; + } + + bt_value_freeze(value); } - var = g_new0(struct environment_variable, 1); - if (!var) { + ret = bt_ctf_attributes_set_field_value(trace->environment, name, + value); + +end: + return ret; +} + +int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace, + const char *name, const char *value) +{ + int ret = 0; + struct bt_value *env_value_string_obj = NULL; + + if (!trace || !name || !value) { ret = -1; - goto error; + goto end; + } + + if (trace->frozen) { + /* + * New environment fields may be added to a frozen trace, + * but existing fields may not be changed. + */ + struct bt_value *attribute = + bt_ctf_attributes_get_field_value_by_name( + trace->environment, name); + + if (attribute) { + BT_VALUE_PUT(attribute); + ret = -1; + goto end; + } } - escaped_value = g_strescape(value, NULL); - if (!escaped_value) { + env_value_string_obj = bt_value_string_create_init(value); + + if (!env_value_string_obj) { ret = -1; - goto error; + goto end; + } + + if (trace->frozen) { + bt_value_freeze(env_value_string_obj); } + ret = bt_ctf_trace_set_environment_field(trace, name, + env_value_string_obj); - var->name = g_string_new(name); - var->value = g_string_new(escaped_value); - g_free(escaped_value); - if (!var->name || !var->value) { +end: + BT_VALUE_PUT(env_value_string_obj); + + return ret; +} + +int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace *trace, + const char *name, int64_t value) +{ + int ret = 0; + struct bt_value *env_value_integer_obj = NULL; + + if (!trace || !name) { ret = -1; - goto error; + goto end; + } + + if (trace->frozen) { + /* + * New environment fields may be added to a frozen trace, + * but existing fields may not be changed. + */ + struct bt_value *attribute = + bt_ctf_attributes_get_field_value_by_name( + trace->environment, name); + + if (attribute) { + BT_VALUE_PUT(attribute); + ret = -1; + goto end; + } } - g_ptr_array_add(trace->environment, var); + env_value_integer_obj = bt_value_integer_create_init(value); + if (!env_value_integer_obj) { + ret = -1; + goto end; + } + + ret = bt_ctf_trace_set_environment_field(trace, name, + env_value_integer_obj); + if (trace->frozen) { + bt_value_freeze(env_value_integer_obj); + } +end: + BT_VALUE_PUT(env_value_integer_obj); + return ret; +} -error: - if (var && var->name) { - g_string_free(var->name, TRUE); +int bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace *trace) +{ + int ret = 0; + + if (!trace) { + ret = -1; + goto end; + } + + ret = bt_ctf_attributes_get_count(trace->environment); + +end: + return ret; +} + +const char * +bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace, + int index) +{ + const char *ret = NULL; + + if (!trace) { + goto end; } - if (var && var->value) { - g_string_free(var->value, TRUE); + ret = bt_ctf_attributes_get_field_name(trace->environment, index); + +end: + return ret; +} + +struct bt_value *bt_ctf_trace_get_environment_field_value( + struct bt_ctf_trace *trace, int index) +{ + struct bt_value *ret = NULL; + + if (!trace) { + goto end; } - g_free(var); + ret = bt_ctf_attributes_get_field_value(trace->environment, index); + +end: + return ret; +} + +struct bt_value *bt_ctf_trace_get_environment_field_value_by_name( + struct bt_ctf_trace *trace, const char *name) +{ + struct bt_value *ret = NULL; + + if (!trace || !name) { + goto end; + } + + ret = bt_ctf_attributes_get_field_value_by_name(trace->environment, + name); + +end: return ret; } @@ -282,6 +407,204 @@ end: return ret; } +int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace) +{ + int ret = -1; + + if (!trace) { + goto end; + } + + ret = trace->clocks->len; +end: + return ret; +} + +struct bt_ctf_clock *bt_ctf_trace_get_clock(struct bt_ctf_trace *trace, + int index) +{ + struct bt_ctf_clock *clock = NULL; + + if (!trace || index < 0 || index >= trace->clocks->len) { + goto end; + } + + clock = g_ptr_array_index(trace->clocks, index); + bt_ctf_clock_get(clock); +end: + return clock; +} + +int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, + struct bt_ctf_stream_class *stream_class) +{ + int ret, i; + int64_t stream_id; + + if (!trace || !stream_class) { + ret = -1; + goto end; + } + + for (i = 0; i < trace->stream_classes->len; i++) { + if (trace->stream_classes->pdata[i] == stream_class) { + /* Stream already registered to the trace */ + ret = -1; + goto end; + } + } + + ret = bt_ctf_stream_class_resolve_types(stream_class, trace); + if (ret) { + goto end; + } + + stream_id = bt_ctf_stream_class_get_id(stream_class); + if (stream_id < 0) { + stream_id = trace->next_stream_id++; + + /* Try to assign a new stream id */ + for (i = 0; i < trace->stream_classes->len; i++) { + if (stream_id == bt_ctf_stream_class_get_id( + trace->stream_classes->pdata[i])) { + /* Duplicate stream id found */ + ret = -1; + goto end; + } + } + + if (bt_ctf_stream_class_set_id_no_check(stream_class, + stream_id)) { + /* TODO Should retry with a different stream id */ + ret = -1; + goto end; + } + } + + /* Set weak reference to trace in stream class */ + ret = bt_ctf_stream_class_set_trace(stream_class, trace); + if (ret) { + /* Stream class already part of another trace */ + goto end; + } + + bt_ctf_stream_class_get(stream_class); + g_ptr_array_add(trace->stream_classes, stream_class); + + /* + * Freeze the trace and its packet header. + * + * All field type byte orders set as "native" byte ordering can now be + * safely set to trace's own endianness, including the stream class'. + */ + bt_ctf_field_type_set_native_byte_order(trace->packet_header_type, + trace->byte_order); + ret = bt_ctf_stream_class_set_byte_order(stream_class, + trace->byte_order == LITTLE_ENDIAN ? + BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : BT_CTF_BYTE_ORDER_BIG_ENDIAN); + if (ret) { + goto end; + } + + bt_ctf_stream_class_freeze(stream_class); + if (!trace->frozen) { + ret = bt_ctf_trace_freeze(trace); + goto end; + } +end: + if (ret) { + (void) bt_ctf_stream_class_set_trace(stream_class, NULL); + } + return ret; +} + +int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace) +{ + int ret; + + if (!trace) { + ret = -1; + goto end; + } + + ret = trace->stream_classes->len; +end: + return ret; +} + +struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class( + struct bt_ctf_trace *trace, int index) +{ + struct bt_ctf_stream_class *stream_class = NULL; + + if (!trace || index < 0 || index >= trace->stream_classes->len) { + goto end; + } + + stream_class = g_ptr_array_index(trace->stream_classes, index); + bt_ctf_stream_class_get(stream_class); +end: + return stream_class; +} + +struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id( + struct bt_ctf_trace *trace, uint32_t id) +{ + int i; + struct bt_ctf_stream_class *stream_class = NULL; + + if (!trace) { + goto end; + } + + for (i = 0; i < trace->stream_classes->len; ++i) { + struct bt_ctf_stream_class *stream_class_candidate; + + stream_class_candidate = + g_ptr_array_index(trace->stream_classes, i); + + if (bt_ctf_stream_class_get_id(stream_class_candidate) == + (int64_t) id) { + stream_class = stream_class_candidate; + bt_ctf_get(stream_class); + goto end; + } + } + +end: + return stream_class; +} + +struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name( + struct bt_ctf_trace *trace, const char *name) +{ + size_t i; + struct bt_ctf_clock *clock = NULL; + + if (!trace || !name) { + goto end; + } + + for (i = 0; i < trace->clocks->len; ++i) { + struct bt_ctf_clock *cur_clk = + g_ptr_array_index(trace->clocks, i); + const char *cur_clk_name = bt_ctf_clock_get_name(cur_clk); + + if (!cur_clk_name) { + goto end; + } + + if (!strcmp(cur_clk_name, name)) { + clock = cur_clk; + bt_ctf_clock_get(clock); + goto end; + } + } + +end: + return clock; +} + BT_HIDDEN const char *get_byte_order_string(int byte_order) { @@ -326,7 +649,7 @@ int append_trace_metadata(struct bt_ctf_trace *trace, g_string_append(context->string, "\tpacket.header := "); context->current_indentation_level++; g_string_assign(context->field_name, ""); - ret = bt_ctf_field_type_serialize(trace->trace_packet_header_type, + ret = bt_ctf_field_type_serialize(trace->packet_header_type, context); if (ret) { goto end; @@ -338,25 +661,85 @@ end: return ret; } -static -void append_env_field_metadata(struct environment_variable *var, - struct metadata_context *context) -{ - g_string_append_printf(context->string, "\t%s = \"%s\";\n", - var->name->str, var->value->str); -} - static void append_env_metadata(struct bt_ctf_trace *trace, struct metadata_context *context) { - if (trace->environment->len == 0) { + int i; + int env_size; + + env_size = bt_ctf_attributes_get_count(trace->environment); + + if (env_size <= 0) { return; } g_string_append(context->string, "env {\n"); - g_ptr_array_foreach(trace->environment, - (GFunc)append_env_field_metadata, context); + + for (i = 0; i < env_size; ++i) { + struct bt_value *env_field_value_obj = NULL; + const char *entry_name; + + entry_name = bt_ctf_attributes_get_field_name( + trace->environment, i); + env_field_value_obj = bt_ctf_attributes_get_field_value( + trace->environment, i); + + if (!entry_name || !env_field_value_obj) { + goto loop_next; + } + + switch (bt_value_get_type(env_field_value_obj)) { + case BT_VALUE_TYPE_INTEGER: + { + int ret; + int64_t int_value; + + ret = bt_value_integer_get(env_field_value_obj, + &int_value); + + if (ret) { + goto loop_next; + } + + g_string_append_printf(context->string, + "\t%s = %" PRId64 ";\n", entry_name, + int_value); + break; + } + case BT_VALUE_TYPE_STRING: + { + int ret; + const char *str_value; + char *escaped_str = NULL; + + ret = bt_value_string_get(env_field_value_obj, + &str_value); + + if (ret) { + goto loop_next; + } + + escaped_str = g_strescape(str_value, NULL); + + if (!escaped_str) { + goto loop_next; + } + + g_string_append_printf(context->string, + "\t%s = \"%s\";\n", entry_name, escaped_str); + free(escaped_str); + break; + } + + default: + goto loop_next; + } + +loop_next: + BT_VALUE_PUT(env_field_value_obj); + } + g_string_append(context->string, "};\n\n"); } @@ -403,6 +786,28 @@ end: return metadata; } +enum bt_ctf_byte_order bt_ctf_trace_get_byte_order(struct bt_ctf_trace *trace) +{ + enum bt_ctf_byte_order ret = BT_CTF_BYTE_ORDER_UNKNOWN; + + if (!trace) { + goto end; + } + + switch (trace->byte_order) { + case BIG_ENDIAN: + ret = BT_CTF_BYTE_ORDER_BIG_ENDIAN; + break; + case LITTLE_ENDIAN: + ret = BT_CTF_BYTE_ORDER_LITTLE_ENDIAN; + break; + default: + break; + } +end: + return ret; +} + int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace, enum bt_ctf_byte_order byte_order) { @@ -416,7 +821,16 @@ int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace, switch (byte_order) { case BT_CTF_BYTE_ORDER_NATIVE: - internal_byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN) ? + /* + * This doesn't make sense since the CTF specification defines + * the "native" byte order as "the byte order described in the + * trace description". However, this behavior had been + * implemented as part of v1.2 and is kept to maintain + * compatibility. + * + * This may be changed on a major version bump only. + */ + internal_byte_order = (G_BYTE_ORDER == G_LITTLE_ENDIAN) ? LITTLE_ENDIAN : BIG_ENDIAN; break; case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN: @@ -432,90 +846,99 @@ int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace, } trace->byte_order = internal_byte_order; - if (trace->trace_packet_header_type || - trace->trace_packet_header) { - init_trace_packet_header(trace); - } end: return ret; } -void bt_ctf_trace_get(struct bt_ctf_trace *trace) +struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type( + struct bt_ctf_trace *trace) { - if (!trace) { - return; - } - - bt_ctf_ref_get(&trace->ref_count); -} + struct bt_ctf_field_type *field_type = NULL; -void bt_ctf_trace_put(struct bt_ctf_trace *trace) -{ if (!trace) { - return; + goto end; } - bt_ctf_ref_put(&trace->ref_count, bt_ctf_trace_destroy); + bt_ctf_field_type_get(trace->packet_header_type); + field_type = trace->packet_header_type; +end: + return field_type; } -BT_HIDDEN -int validate_identifier(const char *input_string) +int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace, + struct bt_ctf_field_type *packet_header_type) { int ret = 0; - char *string = NULL; - char *save_ptr, *token; - if (!input_string || input_string[0] == '\0') { + if (!trace || !packet_header_type || trace->frozen) { ret = -1; goto end; } - string = strdup(input_string); - if (!string) { + /* packet_header_type must be a structure */ + if (bt_ctf_field_type_get_type_id(packet_header_type) != + CTF_TYPE_STRUCT) { ret = -1; goto end; } - token = strtok_r(string, " ", &save_ptr); - while (token) { - if (g_hash_table_lookup_extended(reserved_keywords_set, - GINT_TO_POINTER(g_quark_from_string(token)), - NULL, NULL)) { - ret = -1; - goto end; - } - - token = strtok_r(NULL, " ", &save_ptr); - } + bt_ctf_field_type_get(packet_header_type); + bt_ctf_field_type_put(trace->packet_header_type); + trace->packet_header_type = packet_header_type; end: - free(string); return ret; } +void bt_ctf_trace_get(struct bt_ctf_trace *trace) +{ + bt_ctf_get(trace); +} + +void bt_ctf_trace_put(struct bt_ctf_trace *trace) +{ + bt_ctf_put(trace); + +} + BT_HIDDEN struct bt_ctf_field_type *get_field_type(enum field_type_alias alias) { unsigned int alignment, size; - struct bt_ctf_field_type *field_type; + struct bt_ctf_field_type *field_type = NULL; if (alias >= NR_FIELD_TYPE_ALIAS) { - return NULL; + goto end; } alignment = field_type_aliases_alignments[alias]; size = field_type_aliases_sizes[alias]; field_type = bt_ctf_field_type_integer_create(size); bt_ctf_field_type_set_alignment(field_type, alignment); +end: return field_type; } +static +int bt_ctf_trace_freeze(struct bt_ctf_trace *trace) +{ + int ret = 0; + + ret = bt_ctf_trace_resolve_types(trace); + if (ret) { + goto end; + } + + bt_ctf_attributes_freeze(trace->environment); + trace->frozen = 1; +end: + return ret; +} + static int init_trace_packet_header(struct bt_ctf_trace *trace) { - size_t i; int ret = 0; - struct bt_ctf_field *trace_packet_header = NULL, - *magic = NULL, *uuid_array = NULL; + struct bt_ctf_field *magic = NULL, *uuid_array = NULL; struct bt_ctf_field_type *_uint32_t = get_field_type(FIELD_TYPE_ALIAS_UINT32_T); struct bt_ctf_field_type *_uint8_t = @@ -530,14 +953,6 @@ int init_trace_packet_header(struct bt_ctf_trace *trace) goto end; } - ret = bt_ctf_field_type_set_byte_order(_uint32_t, - (trace->byte_order == LITTLE_ENDIAN ? - BT_CTF_BYTE_ORDER_LITTLE_ENDIAN : - BT_CTF_BYTE_ORDER_BIG_ENDIAN)); - if (ret) { - goto end; - } - ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "magic"); if (ret) { @@ -556,84 +971,18 @@ int init_trace_packet_header(struct bt_ctf_trace *trace) goto end; } - trace_packet_header = bt_ctf_field_create(trace_packet_header_type); - if (!trace_packet_header) { - ret = -1; - goto end; - } - - magic = bt_ctf_field_structure_get_field(trace_packet_header, "magic"); - ret = bt_ctf_field_unsigned_integer_set_value(magic, 0xC1FC1FC1); + ret = bt_ctf_trace_set_packet_header_type(trace, + trace_packet_header_type); if (ret) { goto end; } - - uuid_array = bt_ctf_field_structure_get_field(trace_packet_header, - "uuid"); - for (i = 0; i < 16; i++) { - struct bt_ctf_field *uuid_element = - bt_ctf_field_array_get_field(uuid_array, i); - ret = bt_ctf_field_unsigned_integer_set_value(uuid_element, - trace->uuid[i]); - bt_ctf_field_put(uuid_element); - if (ret) { - goto end; - } - } - - bt_ctf_field_type_put(trace->trace_packet_header_type); - bt_ctf_field_put(trace->trace_packet_header); - trace->trace_packet_header_type = trace_packet_header_type; - trace->trace_packet_header = trace_packet_header; end: bt_ctf_field_type_put(uuid_array_type); bt_ctf_field_type_put(_uint32_t); bt_ctf_field_type_put(_uint8_t); bt_ctf_field_put(magic); bt_ctf_field_put(uuid_array); - if (ret) { - bt_ctf_field_type_put(trace_packet_header_type); - bt_ctf_field_put(trace_packet_header); - } + bt_ctf_field_type_put(trace_packet_header_type); return ret; } - -static -void environment_variable_destroy(struct environment_variable *var) -{ - g_string_free(var->name, TRUE); - g_string_free(var->value, TRUE); - g_free(var); -} - -static __attribute__((constructor)) -void trace_init(void) -{ - size_t i; - const size_t reserved_keywords_count = - sizeof(reserved_keywords_str) / sizeof(char *); - - global_data_refcount++; - if (init_done) { - return; - } - - reserved_keywords_set = g_hash_table_new(g_direct_hash, g_direct_equal); - for (i = 0; i < reserved_keywords_count; i++) { - gpointer quark = GINT_TO_POINTER(g_quark_from_string( - reserved_keywords_str[i])); - - g_hash_table_insert(reserved_keywords_set, quark, quark); - } - - init_done = 1; -} - -static __attribute__((destructor)) -void trace_finalize(void) -{ - if (--global_data_refcount == 0) { - g_hash_table_destroy(reserved_keywords_set); - } -}