From: Simon Marchi Date: Tue, 9 Apr 2024 21:03:42 +0000 (-0400) Subject: src.ctf.fs: make ctf_fs_component::trace a unique_ptr X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=7df773f2c13b7e624f503c51605ddcae31625a30 src.ctf.fs: make ctf_fs_component::trace a unique_ptr Define ctf_fs_trace::UP to be a unique_ptr type with a deleter that calls ctf_fs_trace_destroy (the custom deleter will go away once ctf_fs_trace is properly destructible). Change ctf_fs_component::trace to be of this type. Change-Id: Iaf8111922b320781d7e9333bcdc5db129192509d Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8240 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12279 --- diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index a776f27c..21e61e37 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -298,14 +298,17 @@ static void ctf_fs_trace_destroy(struct ctf_fs_trace *ctf_fs_trace) delete ctf_fs_trace; } +void ctf_fs_trace_deleter::operator()(ctf_fs_trace * const trace) noexcept +{ + ctf_fs_trace_destroy(trace); +} + void ctf_fs_destroy(struct ctf_fs_component *ctf_fs) { if (!ctf_fs) { return; } - ctf_fs_trace_destroy(ctf_fs->trace); - if (ctf_fs->port_data) { g_ptr_array_free(ctf_fs->port_data, TRUE); } @@ -1995,14 +1998,14 @@ int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, goto error; } - ctf_fs->trace = trace; + ctf_fs->trace.reset(trace); } else { /* Just one trace, it may or may not have a UUID, both are fine. */ - ctf_fs->trace = (ctf_fs_trace *) traces->pdata[0]; + ctf_fs->trace.reset((ctf_fs_trace *) traces->pdata[0]); traces->pdata[0] = NULL; } - ret = fix_packet_index_tracer_bugs(ctf_fs->trace); + ret = fix_packet_index_tracer_bugs(ctf_fs->trace.get()); if (ret) { BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs->logger, "Failed to fix packet index tracer bugs."); } @@ -2210,11 +2213,11 @@ static ctf_fs_component::UP ctf_fs_create(const bt_value *params, return nullptr; } - if (create_streams_for_trace(ctf_fs->trace)) { + if (create_streams_for_trace(ctf_fs->trace.get())) { return nullptr; } - if (create_ports_for_trace(ctf_fs.get(), ctf_fs->trace, self_comp_src)) { + if (create_ports_for_trace(ctf_fs.get(), ctf_fs->trace.get(), self_comp_src)) { return nullptr; } diff --git a/src/plugins/ctf/fs-src/fs.hpp b/src/plugins/ctf/fs-src/fs.hpp index a0153a9b..b0052bb7 100644 --- a/src/plugins/ctf/fs-src/fs.hpp +++ b/src/plugins/ctf/fs-src/fs.hpp @@ -58,8 +58,15 @@ struct ctf_fs_metadata int bo = 0; }; +struct ctf_fs_trace_deleter +{ + void operator()(ctf_fs_trace *) noexcept; +}; + struct ctf_fs_trace { + using UP = std::unique_ptr; + explicit ctf_fs_trace(const bt2c::Logger& parentLogger) : logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"} { @@ -111,8 +118,7 @@ struct ctf_fs_component /* Array of struct ctf_fs_port_data *, owned by this */ GPtrArray *port_data = nullptr; - /* Owned by this */ - struct ctf_fs_trace *trace = nullptr; + ctf_fs_trace::UP trace; ctf::src::ClkClsCfg clkClsCfg; }; diff --git a/src/plugins/ctf/fs-src/query.cpp b/src/plugins/ctf/fs-src/query.cpp index b9efc65b..3e25f168 100644 --- a/src/plugins/ctf/fs-src/query.cpp +++ b/src/plugins/ctf/fs-src/query.cpp @@ -199,7 +199,7 @@ bt2::Value::Shared trace_infos_query(const bt2::ConstMapValue params, const bt2c const auto result = bt2::ArrayValue::create(); const auto traceInfo = result->appendEmptyMap(); - populate_trace_info(ctf_fs->trace, traceInfo, logger); + populate_trace_info(ctf_fs->trace.get(), traceInfo, logger); return result; }