Fix: allow NULL (unnamed) in bt_ctf_stream_class_{get,set}_name()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 19 Jun 2017 22:25:30 +0000 (18:25 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 6 Jul 2017 20:02:50 +0000 (16:02 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/ctf-ir/stream-class.h
include/babeltrace/ctf-ir/stream-internal.h
lib/ctf-ir/stream-class.c
plugins/libctfcopytrace/ctfcopytrace.c
plugins/lttng-utils/copy.c

index e66ab7da8d235471ab1dfc05fc9d4e992a041814..64400f5201e794bf17c300ae6f66f60a4f664c3d 100644 (file)
@@ -252,17 +252,20 @@ extern const char *bt_ctf_stream_class_get_name(
 
 /**
 @brief Sets the name of the CTF IR stream class
-       \p stream_class to \p name.
+       \p stream_class to \p name, or resets the name of
+       \p stream_class.
 
-\p name must be unique amongst the names of all the stream classes
-of the trace class to which you eventually add \p stream_class.
+If \p name is not \c NULL, it must be unique amongst the names of all
+the stream classes of the trace class to which you eventually add
+\p stream_class.
 
 @param[in] stream_class        Stream class of which to set the name.
-@param[in] name                Name of the stream class (copied on success).
+@param[in] name                Name of the stream class (copied on success), or
+                       \c NULL to reset the name of \p stream_class
+                       (make it unnamed).
 @returns               0 on success, or a negative value on error.
 
 @prenotnull{stream_class}
-@prenotnull{name}
 @prehot{stream_class}
 @postrefcountsame{stream_class}
 
index 87395b107f37f609a9231401856e3261ced9ab0b..41fe247d21afbe152a9b7dc80447781b47b64e0a 100644 (file)
@@ -107,4 +107,12 @@ BT_HIDDEN
 void bt_ctf_stream_remove_destroy_listener(struct bt_ctf_stream *stream,
                bt_ctf_stream_destroy_listener_func func, void *data);
 
+static inline
+struct bt_ctf_stream_class *bt_ctf_stream_borrow_stream_class(
+               struct bt_ctf_stream *stream)
+{
+       assert(stream);
+       return stream->stream_class;
+}
+
 #endif /* BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H */
index 1ac20cc55ee339157093f4e9f70fab50b4c78d1d..6fdb8ed2f5747b4cf5bc0b70d50bebf4b7412447 100644 (file)
@@ -146,7 +146,7 @@ const char *bt_ctf_stream_class_get_name(
                goto end;
        }
 
-       name = stream_class->name->str;
+       name = stream_class->name->len > 0 ? stream_class->name->str : NULL;
 end:
        return name;
 }
@@ -171,7 +171,18 @@ int bt_ctf_stream_class_set_name(struct bt_ctf_stream_class *stream_class,
                goto end;
        }
 
-       g_string_assign(stream_class->name, name);
+       if (!name) {
+               g_string_assign(stream_class->name, "");
+       } else {
+               if (strlen(name) == 0) {
+                       BT_LOGW("Invalid parameter: name is empty.");
+                       ret = -1;
+                       goto end;
+               }
+
+               g_string_assign(stream_class->name, name);
+       }
+
        BT_LOGV("Set stream class's name: "
                "addr=%p, name=\"%s\", id=%" PRId64,
                stream_class, bt_ctf_stream_class_get_name(stream_class),
index b12faefae94c7437f17236206afe3e833bab46b7..4f0811e35e8b72b45b6aa3487a9ba2aaca10f4a2 100644 (file)
@@ -386,10 +386,6 @@ struct bt_ctf_stream_class *ctf_copy_stream_class(FILE *err,
        int ret_int;
        const char *name = bt_ctf_stream_class_get_name(stream_class);
 
-       if (strlen(name) == 0) {
-               name = NULL;
-       }
-
        writer_stream_class = bt_ctf_stream_class_create_empty(name);
        if (!writer_stream_class) {
                fprintf(err, "[error] %s in %s:%d\n",
index 07590c7b330127eae12a67318beb2f6f92b9fb8a..eca816851018849c0c1fe8d7d7161aba0e67734f 100644 (file)
@@ -1045,10 +1045,6 @@ struct bt_ctf_stream_class *copy_stream_class_debug_info(FILE *err,
        int ret_int;
        const char *name = bt_ctf_stream_class_get_name(stream_class);
 
-       if (strlen(name) == 0) {
-               name = NULL;
-       }
-
        writer_stream_class = bt_ctf_stream_class_create_empty(name);
        if (!writer_stream_class) {
                fprintf(err, "[error] %s in %s:%d\n",
This page took 0.02769 seconds and 4 git commands to generate.