Skip to content

Commit 81174d8

Browse files
committed
Merge bitcoin/bitcoin#29961: refactor: remove remaining unused code from cpp-subprocess
8b52e7f update comments in cpp-subprocess (check_output references) (Sebastian Falbesoner) 97f1597 remove unused method `Popen::kill` from cpp-subprocess (Sebastian Falbesoner) 908c51f remove commented out code in cpp-subprocess (Sebastian Falbesoner) ff79adb remove unused templates from cpp-subprocess (Sebastian Falbesoner) Pull request description: This PR removes remaining code that is unused within the cpp-subprocess module (templates and commented out code). Happy to add more removals if anyone finds more unused parts. Note that there are some API functions of the `Popen` class that we don't use, e.g. `wait()`, `pid()`, `poll()`, `kill()`, but they sound IMHO common enough to be useful in the future, so not sure how deep we should go there. ACKs for top commit: fjahr: Code review ACK 8b52e7f achow101: ACK 8b52e7f hebasto: ACK 8b52e7f. Tree-SHA512: 14c1cd2216185d941923f06fdc7acbeed66cd87e2691d9a352f7309b3e07fe4877b580f598a2e4106f9c48395ed6de00a0bfb5d3c3af9c4624d1956a0f543e99
2 parents 3d28725 + 8b52e7f commit 81174d8

File tree

1 file changed

+18
-96
lines changed

1 file changed

+18
-96
lines changed

src/util/subprocess.h

Lines changed: 18 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,6 @@ class OSError: public std::runtime_error
159159
//--------------------------------------------------------------------
160160
namespace util
161161
{
162-
template <typename R>
163-
inline bool is_ready(std::shared_future<R> const &f)
164-
{
165-
return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
166-
}
167-
168162
inline void quote_argument(const std::wstring &argument, std::wstring &command_line,
169163
bool force)
170164
{
@@ -676,8 +670,8 @@ struct error
676670
* This is basically used to determine the length of the actual
677671
* data stored inside the dynamically resized vector.
678672
*
679-
* This is what is returned as the output to communicate and check_output
680-
* functions, so, users must know about this class.
673+
* This is what is returned as the output to the communicate
674+
* function, so, users must know about this class.
681675
*
682676
* OutBuffer and ErrBuffer are just different typedefs to this class.
683677
*/
@@ -688,22 +682,6 @@ class Buffer
688682
explicit Buffer(size_t cap) { buf.resize(cap); }
689683
void add_cap(size_t cap) { buf.resize(cap); }
690684

691-
#if 0
692-
Buffer(const Buffer& other):
693-
buf(other.buf),
694-
length(other.length)
695-
{
696-
std::cout << "COPY" << std::endl;
697-
}
698-
699-
Buffer(Buffer&& other):
700-
buf(std::move(other.buf)),
701-
length(other.length)
702-
{
703-
std::cout << "MOVE" << std::endl;
704-
}
705-
#endif
706-
707685
public:
708686
std::vector<char> buf;
709687
size_t length = 0;
@@ -724,39 +702,9 @@ class Popen;
724702
*/
725703

726704
namespace detail {
727-
728-
// Metaprogram for searching a type within
729-
// a variadic parameter pack
730-
// This is particularly required to do a compile time
731-
// checking of the arguments provided to 'check_output' function
732-
// wherein the user is not expected to provide an 'output' option.
733-
734-
template <typename... T> struct param_pack{};
735-
736-
template <typename F, typename T> struct has_type;
737-
738-
template <typename F>
739-
struct has_type<F, param_pack<>> {
740-
static constexpr bool value = false;
741-
};
742-
743-
template <typename F, typename... T>
744-
struct has_type<F, param_pack<F, T...>> {
745-
static constexpr bool value = true;
746-
};
747-
748-
template <typename F, typename H, typename... T>
749-
struct has_type<F, param_pack<H,T...>> {
750-
static constexpr bool value =
751-
std::is_same<F, typename std::decay<H>::type>::value ? true : has_type<F, param_pack<T...>>::value;
752-
};
753-
754-
//----
755-
756705
/*!
757706
* A helper class to Popen class for setting
758-
* options as provided in the Popen constructor
759-
* or in check_output arguments.
707+
* options as provided in the Popen constructor.
760708
* This design allows us to _not_ have any fixed position
761709
* to any arguments and specify them in a way similar to what
762710
* can be done in python.
@@ -948,24 +896,23 @@ class Streams
948896
* interface to the client.
949897
*
950898
* API's provided by the class:
951-
* 1. Popen({"cmd"}, output{..}, error{..}, ....)
899+
* Popen({"cmd"}, output{..}, error{..}, ....)
952900
* Command provided as a sequence.
953-
* 2. Popen("cmd arg1"m output{..}, error{..}, ....)
901+
* Popen("cmd arg1", output{..}, error{..}, ....)
954902
* Command provided in a single string.
955-
* 3. wait() - Wait for the child to exit.
956-
* 4. retcode() - The return code of the exited child.
957-
* 5. pid() - PID of the spawned child.
958-
* 6. poll() - Check the status of the running child.
959-
* 7. kill(sig_num) - Kill the child. SIGTERM used by default.
960-
* 8. send(...) - Send input to the input channel of the child.
961-
* 9. communicate(...) - Get the output/error from the child and close the channels
962-
* from the parent side.
963-
*10. input() - Get the input channel/File pointer. Can be used for
964-
* customizing the way of sending input to child.
965-
*11. output() - Get the output channel/File pointer. Usually used
966-
in case of redirection. See piping examples.
967-
*12. error() - Get the error channel/File pointer. Usually used
968-
in case of redirection.
903+
* wait() - Wait for the child to exit.
904+
* retcode() - The return code of the exited child.
905+
* pid() - PID of the spawned child.
906+
* poll() - Check the status of the running child.
907+
* send(...) - Send input to the input channel of the child.
908+
* communicate(...) - Get the output/error from the child and close the channels
909+
* from the parent side.
910+
* input() - Get the input channel/File pointer. Can be used for
911+
* customizing the way of sending input to child.
912+
* output() - Get the output channel/File pointer. Usually used
913+
in case of redirection. See piping examples.
914+
* error() - Get the error channel/File pointer. Usually used
915+
in case of redirection.
969916
*/
970917
class Popen
971918
{
@@ -1009,15 +956,6 @@ class Popen
1009956
execute_process();
1010957
}
1011958

1012-
/*
1013-
~Popen()
1014-
{
1015-
#ifdef __USING_WINDOWS__
1016-
CloseHandle(this->process_handle_);
1017-
#endif
1018-
}
1019-
*/
1020-
1021959
int pid() const noexcept { return child_pid_; }
1022960

1023961
int retcode() const noexcept { return retcode_; }
@@ -1026,10 +964,6 @@ class Popen
1026964

1027965
int poll() noexcept(false);
1028966

1029-
// Does not fail, Caller is expected to recheck the
1030-
// status with a call to poll()
1031-
void kill(int sig_num = 9);
1032-
1033967
void set_out_buf_cap(size_t cap) { stream_.set_out_buf_cap(cap); }
1034968

1035969
void set_err_buf_cap(size_t cap) { stream_.set_err_buf_cap(cap); }
@@ -1197,18 +1131,6 @@ inline int Popen::poll() noexcept(false)
11971131
#endif
11981132
}
11991133

1200-
inline void Popen::kill(int sig_num)
1201-
{
1202-
#ifdef __USING_WINDOWS__
1203-
if (!TerminateProcess(this->process_handle_, (UINT)sig_num)) {
1204-
throw OSError("TerminateProcess", 0);
1205-
}
1206-
#else
1207-
::kill(child_pid_, sig_num);
1208-
#endif
1209-
}
1210-
1211-
12121134
inline void Popen::execute_process() noexcept(false)
12131135
{
12141136
#ifdef __USING_WINDOWS__

0 commit comments

Comments
 (0)