Skip to content

Commit 0c68ed0

Browse files
author
Howard Hinnant
committed
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.
llvm-svn: 126462
1 parent 4d0779a commit 0c68ed0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

libcxx/include/locale

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,7 +3474,7 @@ extern template class money_put<wchar_t>;
34743474
class _LIBCPP_VISIBLE messages_base
34753475
{
34763476
public:
3477-
typedef nl_catd catalog;
3477+
typedef ptrdiff_t catalog;
34783478

34793479
_LIBCPP_ALWAYS_INLINE messages_base() {}
34803480
};
@@ -3531,7 +3531,10 @@ template <class _CharT>
35313531
typename messages<_CharT>::catalog
35323532
messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
35333533
{
3534-
return catopen(__nm.c_str(), NL_CAT_LOCALE);
3534+
catalog __cat = reinterpret_cast<catalog>(catopen(__nm.c_str(), NL_CAT_LOCALE));
3535+
if (__cat != -1)
3536+
__cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
3537+
return __cat;
35353538
}
35363539

35373540
template <class _CharT>
@@ -3543,7 +3546,10 @@ messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
35433546
__narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt),
35443547
__dflt.c_str(),
35453548
__dflt.c_str() + __dflt.size());
3546-
char* __n = catgets(__c, __set, __msgid, __ndflt.c_str());
3549+
if (__c != -1)
3550+
__c <<= 1;
3551+
nl_catd __cat = reinterpret_cast<nl_catd>(__c);
3552+
char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
35473553
string_type __w;
35483554
__widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w),
35493555
__n, __n + strlen(__n));
@@ -3554,7 +3560,10 @@ template <class _CharT>
35543560
void
35553561
messages<_CharT>::do_close(catalog __c) const
35563562
{
3557-
catclose(__c);
3563+
if (__c != -1)
3564+
__c <<= 1;
3565+
nl_catd __cat = reinterpret_cast<nl_catd>(__c);
3566+
catclose(__cat);
35583567
}
35593568

35603569
extern template class messages<char>;

0 commit comments

Comments
 (0)