misc: fix some compile warnings (#25)

- Cleans up compile warnings
- Formats code
- Cleans up unused vars
- etc
This commit is contained in:
nyx 2024-12-25 14:10:14 -05:00 committed by GitHub
parent 5e45b1a1b9
commit 9be03a8562
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 29 additions and 29 deletions

View file

@ -102,7 +102,7 @@ namespace Hyprutils {
}
// absolutely ridiculous formatter spec parsing
#define AQ_FORMAT_PARSE(specs__, type__) \
#define AQ_FORMAT_PARSE(specs__, type__) \
template <typename FormatContext> \
constexpr auto parse(FormatContext& ctx) { \
auto it = ctx.begin(); \
@ -112,10 +112,10 @@ namespace Hyprutils {
return it; \
}
#define AQ_FORMAT_FLAG(spec__, flag__) \
#define AQ_FORMAT_FLAG(spec__, flag__) \
case spec__: (flag__) = true; break;
#define AQ_FORMAT_NUMBER(buf__) \
#define AQ_FORMAT_NUMBER(buf__) \
case '0': \
case '1': \
case '2': \
@ -139,9 +139,9 @@ struct std::formatter<Hyprutils::Math::Vector2D, CharT> : std::formatter<CharT>
bool formatX = false;
std::string precision = "";
AQ_FORMAT_PARSE(AQ_FORMAT_FLAG('j', formatJson) //
AQ_FORMAT_FLAG('X', formatX) //
AQ_FORMAT_NUMBER(precision),
Hyprutils::Math::Vector2D)
AQ_FORMAT_FLAG('X', formatX) //
AQ_FORMAT_NUMBER(precision),
Hyprutils::Math::Vector2D)
template <typename FormatContext>
auto format(const Hyprutils::Math::Vector2D& vec, FormatContext& ctx) const {

View file

@ -5,7 +5,7 @@ namespace Hyprutils {
namespace String {
// trims beginning and end of whitespace characters
std::string trim(const std::string& in);
bool isNumber(const std::string& str, bool allowfloat = false);
void replaceInString(std::string& string, const std::string& what, const std::string& to);
bool isNumber(const std::string& str, bool allowfloat = false);
void replaceInString(std::string& string, const std::string& what, const std::string& to);
};
};

View file

@ -200,7 +200,7 @@ Vector2D Hyprutils::Math::CBox::size() const {
}
Vector2D Hyprutils::Math::CBox::extent() const {
return pos() + size();
return pos() + size();
}
Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {

View file

@ -86,14 +86,8 @@ bool Hyprutils::OS::CProcess::runSync() {
return false;
pollfd pollfds[2] = {
{
.fd = outPipe[0],
.events = POLLIN,
},
{
.fd = errPipe[0],
.events = POLLIN,
},
{.fd = outPipe[0], .events = POLLIN, .revents = 0},
{.fd = errPipe[0], .events = POLLIN, .revents = 0},
};
while (1337) {
@ -188,26 +182,33 @@ bool Hyprutils::OS::CProcess::runAsync() {
std::vector<const char*> argsC;
argsC.emplace_back(strdup(binary.c_str()));
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(nullptr);
execvp(binary.c_str(), (char* const*)argsC.data());
// exit grandchild
_exit(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]);
// exit child
_exit(0);
}
// run in parent
close(socket[1]);
read(socket[0], &grandchild, sizeof(grandchild));
ssize_t bytesRead = read(socket[0], &grandchild, sizeof(grandchild));
close(socket[0]);
if (bytesRead != sizeof(grandchild)) {
waitpid(child, nullptr, 0);
return false;
}
// clear child and leave grandchild to init
waitpid(child, nullptr, 0);

View file

@ -12,8 +12,7 @@ Hyprutils::String::CVarList::CVarList(const std::string& in, const size_t lastAr
std::string args{in};
size_t idx = 0;
size_t pos = 0;
std::ranges::replace_if(
args, [&](const char& c) { return delim == 's' ? std::isspace(c) : c == delim; }, 0);
std::ranges::replace_if(args, [&](const char& c) { return delim == 's' ? std::isspace(c) : c == delim; }, 0);
for (const auto& s : args | std::views::split(0)) {
if (removeEmpty && s.empty())

View file

@ -8,7 +8,7 @@
using namespace Hyprutils::OS;
int main(int argc, char** argv, char** envp) {
int ret = 0;
int ret = 0;
CProcess process("sh", {"-c", "echo \"Hello $WORLD!\""});
process.addEnv("WORLD", "World");

View file

@ -10,7 +10,7 @@ int main(int argc, char** argv, char** envp) {
CSignal signal;
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();