aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-01-08 12:46:58 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-01-08 12:46:58 +0200
commit46b32368147e7975bf98826c30eed48e22ba07b4 (patch)
tree0766e6ddc5db8b58556d827ceacea54974714a43
parentb62ccc5d017e54beecd72d64d2074473c49192a7 (diff)
Implement manual copying of process_path
Also fix bug in move ctor/assignment.
-rw-r--r--libbutl/process.ixx28
-rw-r--r--libbutl/process.mxx5
2 files changed, 28 insertions, 5 deletions
diff --git a/libbutl/process.ixx b/libbutl/process.ixx
index a0e2de6..cc5170f 100644
--- a/libbutl/process.ixx
+++ b/libbutl/process.ixx
@@ -22,34 +22,52 @@ namespace butl
inline process_path::
process_path (process_path&& p)
- : initial (p.initial),
- recall (std::move (p.recall)),
+ : recall (std::move (p.recall)),
effect (std::move (p.effect)),
args0_ (p.args0_)
{
+ initial = p.initial != p.recall.string ().c_str ()
+ ? p.initial
+ : recall.string ().c_str ();
+
p.args0_ = nullptr;
}
inline process_path& process_path::
operator= (process_path&& p)
{
-
if (this != &p)
{
if (args0_ != nullptr)
- *args0_ = initial;
+ *args0_ = initial; // Restore.
- initial = p.initial;
recall = std::move (p.recall);
effect = std::move (p.effect);
args0_ = p.args0_;
+ initial = p.initial != p.recall.string ().c_str ()
+ ? p.initial
+ : recall.string ().c_str ();
+
p.args0_ = nullptr;
}
return *this;
}
+ inline process_path::
+ process_path (const process_path& p, bool init)
+ : recall (p.recall), effect (p.effect)
+ {
+ assert (p.args0_ == nullptr);
+
+ if (!p.empty ())
+ {
+ assert (init == (p.initial != p.recall.string ().c_str ()));
+ initial = init ? p.initial : recall.string ().c_str ();
+ }
+ }
+
inline const char* process_path::
recall_string () const
{
diff --git a/libbutl/process.mxx b/libbutl/process.mxx
index 199273b..4faa808 100644
--- a/libbutl/process.mxx
+++ b/libbutl/process.mxx
@@ -135,6 +135,11 @@ LIBBUTL_MODEXPORT namespace butl
process_path (const char* i, path&& r, path&& e);
~process_path ();
+ // Manual copying. Should not use args[0] RAII. See path_search() for the
+ // init semantics.
+ //
+ process_path (const process_path&, bool init);
+
private:
friend class process;
const char** args0_ = nullptr;