#include <babeltrace/ctf-writer/functor-internal.h>
#include <babeltrace/ctf-ir/event-types-internal.h>
#include <babeltrace/ctf-ir/attributes-internal.h>
+#include <babeltrace/ctf-ir/visitor-internal.h>
#include <babeltrace/ctf-ir/utils.h>
#include <babeltrace/compiler.h>
#include <babeltrace/objects.h>
{
int ret = 0;
- if (!trace || trace->frozen || !name || !value ||
+ if (!trace || !name || !value ||
bt_ctf_validate_identifier(name) ||
!(bt_object_is_integer(value) || bt_object_is_string(value))) {
ret = -1;
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_object *attribute =
+ bt_ctf_attributes_get_field_value_by_name(
+ trace->environment, name);
+
+ if (attribute) {
+ BT_OBJECT_PUT(attribute);
+ ret = -1;
+ goto end;
+ }
+
+ bt_object_freeze(value);
+ }
+
ret = bt_ctf_attributes_set_field_value(trace->environment, name,
value);
goto end;
}
+ if (trace->frozen) {
+ /*
+ * New environment fields may be added to a frozen trace,
+ * but existing fields may not be changed.
+ */
+ struct bt_object *attribute =
+ bt_ctf_attributes_get_field_value_by_name(
+ trace->environment, name);
+
+ if (attribute) {
+ BT_OBJECT_PUT(attribute);
+ ret = -1;
+ goto end;
+ }
+ }
+
env_value_string_obj = bt_object_string_create_init(value);
if (!env_value_string_obj) {
goto end;
}
+ if (trace->frozen) {
+ bt_object_freeze(env_value_string_obj);
+ }
ret = bt_ctf_trace_set_environment_field(trace, name,
env_value_string_obj);
goto end;
}
+ if (trace->frozen) {
+ /*
+ * New environment fields may be added to a frozen trace,
+ * but existing fields may not be changed.
+ */
+ struct bt_object *attribute =
+ bt_ctf_attributes_get_field_value_by_name(
+ trace->environment, name);
+
+ if (attribute) {
+ BT_OBJECT_PUT(attribute);
+ ret = -1;
+ goto end;
+ }
+ }
+
env_value_integer_obj = bt_object_integer_create_init(value);
if (!env_value_integer_obj) {
ret = -1;
ret = bt_ctf_trace_set_environment_field(trace, name,
env_value_integer_obj);
-
+ if (trace->frozen) {
+ bt_object_freeze(env_value_integer_obj);
+ }
end:
BT_OBJECT_PUT(env_value_integer_obj);
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++;
}
}
- if (_bt_ctf_stream_class_set_id(stream_class,
+ if (bt_ctf_stream_class_set_id_no_check(stream_class,
stream_id)) {
/* TODO Should retry with a different stream id */
ret = -1;
}
bt_ctf_stream_class_freeze(stream_class);
- bt_ctf_trace_freeze(trace);
+ if (!trace->frozen) {
+ bt_ctf_trace_freeze(trace);
+ }
end:
if (ret) {
(void) bt_ctf_stream_class_set_trace(stream_class, NULL);
static
void bt_ctf_trace_freeze(struct bt_ctf_trace *trace)
{
+ bt_ctf_trace_resolve_types(trace);
bt_ctf_attributes_freeze(trace->environment);
trace->frozen = 1;
}