From b2080c70d4fc91f83afe25506240e73ad7dddf65 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 25 Feb 2011 00:51:08 +0000 Subject: [PATCH] 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 --- include/locale | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/include/locale b/include/locale index 72039a59..13bac7ad 100644 --- a/include/locale +++ b/include/locale @@ -3474,7 +3474,7 @@ extern template class money_put; class _LIBCPP_VISIBLE messages_base { public: - typedef nl_catd catalog; + typedef ptrdiff_t catalog; _LIBCPP_ALWAYS_INLINE messages_base() {} }; @@ -3531,7 +3531,10 @@ template typename messages<_CharT>::catalog messages<_CharT>::do_open(const basic_string& __nm, const locale&) const { - return catopen(__nm.c_str(), NL_CAT_LOCALE); + catalog __cat = reinterpret_cast(catopen(__nm.c_str(), NL_CAT_LOCALE)); + if (__cat != -1) + __cat = static_cast((static_cast(__cat) >> 1)); + return __cat; } template @@ -3543,7 +3546,10 @@ messages<_CharT>::do_get(catalog __c, int __set, int __msgid, __narrow_to_utf8()(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(__c); + char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str()); string_type __w; __widen_from_utf8()(back_inserter(__w), __n, __n + strlen(__n)); @@ -3554,7 +3560,10 @@ template void messages<_CharT>::do_close(catalog __c) const { - catclose(__c); + if (__c != -1) + __c <<= 1; + nl_catd __cat = reinterpret_cast(__c); + catclose(__cat); } extern template class messages;