Re: parsing configs with non-C locale
toggle quoted message Show quoted text
I've not had much experience with locales either, but it seemed like an interesting thing to read up on.. so..
With LANG=de_DE, sscanf expects to see floats like "0,12" (compared to 0.12 as required in the LUT file)
Doesn't happen often because the locale defaults to "C", and the user's environment is ignored unless setlocale() has been called elsewhere in the process:
I think OCIO should definitely set the locale to "C" temporarily while parsing/writing files, otherwise it might end up with invalid LUT's that happen to work for the current user but no-one else..
Based on this page..
..I think the tidiest way to fix this would be:
- Replace the few usages of the C string-parsing methods (sscanf/atof/etc) with the C++ stdlib equivalents (the *stream stuff)
- Modify FileTransform.cpp:GetFile to imbue the filestream with the "C" locale (as described in the above apache.org link)
- Same imbue'ing wherever else std::ofstream or std::ifstream is used (not many places - main ones are FileTransform, ociobakelut, and the CDLTransform)
I think that should make the reading/writing of files locale-independant, but there might still be other issues..? (e.g the stringstream used to construct exception messages)
Python has a kind of similar problem, seems like their approach was to write their own atof/stdtod methods, but I don't think this will work for OCIO, since it mainly uses the C++ *stream stuff..
On 17/11/2012, at 2:46 AM, Jeremy Selan wrote:
I have to admit I dont have much experience with locales. Can someone
with experience on such issues please comment? On first glance, it
feels like it should certainly be fixed inside OCIO, but perhaps I am
On Thu, Nov 15, 2012 at 7:01 AM, Paul Miller <pa...@...> wrote:I think I found a bug in either my code or OCIO. When our software is run ona Ubuntu 12.04 machine with a German locale, parsing of srgb.spi1d fails andwe get an "Invalid 'From' Tag" exception. I think the sscanf() there isattempting to parse the string using the German locale. Should I be forcingthe C locale before calling into OCIO, or should OCIO be doing this itself?