mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-01-27 19:59:48 +01:00
misc: fix some compile warnings (#25)
- Cleans up compile warnings - Formats code - Cleans up unused vars - etc
This commit is contained in:
parent
5e45b1a1b9
commit
9be03a8562
8 changed files with 29 additions and 29 deletions
|
@ -102,7 +102,7 @@ namespace Hyprutils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// absolutely ridiculous formatter spec parsing
|
// absolutely ridiculous formatter spec parsing
|
||||||
#define AQ_FORMAT_PARSE(specs__, type__) \
|
#define AQ_FORMAT_PARSE(specs__, type__) \
|
||||||
template <typename FormatContext> \
|
template <typename FormatContext> \
|
||||||
constexpr auto parse(FormatContext& ctx) { \
|
constexpr auto parse(FormatContext& ctx) { \
|
||||||
auto it = ctx.begin(); \
|
auto it = ctx.begin(); \
|
||||||
|
@ -112,10 +112,10 @@ namespace Hyprutils {
|
||||||
return it; \
|
return it; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define AQ_FORMAT_FLAG(spec__, flag__) \
|
#define AQ_FORMAT_FLAG(spec__, flag__) \
|
||||||
case spec__: (flag__) = true; break;
|
case spec__: (flag__) = true; break;
|
||||||
|
|
||||||
#define AQ_FORMAT_NUMBER(buf__) \
|
#define AQ_FORMAT_NUMBER(buf__) \
|
||||||
case '0': \
|
case '0': \
|
||||||
case '1': \
|
case '1': \
|
||||||
case '2': \
|
case '2': \
|
||||||
|
@ -139,9 +139,9 @@ struct std::formatter<Hyprutils::Math::Vector2D, CharT> : std::formatter<CharT>
|
||||||
bool formatX = false;
|
bool formatX = false;
|
||||||
std::string precision = "";
|
std::string precision = "";
|
||||||
AQ_FORMAT_PARSE(AQ_FORMAT_FLAG('j', formatJson) //
|
AQ_FORMAT_PARSE(AQ_FORMAT_FLAG('j', formatJson) //
|
||||||
AQ_FORMAT_FLAG('X', formatX) //
|
AQ_FORMAT_FLAG('X', formatX) //
|
||||||
AQ_FORMAT_NUMBER(precision),
|
AQ_FORMAT_NUMBER(precision),
|
||||||
Hyprutils::Math::Vector2D)
|
Hyprutils::Math::Vector2D)
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const Hyprutils::Math::Vector2D& vec, FormatContext& ctx) const {
|
auto format(const Hyprutils::Math::Vector2D& vec, FormatContext& ctx) const {
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace Hyprutils {
|
||||||
namespace String {
|
namespace String {
|
||||||
// trims beginning and end of whitespace characters
|
// trims beginning and end of whitespace characters
|
||||||
std::string trim(const std::string& in);
|
std::string trim(const std::string& in);
|
||||||
bool isNumber(const std::string& str, bool allowfloat = false);
|
bool isNumber(const std::string& str, bool allowfloat = false);
|
||||||
void replaceInString(std::string& string, const std::string& what, const std::string& to);
|
void replaceInString(std::string& string, const std::string& what, const std::string& to);
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -200,7 +200,7 @@ Vector2D Hyprutils::Math::CBox::size() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D Hyprutils::Math::CBox::extent() const {
|
Vector2D Hyprutils::Math::CBox::extent() const {
|
||||||
return pos() + size();
|
return pos() + size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
|
Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
|
||||||
|
|
|
@ -86,14 +86,8 @@ bool Hyprutils::OS::CProcess::runSync() {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
pollfd pollfds[2] = {
|
pollfd pollfds[2] = {
|
||||||
{
|
{.fd = outPipe[0], .events = POLLIN, .revents = 0},
|
||||||
.fd = outPipe[0],
|
{.fd = errPipe[0], .events = POLLIN, .revents = 0},
|
||||||
.events = POLLIN,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.fd = errPipe[0],
|
|
||||||
.events = POLLIN,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
while (1337) {
|
while (1337) {
|
||||||
|
@ -188,26 +182,33 @@ bool Hyprutils::OS::CProcess::runAsync() {
|
||||||
std::vector<const char*> argsC;
|
std::vector<const char*> argsC;
|
||||||
argsC.emplace_back(strdup(binary.c_str()));
|
argsC.emplace_back(strdup(binary.c_str()));
|
||||||
for (auto& arg : args) {
|
for (auto& arg : args) {
|
||||||
// TODO: does this leak? Can we just pipe c_str() as the strings won't be realloc'd?
|
|
||||||
argsC.emplace_back(strdup(arg.c_str()));
|
argsC.emplace_back(strdup(arg.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
argsC.emplace_back(nullptr);
|
argsC.emplace_back(nullptr);
|
||||||
|
|
||||||
execvp(binary.c_str(), (char* const*)argsC.data());
|
execvp(binary.c_str(), (char* const*)argsC.data());
|
||||||
// exit grandchild
|
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
close(socket[0]);
|
close(socket[0]);
|
||||||
write(socket[1], &grandchild, sizeof(grandchild));
|
if (write(socket[1], &grandchild, sizeof(grandchild)) != sizeof(grandchild)) {
|
||||||
|
close(socket[1]);
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
close(socket[1]);
|
close(socket[1]);
|
||||||
// exit child
|
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run in parent
|
// run in parent
|
||||||
close(socket[1]);
|
close(socket[1]);
|
||||||
read(socket[0], &grandchild, sizeof(grandchild));
|
ssize_t bytesRead = read(socket[0], &grandchild, sizeof(grandchild));
|
||||||
close(socket[0]);
|
close(socket[0]);
|
||||||
|
|
||||||
|
if (bytesRead != sizeof(grandchild)) {
|
||||||
|
waitpid(child, nullptr, 0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// clear child and leave grandchild to init
|
// clear child and leave grandchild to init
|
||||||
waitpid(child, nullptr, 0);
|
waitpid(child, nullptr, 0);
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ void Hyprutils::Signal::CSignal::emit(std::any data) {
|
||||||
// vector and was removed during our iteration
|
// vector and was removed during our iteration
|
||||||
if (l.strongRef() == 1)
|
if (l.strongRef() == 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
l->emit(data);
|
l->emit(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ void Hyprutils::Signal::CSignal::emit(std::any data) {
|
||||||
// release SPs
|
// release SPs
|
||||||
listeners.clear();
|
listeners.clear();
|
||||||
|
|
||||||
// we cannot release any expired refs here as one of the listeners could've removed this object and
|
// we cannot release any expired refs here as one of the listeners could've removed this object and
|
||||||
// as such we'd be doing a UAF
|
// as such we'd be doing a UAF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ CHyprSignalListener Hyprutils::Signal::CSignal::registerListener(std::function<v
|
||||||
|
|
||||||
// housekeeping: remove any stale listeners
|
// housekeeping: remove any stale listeners
|
||||||
std::erase_if(m_vListeners, [](const auto& other) { return other.expired(); });
|
std::erase_if(m_vListeners, [](const auto& other) { return other.expired(); });
|
||||||
|
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,7 @@ Hyprutils::String::CVarList::CVarList(const std::string& in, const size_t lastAr
|
||||||
std::string args{in};
|
std::string args{in};
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
std::ranges::replace_if(
|
std::ranges::replace_if(args, [&](const char& c) { return delim == 's' ? std::isspace(c) : c == delim; }, 0);
|
||||||
args, [&](const char& c) { return delim == 's' ? std::isspace(c) : c == delim; }, 0);
|
|
||||||
|
|
||||||
for (const auto& s : args | std::views::split(0)) {
|
for (const auto& s : args | std::views::split(0)) {
|
||||||
if (removeEmpty && s.empty())
|
if (removeEmpty && s.empty())
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
using namespace Hyprutils::OS;
|
using namespace Hyprutils::OS;
|
||||||
|
|
||||||
int main(int argc, char** argv, char** envp) {
|
int main(int argc, char** argv, char** envp) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
CProcess process("sh", {"-c", "echo \"Hello $WORLD!\""});
|
CProcess process("sh", {"-c", "echo \"Hello $WORLD!\""});
|
||||||
process.addEnv("WORLD", "World");
|
process.addEnv("WORLD", "World");
|
||||||
|
|
|
@ -10,7 +10,7 @@ int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
CSignal signal;
|
CSignal signal;
|
||||||
int data = 0;
|
int data = 0;
|
||||||
auto listener = signal.registerListener([&](std::any d) { data = 1; });
|
auto listener = signal.registerListener([&]([[maybe_unused]] std::any d) { data = 1; });
|
||||||
|
|
||||||
signal.emit();
|
signal.emit();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue