From 5d16d8fd87306f6442b6ac0944ca9251c762e018 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 8 May 2017 20:36:59 +0200 Subject: [PATCH] move_data/swap_data is platform independent --- src/process.cc | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/process.cc b/src/process.cc index c6d4612..d61c725 100644 --- a/src/process.cc +++ b/src/process.cc @@ -286,27 +286,6 @@ OSTD_EXPORT void subprocess::reset() { p_current = nullptr; } -OSTD_EXPORT void subprocess::move_data(subprocess &i) { - data *od = static_cast(i.p_current); - if (!od) { - return; - } - p_current = ::new (reinterpret_cast(&p_data)) data{*od}; - i.p_current = nullptr; -} - -OSTD_EXPORT void subprocess::swap_data(subprocess &i) { - if (!p_current) { - move_data(i); - } else if (!i.p_current) { - i.move_data(*this); - } else { - std::swap( - *static_cast(p_current), *static_cast(i.p_current) - ); - } -} - OSTD_EXPORT int subprocess::close() { if (!p_current) { throw process_error{ECHILD, std::generic_category()}; @@ -333,6 +312,10 @@ OSTD_EXPORT int subprocess::close() { #else /* OSTD_PLATFORM_WIN32 */ +struct data { + HANDLE process = nullptr, thread = nullptr; +}; + OSTD_EXPORT void subprocess::open_impl( std::string const &, std::vector const &, bool ) { @@ -348,6 +331,27 @@ OSTD_EXPORT void subprocess::reset() { #endif +OSTD_EXPORT void subprocess::move_data(subprocess &i) { + data *od = static_cast(i.p_current); + if (!od) { + return; + } + p_current = ::new (reinterpret_cast(&p_data)) data{*od}; + i.p_current = nullptr; +} + +OSTD_EXPORT void subprocess::swap_data(subprocess &i) { + if (!p_current) { + move_data(i); + } else if (!i.p_current) { + i.move_data(*this); + } else { + std::swap( + *static_cast(p_current), *static_cast(i.p_current) + ); + } +} + OSTD_EXPORT subprocess::~subprocess() { try { close();