-
Notifications
You must be signed in to change notification settings - Fork 36.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
qt: Kill the locale dependency bug class by not allowing Qt to mess with LC_NUMERIC #18147
qt: Kill the locale dependency bug class by not allowing Qt to mess with LC_NUMERIC #18147
Conversation
Concept NACK. Locale-enabled functions should be using the user's locale. If we don't want that, we should use locale-independent equivalents. |
I'm unable to parse your message. In
Which of these are you suggesting should be set according to what the user has specified in his/hers |
@practicalswift The user-specified locale should affect all locale code, so all 3 should be set correctly... |
@luke-jr Are you aware that it does not work like that today? |
@luke-jr Are you aware that we never set the global C++ locale to the user-specified locale in any of the programs we produce? |
@luke-jr Friendly ping. Could you clarify? :) I'm trying to make sense of the feedback. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
I agree with Luke-Jr for a change. We should move to locale-independent functions for locale-independent formatting and functionality (RPC and command line handling and logging and such), not add more and more layers of these kind of increasingly obscure global workarounds to coerce the functions into hopefully being locale-independent. |
I agree that we should use locale-independent functions, but I think you're misunderstanding what I am suggesting. I think that the implicit AFAICT we rely on From what I can tell this implicit Are you following my reasoning? If not, can you think of a counter-example where we want the My suggestion is thus that:
I think we should do both - not either-or :) What would the downsides be from such an approach? :) |
fd04faa
to
26be181
Compare
Rebased :) |
@practicalswift My preference (and I suspect that's what @laanwj means as well) is that in the parts of the codebase that are supposed to be locale-independent, simply no locale-related operations are present (including locale-dependent formatting, or checks of, or setting of, any global locale). That would make those pieces of code maximally reusable. |
@sipa I understand that and I agree with that: I've worked extensively with getting rid of the use of locale-dependent functions in our code base :) What I still don't understand is how we would be better off by opting in to locale dependence that we do not want. I don't see how a.) getting rid of usage of locale independent functions and b.) not opting in to locale dependence we do not want would in any way be mutually exclusive :) To make this more concrete: Is there a single place in the code base where we want the locale dependency we're now opting in to by the implicit Are we intentionally opting in to locale dependency for the POSIX functions? To me it looks like this is purely by accident. Please correct me if I'm wrong :) From the Qt documentation:
|
I guess this is like mitigations in general -- an example:
a.) and b.) are clearly not mutually exclusive: we would do b.) immediately and over time do our best to achieve a.) as well. I fail to see how this case is different :) This case:
Help me understand what I'm missing :) |
Closing this issue. Seems like I was unable to gather consensus support for permanently killing off the locale dependency bug class by fixing the root cause (unintended Qt interference with POSIX I guess we'll have to live with locale issues also in the future, but now the root cause is documented at least and this PR can be referenced when we hit locale issues going forward :) |
Kill the locale dependency bug class by not allowing Qt to mess with
LC_NUMERIC
.Context: #18124 (Recommended reading if you are unsure about how C and C++ locales work in C++)
Guaranteed locale settings before this PR:
LC_NUMERIC
std::locale
)bitcoind
C
(classic)C
(classic)bitcoin-qt
C
(classic)Guaranteed locale settings after this PR:
LC_NUMERIC
std::locale
)bitcoind
C
(classic)C
(classic)bitcoin-qt
C
(classic)C
(classic)Background:
Perhaps surprisingly Qt runs
setlocale(LC_ALL, "")
on initialization. This installs the locale specified by the user'sLC_ALL
(orLC_*
) environment variable as the new C locale.In contrast
bitcoind
does not opt-in to localization -- no call tosetlocale(LC_ALL, "")
(orstd::locale::global(std::locale(""))
) is made and the environment variablesLC_*
are thus ignored.This results in an unfortunate situation where the
bitcoind
is guaranteed to be running with the classic locale ("C"
) whereas the locale ofbitcoin-qt
will vary depending on the user's environment variables.An example: Assuming the environment variable
LC_ALL=de_DE
then the callstd::to_string(1.23)
will return"1.230000"
inbitcoind
but"1,230000"
inbitcoin-qt
.From the Qt documentation:
C and C++ locales 101:
Let's try with
LC_ALL=de_DE ./l8n
without any opt-in to locale dependence:Let's try with
LC_NUMERIC=de_DE ./l8n
without any opt-in to locale dependence:Let's try
LC_ALL=de_DE ./l8n
with opt-in to locale dependence usingset_locale
:Let's try
LC_ALL=de_DE ./l8n
with opt-in to locale dependence usingstd::locale::global
: