jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

Set the stream locale to "C" locally

Open sbarzowski opened this issue 6 years ago • 5 comments

So that even if there is a global locale set by the library user, Jsonnet output is still the same.

sbarzowski avatar Oct 30 '19 22:10 sbarzowski

Fixes https://github.com/google/jsonnet/issues/722.

It makes sense to add a regression test and check that we don't have the same problem in other places. Perhaps we can have a helper function to create stringstreams and clear the locale?

sbarzowski avatar Oct 30 '19 22:10 sbarzowski

The test failed on mac gcc. It looked like a legitimate failure with the locale stuff but I didn't understand the error. I ran it again anyway, just in case.

sparkprime avatar Dec 10 '19 21:12 sparkprime

Same thing:

terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid

sparkprime avatar Dec 10 '19 21:12 sparkprime

My guess would be that it needs some packaged installed to get the right locale files. However I'm not sure why it works on clang but not gcc? Maybe they use different standard libraries and the clang library bundles it.

sparkprime avatar Dec 12 '19 12:12 sparkprime

I tried getting to the bottom of this again, but I'm still very confused. One idea that I haven't checked yet is that the locale is just not there, but clang-compiled-version falls back to something "gracefully" and gcc-compiled-version crashes.

sbarzowski avatar Dec 17 '19 21:12 sbarzowski

This still seems worth fixing. std::locale::classic / C locale should always be available I think. We just need the test itself to not rely on a particular locale that might not be available on the system where the test is running.

I've rebased to master and made some adjustments to the test, see https://github.com/google/jsonnet/compare/master...johnbartholomew:jsonnet:sbarzowski-fix-locale-dependence

johnbartholomew avatar Feb 29 '24 16:02 johnbartholomew

Re: the test failure on Mac (https://github.com/google/jsonnet/pull/724#issuecomment-564268750), it might be this? https://stackoverflow.com/a/58385001

Anyway, I think it can/should be avoided by just defining a custom locale facet for the test.

johnbartholomew avatar Mar 02 '24 14:03 johnbartholomew

As this PR has been open for a long time (4+ years), I'll just go ahead and rebase and merge this (with a few adjustments/additions)

johnbartholomew avatar Mar 02 '24 18:03 johnbartholomew