From: Philippe Proulx Date: Mon, 19 Jun 2017 22:25:30 +0000 (-0400) Subject: Fix: allow NULL (unnamed) in bt_ctf_stream_class_{get,set}_name() X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=03be3bcd6f3e4269f89672a418b5166ea343768f Fix: allow NULL (unnamed) in bt_ctf_stream_class_{get,set}_name() Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/ctf-ir/stream-class.h b/include/babeltrace/ctf-ir/stream-class.h index e66ab7da..64400f52 100644 --- a/include/babeltrace/ctf-ir/stream-class.h +++ b/include/babeltrace/ctf-ir/stream-class.h @@ -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} diff --git a/include/babeltrace/ctf-ir/stream-internal.h b/include/babeltrace/ctf-ir/stream-internal.h index 87395b10..41fe247d 100644 --- a/include/babeltrace/ctf-ir/stream-internal.h +++ b/include/babeltrace/ctf-ir/stream-internal.h @@ -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 */ diff --git a/lib/ctf-ir/stream-class.c b/lib/ctf-ir/stream-class.c index 1ac20cc5..6fdb8ed2 100644 --- a/lib/ctf-ir/stream-class.c +++ b/lib/ctf-ir/stream-class.c @@ -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), diff --git a/plugins/libctfcopytrace/ctfcopytrace.c b/plugins/libctfcopytrace/ctfcopytrace.c index b12faefa..4f0811e3 100644 --- a/plugins/libctfcopytrace/ctfcopytrace.c +++ b/plugins/libctfcopytrace/ctfcopytrace.c @@ -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", diff --git a/plugins/lttng-utils/copy.c b/plugins/lttng-utils/copy.c index 07590c7b..eca81685 100644 --- a/plugins/lttng-utils/copy.c +++ b/plugins/lttng-utils/copy.c @@ -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",