Skip to content

Commit

Permalink
Don't crash examples/benchmarks if locale not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Oipo committed Sep 20, 2024
1 parent d71e643 commit 55bd64c
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 22 deletions.
6 changes: 5 additions & 1 deletion benchmarks/coroutine_benchmark/ichor_coroutine_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@


int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

bool showHelp{};
bool singleOnly{};
Expand Down
6 changes: 5 additions & 1 deletion benchmarks/event_benchmark/ichor_event_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
//#include <spdlog/sinks/stdout_color_sinks.h>

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}
// auto new_logger = spdlog::stdout_color_mt("default_logger");
// new_logger->set_pattern("[%H:%M:%S.%f] [%t] [%l] %v");
// spdlog::set_default_logger(new_logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ uint64_t sizeof_test{};
const uint32_t threadCount{8};

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

bool showHelp{};
bool singleOnly{};
Expand Down
6 changes: 5 additions & 1 deletion benchmarks/start_benchmark/ichor_start_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
#include "../../examples/common/lyra.hpp"

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

bool showHelp{};
bool singleOnly{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
#include "../../examples/common/lyra.hpp"

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

bool showHelp{};
bool singleOnly{};
Expand Down
6 changes: 5 additions & 1 deletion benchmarks/utils_benchmark/ichor_utils_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ void run_regex_bench(char *argv) {
}

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

bool onlyPrint{};
bool onlyRegex{};
Expand Down
6 changes: 5 additions & 1 deletion examples/etcd_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down
6 changes: 5 additions & 1 deletion examples/event_statistics_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ using namespace Ichor;
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down
6 changes: 5 additions & 1 deletion examples/factory_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down
6 changes: 5 additions & 1 deletion examples/http_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ using namespace std::string_literals;
using namespace Ichor;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

uint64_t verbosity{};
uint64_t threads{1};
Expand Down
6 changes: 5 additions & 1 deletion examples/http_ping_pong/ping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ using namespace std::string_literals;
using namespace Ichor;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

uint64_t verbosity{};
bool silent{};
Expand Down
6 changes: 5 additions & 1 deletion examples/http_ping_pong/pong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ using namespace std::string_literals;
using namespace Ichor;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

uint64_t verbosity{};
uint64_t threads{1};
Expand Down
6 changes: 5 additions & 1 deletion examples/introspection_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ using namespace Ichor;
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down
7 changes: 6 additions & 1 deletion examples/minimal_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class SigIntService final {
};

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8")); // some loggers require having a locale
// some loggers require having a locale
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto queue = std::make_unique<PriorityQueue>();
auto &dm = queue->createManager();
Expand Down
6 changes: 5 additions & 1 deletion examples/multithreaded_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#include <thread>

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();

Expand Down
6 changes: 5 additions & 1 deletion examples/optional_dependency_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down
6 changes: 5 additions & 1 deletion examples/realtime_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ void* run_example(void*) {
}

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}
progName = argv[0];

#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32) || defined(__APPLE__)) && !defined(__CYGWIN__)
Expand Down
6 changes: 5 additions & 1 deletion examples/serializer_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
#include <iostream>

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down
6 changes: 5 additions & 1 deletion examples/tcp_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<QIMPL>(500);
Expand Down
6 changes: 5 additions & 1 deletion examples/timer_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down
6 changes: 5 additions & 1 deletion examples/websocket_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ using namespace std::string_literals;
using namespace Ichor;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

uint64_t verbosity{};
uint64_t threads{1};
Expand Down
6 changes: 5 additions & 1 deletion examples/yielding_timer_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
using namespace std::string_literals;

int main(int argc, char *argv[]) {
std::locale::global(std::locale("en_US.UTF-8"));
try {
std::locale::global(std::locale("en_US.UTF-8"));
} catch(std::runtime_error const &e) {
fmt::println("Couldn't set locale to en_US.UTF-8: {}", e.what());
}

auto start = std::chrono::steady_clock::now();
auto queue = std::make_unique<PriorityQueue>();
Expand Down

0 comments on commit 55bd64c

Please sign in to comment.