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>
- 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;
bt_ctf_validate_identifier(name) ||
!(bt_object_is_integer(value) || bt_object_is_string(value))) {
ret = -1;
+ 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);
ret = bt_ctf_attributes_set_field_value(trace->environment, name,
value);
+ 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) {
env_value_string_obj = bt_object_string_create_init(value);
if (!env_value_string_obj) {
+ if (trace->frozen) {
+ bt_object_freeze(env_value_string_obj);
+ }
ret = bt_ctf_trace_set_environment_field(trace, name,
env_value_string_obj);
ret = bt_ctf_trace_set_environment_field(trace, name,
env_value_string_obj);
+ 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;
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);
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);
end:
BT_OBJECT_PUT(env_value_integer_obj);