From: Simon Marchi Date: Mon, 29 Jan 2024 17:05:23 +0000 (+0000) Subject: src.ctf.fs: make set_trace_name use bt2::Trace X-Git-Url: https://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=68c9714499bece2e9762471e84119f2d9e93791c src.ctf.fs: make set_trace_name use bt2::Trace Add an out-of-class `operator+=` to append a `bt2c::CStringView` to an `std::string`. Without it, I get: CXX plugins/ctf/fs-src/fs.lo /home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.cpp: In function 'void set_trace_name(bt2::Trace, const char*)': /home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.cpp:598:14: error: ambiguous overload for 'operator+=' (operand types are 'std::string' {aka 'std::__cxx11::basic_string'} and 'bt2::CommonStringValue::Value' {aka 'bt2c::CStringView'}) 598 | name += val->asString().value(); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13.2.1/string:54, from /usr/include/c++/13.2.1/bits/locale_classes.h:40, from /usr/include/c++/13.2.1/bits/ios_base.h:41, from /usr/include/c++/13.2.1/ios:44, from /usr/include/c++/13.2.1/istream:40, from /usr/include/c++/13.2.1/sstream:40, from /home/simark/src/babeltrace/src/plugins/ctf/fs-src/fs.cpp:10: /usr/include/c++/13.2.1/bits/basic_string.h:1354:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]' 1354 | operator+=(const basic_string& __str) | ^~~~~~~~ /usr/include/c++/13.2.1/bits/basic_string.h:1364:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator+=(const _CharT*) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]' 1364 | operator+=(const _CharT* __s) | ^~~~~~~~ Change-Id: I3f47878658a431f81a129fc9e644efe50608e7ce Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8418 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12354 Tested-by: jenkins --- diff --git a/src/cpp-common/bt2c/c-string-view.hpp b/src/cpp-common/bt2c/c-string-view.hpp index 0437cd65..771954c1 100644 --- a/src/cpp-common/bt2c/c-string-view.hpp +++ b/src/cpp-common/bt2c/c-string-view.hpp @@ -258,4 +258,12 @@ bool operator!=(LhsT&& lhs, RhsT&& rhs) noexcept } /* namespace bt2c */ +/* + * Appends `rhs` to `lhs`. + */ +inline void operator+=(std::string& lhs, bt2c::CStringView rhs) +{ + lhs += rhs.data(); +} + #endif /* BABELTRACE_CPP_COMMON_BT2C_C_STRING_VIEW_HPP */ diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index df6a0e28..9cf0c6cb 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -581,7 +581,7 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace) return 0; } -static int set_trace_name(bt_trace *trace, const char *name_suffix) +static void set_trace_name(const bt2::Trace trace, const char *name_suffix) { std::string name; @@ -589,9 +589,9 @@ static int set_trace_name(bt_trace *trace, const char *name_suffix) * Check if we have a trace environment string value named `hostname`. * If so, use it as the trace name's prefix. */ - const bt_value *val = bt_trace_borrow_environment_entry_value_by_name_const(trace, "hostname"); - if (val && bt_value_is_string(val)) { - name += bt_value_string_get(val); + const auto val = trace.environmentEntry("hostname"); + if (val && val->isString()) { + name += val->asString().value(); if (name_suffix) { name += G_DIR_SEPARATOR; @@ -602,7 +602,7 @@ static int set_trace_name(bt_trace *trace, const char *name_suffix) name += name_suffix; } - return bt_trace_set_name(trace, name.c_str()); + trace.name(name); } static ctf_fs_trace::UP ctf_fs_trace_create(const char *path, const char *name, @@ -631,10 +631,7 @@ static ctf_fs_trace::UP ctf_fs_trace_create(const char *path, const char *name, if (ctf_fs_trace->trace) { ctf_trace_class_configure_ir_trace(ctf_fs_trace->metadata->tc, *ctf_fs_trace->trace); - ret = set_trace_name(ctf_fs_trace->trace->libObjPtr(), name); - if (ret) { - return nullptr; - } + set_trace_name(*ctf_fs_trace->trace, name); } ret = create_ds_file_groups(ctf_fs_trace.get());