Work on Windows port by Ruben Van Boxem

llvm-svn: 140384
This commit is contained in:
Howard Hinnant 2011-09-23 16:11:27 +00:00
parent a54fd541c2
commit dbe8111948
8 changed files with 159 additions and 30 deletions

View File

@ -687,12 +687,12 @@ move_backward(__bit_iterator<_C, _IsConst> __first, __bit_iterator<_C, _IsConst>
// swap_ranges // swap_ranges
template <class _C1, class _C2> template <class __C1, class __C2>
__bit_iterator<_C2, false> __bit_iterator<__C2, false>
__swap_ranges_aligned(__bit_iterator<_C1, false> __first, __bit_iterator<_C1, false> __last, __swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
__bit_iterator<_C2, false> __result) __bit_iterator<__C2, false> __result)
{ {
typedef __bit_iterator<_C1, false> _I1; typedef __bit_iterator<__C1, false> _I1;
typedef typename _I1::difference_type difference_type; typedef typename _I1::difference_type difference_type;
typedef typename _I1::__storage_type __storage_type; typedef typename _I1::__storage_type __storage_type;
static const unsigned __bits_per_word = _I1::__bits_per_word; static const unsigned __bits_per_word = _I1::__bits_per_word;
@ -737,12 +737,12 @@ __swap_ranges_aligned(__bit_iterator<_C1, false> __first, __bit_iterator<_C1, fa
return __result; return __result;
} }
template <class _C1, class _C2> template <class __C1, class __C2>
__bit_iterator<_C2, false> __bit_iterator<__C2, false>
__swap_ranges_unaligned(__bit_iterator<_C1, false> __first, __bit_iterator<_C1, false> __last, __swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
__bit_iterator<_C2, false> __result) __bit_iterator<__C2, false> __result)
{ {
typedef __bit_iterator<_C1, false> _I1; typedef __bit_iterator<__C1, false> _I1;
typedef typename _I1::difference_type difference_type; typedef typename _I1::difference_type difference_type;
typedef typename _I1::__storage_type __storage_type; typedef typename _I1::__storage_type __storage_type;
static const unsigned __bits_per_word = _I1::__bits_per_word; static const unsigned __bits_per_word = _I1::__bits_per_word;
@ -837,11 +837,11 @@ __swap_ranges_unaligned(__bit_iterator<_C1, false> __first, __bit_iterator<_C1,
return __result; return __result;
} }
template <class _C1, class _C2> template <class __C1, class __C2>
inline _LIBCPP_INLINE_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<_C2, false> __bit_iterator<__C2, false>
swap_ranges(__bit_iterator<_C1, false> __first1, __bit_iterator<_C1, false> __last1, swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1,
__bit_iterator<_C2, false> __first2) __bit_iterator<__C2, false> __first2)
{ {
if (__first1.__ctz_ == __first2.__ctz_) if (__first1.__ctz_ == __first2.__ctz_)
return __swap_ranges_aligned(__first1, __last1, __first2); return __swap_ranges_aligned(__first1, __last1, __first2);
@ -1213,15 +1213,15 @@ private:
template <class _D, bool _IC> friend __bit_iterator<_D, false> copy_backward(__bit_iterator<_D, _IC> __first, template <class _D, bool _IC> friend __bit_iterator<_D, false> copy_backward(__bit_iterator<_D, _IC> __first,
__bit_iterator<_D, _IC> __last, __bit_iterator<_D, _IC> __last,
__bit_iterator<_D, false> __result); __bit_iterator<_D, false> __result);
template <class _C1, class _C2>friend __bit_iterator<_C2, false> __swap_ranges_aligned(__bit_iterator<_C1, false>, template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>,
__bit_iterator<_C1, false>, __bit_iterator<__C1, false>,
__bit_iterator<_C2, false>); __bit_iterator<__C2, false>);
template <class _C1, class _C2>friend __bit_iterator<_C2, false> __swap_ranges_unaligned(__bit_iterator<_C1, false>, template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>,
__bit_iterator<_C1, false>, __bit_iterator<__C1, false>,
__bit_iterator<_C2, false>); __bit_iterator<__C2, false>);
template <class _C1, class _C2>friend __bit_iterator<_C2, false> swap_ranges(__bit_iterator<_C1, false>, template <class __C1, class __C2>friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>,
__bit_iterator<_C1, false>, __bit_iterator<__C1, false>,
__bit_iterator<_C2, false>); __bit_iterator<__C2, false>);
template <class _D> friend __bit_iterator<_D, false> rotate(__bit_iterator<_D, false>, template <class _D> friend __bit_iterator<_D, false> rotate(__bit_iterator<_D, false>,
__bit_iterator<_D, false>, __bit_iterator<_D, false>,
__bit_iterator<_D, false>); __bit_iterator<_D, false>);

View File

@ -186,7 +186,9 @@ template <class charT> class messages_byname;
#endif #endif
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#if !_WIN32 #if _WIN32
#include <support/win32/support.h> // vasprintf
#else // _WIN32
#include <nl_types.h> #include <nl_types.h>
#endif // !_WIN32 #endif // !_WIN32
@ -3711,10 +3713,14 @@ template <class _CharT>
typename messages<_CharT>::catalog typename messages<_CharT>::catalog
messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
{ {
#if _WIN32
return -1;
#else // _WIN32
catalog __cat = reinterpret_cast<catalog>(catopen(__nm.c_str(), NL_CAT_LOCALE)); catalog __cat = reinterpret_cast<catalog>(catopen(__nm.c_str(), NL_CAT_LOCALE));
if (__cat != -1) if (__cat != -1)
__cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1)); __cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
return __cat; return __cat;
#endif // _WIN32
} }
template <class _CharT> template <class _CharT>
@ -3722,6 +3728,9 @@ typename messages<_CharT>::string_type
messages<_CharT>::do_get(catalog __c, int __set, int __msgid, messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
const string_type& __dflt) const const string_type& __dflt) const
{ {
#if _WIN32
return __dflt;
#else // _WIN32
string __ndflt; string __ndflt;
__narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt), __narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt),
__dflt.c_str(), __dflt.c_str(),
@ -3734,16 +3743,19 @@ messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
__widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w), __widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w),
__n, __n + strlen(__n)); __n, __n + strlen(__n));
return __w; return __w;
#endif // _WIN32
} }
template <class _CharT> template <class _CharT>
void void
messages<_CharT>::do_close(catalog __c) const messages<_CharT>::do_close(catalog __c) const
{ {
#if !_WIN32
if (__c != -1) if (__c != -1)
__c <<= 1; __c <<= 1;
nl_catd __cat = reinterpret_cast<nl_catd>(__c); nl_catd __cat = reinterpret_cast<nl_catd>(__c);
catclose(__cat); catclose(__cat);
#endif // !_WIN32
} }
extern template class messages<char>; extern template class messages<char>;

View File

@ -18,13 +18,44 @@
#define strtold_l _strtod_l #define strtold_l _strtod_l
#define isdigit_l _isdigit_l #define isdigit_l _isdigit_l
#define isxdigit_l _isxdigit_l #define isxdigit_l _isxdigit_l
#define newlocale _create_locale #define strcoll_l _strcoll_l
#define strxfrm_l _strxfrm_l
#define wcscoll_l _wcscoll_l
#define wcsxfrm_l _wcsxfrm_l
#define toupper_l _toupper_l
#define tolower_l _tolower_l
#define iswspace_l _iswspace_l
#define iswprint_l _iswprint_l
#define iswcntrl_l _iswcntrl_l
#define iswupper_l _iswupper_l
#define iswlower_l _iswlower_l
#define iswalpha_l _iswalpha_l
#define iswdigit_l _iswdigit_l
#define iswpunct_l _iswpunct_l
#define iswxdigit_l _iswxdigit_l
#define towupper_l _towupper_l
#define towlower_l _towlower_l
#define strftime_l _strftime_l
inline int isblank_l( int c, locale_t /*loc*/ )
{
return ( c == ' ' || c == '\t' );
}
inline int iswblank_l( wint_t c, locale_t /*loc*/ )
{
return ( c == L' ' || c == L'\t' );
}
#define freelocale _free_locale #define freelocale _free_locale
// ignore base; it is always 0 in libc++ code
inline locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
{
return _create_locale( mask, locale );
}
// FIXME: first call _configthreadlocale(_ENABLE_PER_THREAD_LOCALE) somewhere // FIXME: first call _configthreadlocale(_ENABLE_PER_THREAD_LOCALE) somewhere
// FIXME: return types are different, need to make locale_t from char* // FIXME: return types are different, need to make locale_t from char*
inline locale_t uselocale(locale_t newloc) inline locale_t uselocale(locale_t newloc)
{ {
return newlocale( LC_ALL, setlocale(LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale) ); return _create_locale( LC_ALL, setlocale(LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale) );
} }
#define LC_COLLATE_MASK _M_COLLATE #define LC_COLLATE_MASK _M_COLLATE
@ -33,5 +64,9 @@ inline locale_t uselocale(locale_t newloc)
#define LC_NUMERIC_MASK _M_NUMERIC #define LC_NUMERIC_MASK _M_NUMERIC
#define LC_TIME_MASK _M_TIME #define LC_TIME_MASK _M_TIME
#define LC_MESSAGES_MASK _M_MESSAGES #define LC_MESSAGES_MASK _M_MESSAGES
#define LC_ALL_MASK ( LC_COLLATE_MASK \
enum { NL_SETD=0, NL_CAT_LOCALE=1 }; | LC_CTYPE_MASK \
| LC_MESSAGES_MASK \
| LC_MONETARY_MASK \
| LC_NUMERIC_MASK \
| LC_TIME_MASK )

View File

@ -12,4 +12,12 @@
Functions and constants used in libc++ that are missing from the Windows C library. Functions and constants used in libc++ that are missing from the Windows C library.
*/ */
#if __MINGW32__
#include <stdio.h>
#define swprintf snwprintf
#endif // __MINGW32__
int vasprintf( char **sptr, const char *__restrict__ fmt , va_list ap ); int vasprintf( char **sptr, const char *__restrict__ fmt , va_list ap );
size_t mbsnrtowcs( wchar_t *__restrict__ dst, const char **__restrict__ src,
size_t nmc, size_t len, mbstate_t *__restrict__ ps );
size_t wcsnrtombs( char *__restrict__ dst, const wchar_t **__restrict__ src,
size_t nwc, size_t len, mbstate_t *__restrict__ ps );

View File

@ -19,7 +19,11 @@
#include "cstring" #include "cstring"
#include "cwctype" #include "cwctype"
#include "__sso_allocator" #include "__sso_allocator"
#if _WIN32
#include <locale.h>
#else // _WIN32
#include <langinfo.h> #include <langinfo.h>
#endif // _!WIN32
#include <stdlib.h> #include <stdlib.h>
#ifdef _LIBCPP_STABLE_APPLE_ABI #ifdef _LIBCPP_STABLE_APPLE_ABI
@ -5568,16 +5572,29 @@ moneypunct_byname<char, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits; __frac_digits_ = lc->int_frac_digits;
else else
__frac_digits_ = base::do_frac_digits(); __frac_digits_ = base::do_frac_digits();
#if _WIN32
if (lc->p_sign_posn == 0)
#else // _WIN32
if (lc->int_p_sign_posn == 0) if (lc->int_p_sign_posn == 0)
#endif //_WIN32
__positive_sign_ = "()"; __positive_sign_ = "()";
else else
__positive_sign_ = lc->positive_sign; __positive_sign_ = lc->positive_sign;
#if _WIN32
if(lc->n_sign_posn == 0)
#else // _WIN32
if (lc->int_n_sign_posn == 0) if (lc->int_n_sign_posn == 0)
#endif // _WIN32
__negative_sign_ = "()"; __negative_sign_ = "()";
else else
__negative_sign_ = lc->negative_sign; __negative_sign_ = lc->negative_sign;
#if _WIN32
__init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
__init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
#else
__init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn); __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn);
__init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn); __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn);
#endif // _WIN32
} }
template<> template<>
@ -5698,7 +5715,11 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits; __frac_digits_ = lc->int_frac_digits;
else else
__frac_digits_ = base::do_frac_digits(); __frac_digits_ = base::do_frac_digits();
#if _WIN32
if (lc->p_sign_posn == 0)
#else // _WIN32
if (lc->int_p_sign_posn == 0) if (lc->int_p_sign_posn == 0)
#endif // _WIN32
__positive_sign_ = L"()"; __positive_sign_ = L"()";
else else
{ {
@ -5714,7 +5735,11 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
wbe = wbuf + j; wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe); __positive_sign_.assign(wbuf, wbe);
} }
#if _WIN32
if (lc->n_sign_posn == 0)
#else // _WIN32
if (lc->int_n_sign_posn == 0) if (lc->int_n_sign_posn == 0)
#endif // _WIN32
__negative_sign_ = L"()"; __negative_sign_ = L"()";
else else
{ {
@ -5730,8 +5755,13 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
wbe = wbuf + j; wbe = wbuf + j;
__negative_sign_.assign(wbuf, wbe); __negative_sign_.assign(wbuf, wbe);
} }
#if _WIN32
__init_pat(__pos_format_, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn);
__init_pat(__neg_format_, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn);
#else // _WIN32
__init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn); __init_pat(__pos_format_, lc->int_p_cs_precedes, lc->int_p_sep_by_space, lc->int_p_sign_posn);
__init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn); __init_pat(__neg_format_, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn);
#endif // _WIN32
} }
void __do_nothing(void*) {} void __do_nothing(void*) {}

View File

@ -11,6 +11,9 @@
#include "cstdlib" #include "cstdlib"
#include "cwchar" #include "cwchar"
#include "cerrno" #include "cerrno"
#if _WIN32
#include "support/win32/support.h"
#endif // _WIN32
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD

View File

@ -8,11 +8,17 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include <stddef.h> // size_t
#include <stdlib.h> // malloc
#include <stdio.h> // vsprintf, vsnprintf
#include <string.h> // strcpy, wcsncpy
#include <wchar.h> // mbstate_t
int vasprintf( char **sptr, const char *__restrict__ fmt, va_list ap ) int vasprintf( char **sptr, const char *__restrict__ fmt, va_list ap )
{ {
*sptr = NULL *sptr = NULL;
int count = vsnprintf( *sptr, 0, fmt, ap ); int count = vsnprintf( *sptr, 0, fmt, ap );
if( (count >= 0) && ((*sptr = malloc(count+1)) != NULL) ) if( (count >= 0) && ((*sptr = (char*)malloc(count+1)) != NULL) )
{ {
vsprintf( *sptr, fmt, ap ); vsprintf( *sptr, fmt, ap );
sptr[count] = '\0'; sptr[count] = '\0';
@ -20,3 +26,36 @@ int vasprintf( char **sptr, const char *__restrict__ fmt, va_list ap )
return count; return count;
} }
// FIXME: use wcrtomb and avoid copy
// use mbsrtowcs which is available, first copy first nwc elements of src
size_t mbsnrtowcs( wchar_t *__restrict__ dst, const char **__restrict__ src,
size_t nmc, size_t len, mbstate_t *__restrict__ ps )
{
char* local_src = new char[nmc+1];
char* nmcsrc = local_src;
strncpy( nmcsrc, *src, nmc );
nmcsrc[nmc] = '\0';
const size_t result = mbsrtowcs( dst, const_cast<const char **>(&nmcsrc), len, ps );
// propagate error
if( nmcsrc == NULL )
*src = NULL;
delete[] local_src;
return result;
}
// FIXME: use wcrtomb and avoid copy
// use wcsrtombs which is available, first copy first nwc elements of src
size_t wcsnrtombs( char *__restrict__ dst, const wchar_t **__restrict__ src,
size_t nwc, size_t len, mbstate_t *__restrict__ ps )
{
wchar_t* local_src = new wchar_t[nwc];
wchar_t* nwcsrc = local_src;
wcsncpy(nwcsrc, *src, nwc);
nwcsrc[nwc] = '\0';
const size_t result = wcsrtombs( dst, const_cast<const wchar_t **>(&nwcsrc), len, ps );
// propogate error
if( nwcsrc == NULL )
*src = NULL;
delete[] nwcsrc;
return result;
}

View File

@ -12,7 +12,9 @@
#include "vector" #include "vector"
#include "future" #include "future"
#include <sys/types.h> #include <sys/types.h>
#if !_WIN32
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif // _WIN32
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD