From 25d7e3ae8b409a1be550e25a2dbabc3c54f0d446 Mon Sep 17 00:00:00 2001 From: YRabbit Date: Mon, 14 Mar 2022 21:41:57 +1000 Subject: [PATCH 1/3] gowin: support for locales other than en_US and C Specifically, those locales where the fractional part separator in floating point numbers is not a dot. Signed-off-by: YRabbit --- gowin/main.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gowin/main.cc b/gowin/main.cc index 1473f3e8..db74545e 100644 --- a/gowin/main.cc +++ b/gowin/main.cc @@ -21,6 +21,7 @@ #ifdef MAIN_EXECUTABLE #include +#include #include #include "command.h" #include "design_utils.h" @@ -90,6 +91,11 @@ void GowinCommandHandler::customAfterLoad(Context *ctx) int main(int argc, char *argv[]) { + // set the locale here because when you create a context you create several + // floating point strings whose representation depends on the locale. If + // you don't do this, the strings will be in the C locale and later when Qt + // starts it won't be able to read them back as numbers. + std::locale::global(std::locale("")); GowinCommandHandler handler(argc, argv); return handler.exec(); } From ad00f3fdeb9e48a63c2781815d265266123f2621 Mon Sep 17 00:00:00 2001 From: YRabbit Date: Tue, 15 Mar 2022 21:52:32 +1000 Subject: [PATCH 2/3] gowin: test locale workaround Signed-off-by: YRabbit --- gowin/main.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gowin/main.cc b/gowin/main.cc index db74545e..e3c6762b 100644 --- a/gowin/main.cc +++ b/gowin/main.cc @@ -95,7 +95,11 @@ int main(int argc, char *argv[]) // floating point strings whose representation depends on the locale. If // you don't do this, the strings will be in the C locale and later when Qt // starts it won't be able to read them back as numbers. - std::locale::global(std::locale("")); + try { + std::locale::global(std::locale("")); + } catch (const std::runtime_error &e) { + // the locale is broken in this system, so leave it as it is + } GowinCommandHandler handler(argc, argv); return handler.exec(); } From 53ddbbaa8584bac463718ba4837d1ee8f79d88c4 Mon Sep 17 00:00:00 2001 From: YRabbit Date: Wed, 16 Mar 2022 05:39:55 +1000 Subject: [PATCH 3/3] Set the locale as early as possible Signed-off-by: YRabbit --- common/command.cc | 10 +++++++++- gowin/main.cc | 9 --------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/common/command.cc b/common/command.cc index 2167deb9..0de9ccc4 100644 --- a/common/command.cc +++ b/common/command.cc @@ -45,7 +45,15 @@ NEXTPNR_NAMESPACE_BEGIN -CommandHandler::CommandHandler(int argc, char **argv) : argc(argc), argv(argv) { log_streams.clear(); } +CommandHandler::CommandHandler(int argc, char **argv) : argc(argc), argv(argv) +{ + try { + std::locale::global(std::locale("")); + } catch (const std::runtime_error &e) { + // the locale is broken in this system, so leave it as it is + } + log_streams.clear(); +} bool CommandHandler::parseOptions() { diff --git a/gowin/main.cc b/gowin/main.cc index e3c6762b..19c1d02c 100644 --- a/gowin/main.cc +++ b/gowin/main.cc @@ -91,15 +91,6 @@ void GowinCommandHandler::customAfterLoad(Context *ctx) int main(int argc, char *argv[]) { - // set the locale here because when you create a context you create several - // floating point strings whose representation depends on the locale. If - // you don't do this, the strings will be in the C locale and later when Qt - // starts it won't be able to read them back as numbers. - try { - std::locale::global(std::locale("")); - } catch (const std::runtime_error &e) { - // the locale is broken in this system, so leave it as it is - } GowinCommandHandler handler(argc, argv); return handler.exec(); }