Chris Jefferson spotted a problem with messages_base::catalog while getting libc++ to work on boost. The standard says this type must be an int. But this type is the key returned by the OS facility catopen. On OS X the type returned by catopen is void*, which doesn't fit into an int on 64 bit platforms. Chris suggested using ptrdiff_t instead of void*. It still isn't compliant with the standard, but chances are that this change will fix what is ailing boost. Chris also supplied the algorithm for distinguishing high-order pointers from error conditions. Thanks Chris.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@126462 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2011-02-25 00:51:08 +00:00
parent 5a245dbf52
commit b2080c70d4

View File

@ -3474,7 +3474,7 @@ extern template class money_put<wchar_t>;
class _LIBCPP_VISIBLE messages_base
{
public:
typedef nl_catd catalog;
typedef ptrdiff_t catalog;
_LIBCPP_ALWAYS_INLINE messages_base() {}
};
@ -3531,7 +3531,10 @@ template <class _CharT>
typename messages<_CharT>::catalog
messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
{
return catopen(__nm.c_str(), NL_CAT_LOCALE);
catalog __cat = reinterpret_cast<catalog>(catopen(__nm.c_str(), NL_CAT_LOCALE));
if (__cat != -1)
__cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
return __cat;
}
template <class _CharT>
@ -3543,7 +3546,10 @@ messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
__narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt),
__dflt.c_str(),
__dflt.c_str() + __dflt.size());
char* __n = catgets(__c, __set, __msgid, __ndflt.c_str());
if (__c != -1)
__c <<= 1;
nl_catd __cat = reinterpret_cast<nl_catd>(__c);
char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
string_type __w;
__widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w),
__n, __n + strlen(__n));
@ -3554,7 +3560,10 @@ template <class _CharT>
void
messages<_CharT>::do_close(catalog __c) const
{
catclose(__c);
if (__c != -1)
__c <<= 1;
nl_catd __cat = reinterpret_cast<nl_catd>(__c);
catclose(__cat);
}
extern template class messages<char>;