diff --git a/CMakeLists.txt b/CMakeLists.txt index ca2591c..eb9c11c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ target_include_directories( PUBLIC "./include" PRIVATE "./src") set_target_properties(hyprutils PROPERTIES VERSION ${hyprutils_VERSION} - SOVERSION 4) + SOVERSION 5) target_link_libraries(hyprutils PkgConfig::deps) # tests diff --git a/VERSION b/VERSION index 4b9fcbe..a918a2a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.1 +0.6.0 diff --git a/include/hyprutils/memory/SharedPtr.hpp b/include/hyprutils/memory/SharedPtr.hpp index d2c5995..f2003a2 100644 --- a/include/hyprutils/memory/SharedPtr.hpp +++ b/include/hyprutils/memory/SharedPtr.hpp @@ -144,7 +144,7 @@ namespace Hyprutils { Impl_::impl_base* impl_ = nullptr; private: - /* + /* no-op if there is no impl_ may delete the stored object if ref == 0 may delete and reset impl_ if ref == 0 and weak == 0 @@ -167,7 +167,7 @@ namespace Hyprutils { impl_->inc(); } - /* destroy the pointed-to object + /* destroy the pointed-to object if able, will also destroy impl */ void destroyImpl() { // destroy the impl contents @@ -185,6 +185,11 @@ namespace Hyprutils { static CSharedPointer makeShared(Args&&... args) { return CSharedPointer(new U(std::forward(args)...)); } + + template + CSharedPointer reinterpretPointerCast(const CSharedPointer& ref) { + return CSharedPointer(ref.impl_); + } } } diff --git a/include/hyprutils/os/Process.hpp b/include/hyprutils/os/Process.hpp index 47842ce..7c0b64b 100644 --- a/include/hyprutils/os/Process.hpp +++ b/include/hyprutils/os/Process.hpp @@ -14,6 +14,11 @@ namespace Hyprutils { void addEnv(const std::string& name, const std::string& value); + // only for async, sync doesn't make sense + void setStdoutFD(int fd); + // only for async, sync doesn't make sense + void setStderrFD(int fd); + /* Run the process, synchronously, get the stdout and stderr. False on fail */ bool runSync(); @@ -31,6 +36,7 @@ namespace Hyprutils { std::vector args; std::vector> env; pid_t grandchildPid = 0; + int stdoutFD = -1, stderrFD = -1; }; } } \ No newline at end of file diff --git a/src/animation/AnimatedVariable.cpp b/src/animation/AnimatedVariable.cpp index ad63a8b..02ff25c 100644 --- a/src/animation/AnimatedVariable.cpp +++ b/src/animation/AnimatedVariable.cpp @@ -5,6 +5,9 @@ using namespace Hyprutils::Animation; using namespace Hyprutils::Memory; +static const std::string DEFAULTBEZIERNAME = "default"; +static const std::string DEFAULTSTYLE = ""; + #define SP CSharedPointer #define WP CWeakPointer @@ -43,8 +46,6 @@ bool Hyprutils::Animation::CBaseAnimatedVariable::enabled() const { } const std::string& CBaseAnimatedVariable::getBezierName() const { - static constexpr const std::string DEFAULTBEZIERNAME = "default"; - if (const auto PCONFIG = m_pConfig.lock()) { const auto PVALUES = PCONFIG->pValues.lock(); return PVALUES ? PVALUES->internalBezier : DEFAULTBEZIERNAME; @@ -54,8 +55,6 @@ const std::string& CBaseAnimatedVariable::getBezierName() const { } const std::string& CBaseAnimatedVariable::getStyle() const { - static constexpr const std::string DEFAULTSTYLE = ""; - if (const auto PCONFIG = m_pConfig.lock()) { const auto PVALUES = PCONFIG->pValues.lock(); return PVALUES ? PVALUES->internalStyle : DEFAULTSTYLE; diff --git a/src/os/Process.cpp b/src/os/Process.cpp index 7f08dc9..115bbbe 100644 --- a/src/os/Process.cpp +++ b/src/os/Process.cpp @@ -189,6 +189,11 @@ bool Hyprutils::OS::CProcess::runAsync() { argsC.emplace_back(nullptr); + if (stdoutFD != -1) + dup2(stdoutFD, 1); + if (stderrFD != -1) + dup2(stderrFD, 2); + execvp(binary.c_str(), (char* const*)argsC.data()); _exit(0); } @@ -230,3 +235,11 @@ const std::string& Hyprutils::OS::CProcess::stdErr() { const pid_t Hyprutils::OS::CProcess::pid() { return grandchildPid; } + +void Hyprutils::OS::CProcess::setStdoutFD(int fd) { + stdoutFD = fd; +} + +void Hyprutils::OS::CProcess::setStderrFD(int fd) { + stderrFD = fd; +} diff --git a/tests/memory.cpp b/tests/memory.cpp index 2c43303..118e8c8 100644 --- a/tests/memory.cpp +++ b/tests/memory.cpp @@ -11,7 +11,7 @@ using namespace Hyprutils::Memory; int main(int argc, char** argv, char** envp) { SP intPtr = makeShared(10); - SP intPtr2 = makeShared(1337); + SP intPtr2 = makeShared(-1337); UP intUnique = makeUnique(420); int ret = 0; @@ -52,5 +52,15 @@ int main(int argc, char** argv, char** envp) { EXPECT(weak.expired(), true); EXPECT(weakUnique.expired(), true); + auto intPtr2AsUint = reinterpretPointerCast(intPtr2); + EXPECT(intPtr2.strongRef(), 4); + EXPECT(intPtr2AsUint.strongRef(), 4); + + EXPECT(*intPtr2AsUint > 0, true); + EXPECT(*intPtr2AsUint, (unsigned int)(int)-1337); + *intPtr2AsUint = 10; + EXPECT(*intPtr2AsUint, 10); + EXPECT(*intPtr2, 10); + return ret; } \ No newline at end of file