From f5f8d5f05c7e73627be492a1f702fcb04af3160f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 5 Jul 2019 17:52:06 +0300 Subject: Fix move-constructing/assigning for process_env and process_path classes --- libbutl/command.mxx | 1 - libbutl/process.ixx | 48 +++++++++++++++++++++++++++++++++++++----------- libbutl/process.mxx | 8 ++++++++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/libbutl/command.mxx b/libbutl/command.mxx index 354788d..e2a9737 100644 --- a/libbutl/command.mxx +++ b/libbutl/command.mxx @@ -80,5 +80,4 @@ LIBBUTL_MODEXPORT namespace butl const optional& = nullopt, char subst = '@', const std::function& = {}); - } diff --git a/libbutl/process.ixx b/libbutl/process.ixx index 0aa23fa..accc57b 100644 --- a/libbutl/process.ixx +++ b/libbutl/process.ixx @@ -22,13 +22,13 @@ namespace butl inline process_path:: process_path (process_path&& p) - : recall (std::move (p.recall)), - effect (std::move (p.effect)), + : effect (std::move (p.effect)), args0_ (p.args0_) { - initial = p.initial != p.recall.string ().c_str () - ? p.initial - : recall.string ().c_str (); + bool init (p.initial != p.recall.string ().c_str ()); + + recall = std::move (p.recall); + initial = init ? p.initial : recall.string ().c_str (); p.args0_ = nullptr; } @@ -41,14 +41,13 @@ namespace butl if (args0_ != nullptr) *args0_ = initial; // Restore. - recall = std::move (p.recall); - effect = std::move (p.effect); - args0_ = p.args0_; + bool init (p.initial != p.recall.string ().c_str ()); - initial = p.initial != p.recall.string ().c_str () - ? p.initial - : recall.string ().c_str (); + recall = std::move (p.recall); + effect = std::move (p.effect); + initial = init ? p.initial : recall.string ().c_str (); + args0_ = p.args0_; p.args0_ = nullptr; } @@ -237,4 +236,31 @@ namespace butl using namespace std::chrono; return timed_wait (duration_cast (d)); } + + // process_env + // + inline process_env:: + process_env (process_env&& e) + { + *this = std::move (e); + } + + inline process_env& process_env:: + operator= (process_env&& e) + { + if (this != &e) + { + cwd = e.cwd; + + bool sp (e.path == &e.path_); + path_ = std::move (e.path_); + path = sp ? &path_ : e.path; + + bool sv (e.vars == e.vars_.data ()); + vars_ = std::move (e.vars_); + vars = sv ? vars_.data () : e.vars; + } + + return *this; + } } diff --git a/libbutl/process.mxx b/libbutl/process.mxx index 655650e..13438be 100644 --- a/libbutl/process.mxx +++ b/libbutl/process.mxx @@ -588,6 +588,14 @@ LIBBUTL_MODEXPORT namespace butl process_env (const butl::path& p, const V& v) : process_env (p.string (), v) {} + // Moveable-only type. + // + process_env (process_env&&); + process_env& operator= (process_env&&); + + process_env (const process_env&) = delete; + process_env& operator= (const process_env&) = delete; + private: template void -- cgit v1.1