Boost C++ Libraries: Ticket #5289: Library that uses Boost Filesystem would not start when the stdandard C++ library does not support the current locale https://svn.boost.org/trac10/ticket/5289 <p> The standard C++ library required to support only C and POSIX locales, for others it may not be possible to create locale object. </p> <p> Thus std::locale("") would fail if the default system locale is not C or POSIX on may systems. </p> <p> 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. </p> <p> 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. </p> <p> 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. </p> <p> I had attached the patch with following changes: </p> <p> 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. </p> <p> 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. </p> <p> 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. </p> <p> This is better then implement codecvt over <a class="missing wiki">Wide/Narrow</a> API as it would not work correctly on boundaries of double width encoding like Shift-JIS or BIG5. </p> <p> 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. </p> <p> So I think it is always best idea to give a best shot do standard C++ library rather then install your own facets. </p> <p> The patch is attached. </p> <p> Artyom Beilis (Author of Boost.Locale) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5289 Trac 1.4.3 artyomtnk@… Thu, 10 Mar 2011 14:49:37 GMT attachment set https://svn.boost.org/trac10/ticket/5289 https://svn.boost.org/trac10/ticket/5289 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_filesystem.patch</span> </li> </ul> Ticket Sam Morris <sam@…> Tue, 31 May 2011 10:14:34 GMT <link>https://svn.boost.org/trac10/ticket/5289#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5289#comment:1</guid> <description> <p> Duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4688" title="#4688: Bugs: std::runtime_error: locale::facet::_S_create_c_locale name not valid (closed: fixed)">#4688</a>? </p> </description> <category>Ticket</category> </item> <item> <author>artyomtnk@…</author> <pubDate>Tue, 31 May 2011 11:14:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5289#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5289#comment:2</guid> <description> <p> It is duplicate but the patch attached there is not correct. As even on Linux it may not start if LANG=xx_YY.UTF-8 that is not configured on this OS (locale -a) then it would fail as well. </p> <p> So the patch there is wrong. </p> <p> My patch handles it much better even on system when gcc does not support non-POSIX locales. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Tue, 07 Jun 2011 10:43:03 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/5289#comment:3 https://svn.boost.org/trac10/ticket/5289#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I'm concerned that this patch doesn't include any test cases. I'd really like to first add additional test cases that fail with the current implementation and then pass when the patch is supplied. </p> <p> Thanks, </p> <p> --Beman </p> Ticket artyomtnk@… Tue, 07 Jun 2011 12:08:51 GMT <link>https://svn.boost.org/trac10/ticket/5289#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5289#comment:4</guid> <description> <blockquote class="citation"> <p> I'm concerned that this patch doesn't include any test cases. I'd really like to first add additional test cases that fail with the current implementation and then pass when the patch is supplied </p> </blockquote> <p> The simplest test that can be done under any platform is: </p> <ol><li>link the library to simple executable that does nothing. </li><li>Run it with environment variable "LANG" set to "xx_YY.UTF-8" (illegal locale) and check if the library starts (fails to start without this patch). </li><li>Check that the boost::filesystem::path's locale has UTF-8 facet (trivially by converting one wide NON-ASCII character to char. </li></ol><p> It is very easy to reproduce this bug (by setting illegal locale environment variable) but it requires some non-trivial scripting with BBv2 (that I unfortunately not too familiar with it) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 29 Jul 2011 15:32:49 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5289#comment:5 https://svn.boost.org/trac10/ticket/5289#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed by changeset 72855, Fix problem of locale("") exception being thrown before main() starts on misconfigured (e.g. LANG="bad name") POSIX systems. Resolves the most serious aspect of tickets 4688, 5100, 5289. </p> <p> Boost 1.47.0 was the first release to include this fix. </p> <p> --Beman </p> Ticket bbazso@… Tue, 25 Oct 2011 13:43:58 GMT <link>https://svn.boost.org/trac10/ticket/5289#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5289#comment:6</guid> <description> <p> I do not think that this issue should be closed or perhaps another one needs to be opened, but there is definitely still a problem associated with this issue. When I call the function: </p> <p> boost::filesystem::create_directories (iDirectory); </p> <p> To create a directory, I get the error: </p> <p> locale::facet::_S_create_c_locale name not valid </p> <p> I am running Boost 1.47.0 on the following system: </p> <pre class="wiki">DISTRIB_ID=Ubuntu DISTRIB_RELEASE=9.04 DISTRIB_CODENAME=jaunty DISTRIB_DESCRIPTION="Ubuntu 9.04" </pre><p> I manually patched Boost 1.47.0 with the patch in this issue and it solves the issue. So I think that a issue should be opened or this one re-opened. </p> </description> <category>Ticket</category> </item> </channel> </rss>