Ticket #5289 (closed Bugs: fixed)
Library that uses Boost Filesystem would not start when the stdandard C++ library does not support the current locale
|Reported by:||artyomtnk@…||Owned by:||bemandawes|
The standard C++ library required to support only C and POSIX locales, for others it may not be possible to create locale object.
Thus std::locale("") would fail if the default system locale is not C or POSIX on may systems.
For example, GCC support locales only on Linux so basically global_locale() would throw anywhere except Linux, in the Boost.Filesystem's code this means that it would not be possible to even start program under Solaris or FreeBSD.
Even under Linux it is not possible to get to main() when linked with boost.filesystem shared library and the locale (LANG env. variable) is not supported.
Simple test. Link the program with boost.filesystem and try to run the program giving LANG=foo_BAR.UTF-8 - the program would not even start. Of course if may happen even for legal locales like de_AU.UTF-8 that are not configured on this operating system.
I had attached the patch with following changes:
If std::locale("") fails, check if current system locale's charset is UTF-8, if so install utf-8 facet otherwise fallback to global locale.
It would cover most of frequent cases when the standard library does not support the global locale and would not fail on locale generation, it may fail later on conversion if the charset is not supported. But it at least would work for ASCII subset.
The second change in the attached patch is that it always tries to use std::locale(""), for example MSVC fully supports them so why would not use the default one.
This is better then implement codecvt over Wide/Narrow? API as it would not work correctly on boundaries of double width encoding like Shift-JIS or BIG5.
For example of you have sequence "XYYZ" where X, YY and X are "characters" where YY is double width encoded character then if you would do partial conversion of "XY" it would return "error", rather then "partial" which is wrong.
So I think it is always best idea to give a best shot do standard C++ library rather then install your own facets.
The patch is attached.
Artyom Beilis (Author of Boost.Locale)
- Status changed from assigned to closed
- Resolution set to fixed