From a0d129162d2fdd1a99553a6cfbdf4e77ad3f7334 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 9 Apr 2015 14:57:44 -0400 Subject: [PATCH] Fix: Allow the addition of environment fields to a frozen trace MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- formats/ctf/ir/trace.c | 61 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 4d27b833..94a332d1 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -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); -- 2.34.1