Fix: Allow the addition of environment fields to a frozen trace
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 9 Apr 2015 18:57:44 +0000 (14:57 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 9 Apr 2015 19:01:28 +0000 (15:01 -0400)
Commit 7f800dc7 introduced a behavior change which made it
impossible to add environment fields to a frozen trace (after the
creation of a stream).

This fix makes it possible to add new fields to a trace's
environment while making it impossible to modify existing fields
hereby restoring CTF Writer's v1.2 behavior.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/trace.c

index 4d27b833be4c0c0ca93330eb6e500ec5fc961194..94a332d162e4052ff9530baf63e0952d45a9b3af 100644 (file)
@@ -187,7 +187,7 @@ int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace,
 {
        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;
@@ -199,6 +199,26 @@ int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace,
                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);
 
@@ -217,6 +237,22 @@ int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace,
                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) {
@@ -224,6 +260,9 @@ int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace,
                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);
 
@@ -244,6 +283,22 @@ int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace *trace,
                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;
@@ -252,7 +307,9 @@ int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace *trace,
 
        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);
 
This page took 0.026201 seconds and 4 git commands to generate.