Skip to content

Commit

Permalink
Minor touches.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorolev committed Jul 28, 2024
1 parent e084d05 commit c8cdf8a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/lib_c5t_dlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ void C5T_DLIB_USE_PROVIDED_INSTANCE_AND_SET_BASE_DIR(C5T_DLibs_Manager_Interface
void C5T_DLIB_LIST(std::function<void(std::string)>);

// Use the `DLIB`, load it if needed, re-load it if needed.
bool C5T_DLIB_USE(
std::string const& lib_name, std::function<void(C5T_DLib&)>, std::function<void()> = [] {});
bool C5T_DLIB_USE(std::string const& lib_name, std::function<void(C5T_DLib&)>, std::function<void()> = [] {});

// NOTE(dkorolev): Ugly, extra copy, but should do the job for now.
template <class F,
Expand All @@ -226,8 +225,7 @@ std::invoke_result_t<F, C5T_DLib&> C5T_DLIB_CALL(
return std::invoke_result_t<F, C5T_DLib&>();
}) {
std::invoke_result_t<F, C5T_DLib&> r;
C5T_DLIB_USE(
lib_name, [&](C5T_DLib& lib) { r = f(lib); }, [&]() { r = g(); });
C5T_DLIB_USE(lib_name, [&](C5T_DLib& lib) { r = f(lib); }, [&]() { r = g(); });
return r;
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib_c5t_storage.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

// NOTE: NEED THREAD SAFETY AND ATOMIC OPERATIONS!!!

// #define C5T_DEBUG_STORAGE

#include <functional>
Expand Down
7 changes: 2 additions & 5 deletions src/test_c5t_popen2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ TEST(Popen2Test, WithDelay) {

TEST(Popen2Test, InnerBashBecauseParentheses) {
std::string result;
C5T_POPEN2({"bash", "-c", "(sleep 0.01; echo PASS3)"},
[&result](std::string const& line) { result = line; });
C5T_POPEN2({"bash", "-c", "(sleep 0.01; echo PASS3)"}, [&result](std::string const& line) { result = line; });
EXPECT_EQ(result, "PASS3");
}

Expand Down Expand Up @@ -58,9 +57,7 @@ TEST(Popen2Test, ReadsStdin) {
TEST(Popen2Test, ReadsStdinForever) {
std::string result = "result:";
C5T_POPEN2(
{"bash",
"-c",
"while true; do read A; read B; C=$((A+B)); if [ $C == '0' ]; then exit; fi; echo $C; done"},
{"bash", "-c", "while true; do read A; read B; C=$((A+B)); if [ $C == '0' ]; then exit; fi; echo $C; done"},
[&result](std::string const& line) { result += ' ' + line; },
[](Popen2Runtime& run) { run("1\n2\n3\n4\n0\n0\n"); });
ASSERT_EQ(result, "result: 3 7");
Expand Down

0 comments on commit c8cdf8a

Please sign in to comment.