aboutsummaryrefslogtreecommitdiff
path: root/system/lib/libcxx
diff options
context:
space:
mode:
Diffstat (limited to 'system/lib/libcxx')
-rw-r--r--system/lib/libcxx/CREDITS.TXT24
-rw-r--r--system/lib/libcxx/debug.cpp20
-rw-r--r--system/lib/libcxx/exception.cpp9
-rw-r--r--system/lib/libcxx/hash.cpp6
-rw-r--r--system/lib/libcxx/iostream.cpp8
-rw-r--r--system/lib/libcxx/locale.cpp133
-rw-r--r--system/lib/libcxx/readme.txt2
-rw-r--r--system/lib/libcxx/stdexcept.cpp2
-rw-r--r--system/lib/libcxx/string.cpp823
-rw-r--r--system/lib/libcxx/support/win32/locale_win32.cpp6
-rw-r--r--system/lib/libcxx/support/win32/support.cpp181
-rw-r--r--system/lib/libcxx/symbols265
-rw-r--r--system/lib/libcxx/system_error.cpp3
-rw-r--r--system/lib/libcxx/thread.cpp19
-rw-r--r--system/lib/libcxx/typeinfo.cpp14
15 files changed, 663 insertions, 852 deletions
diff --git a/system/lib/libcxx/CREDITS.TXT b/system/lib/libcxx/CREDITS.TXT
index 52948510..5e4d14ec 100644
--- a/system/lib/libcxx/CREDITS.TXT
+++ b/system/lib/libcxx/CREDITS.TXT
@@ -33,6 +33,14 @@ E: mclow.lists@gmail.com
E: marshall@idio.com
D: Minor patches and bug fixes.
+N: Bill Fisher
+E: william.w.fisher@gmail.com
+D: Regex bug fixes.
+
+N: Matthew Dempsky
+E: matthew@dempsky.org
+D: Minor patches and bug fixes.
+
N: Google Inc.
D: Copyright owner and contributor of the CityHash algorithm
@@ -48,6 +56,10 @@ N: Argyrios Kyrtzidis
E: kyrtzidis@apple.com
D: Bug fixes.
+N: Bruce Mitchener, Jr.
+E: bruce.mitchener@gmail.com
+D: Emscripten-related changes.
+
N: Michel Morin
E: mimomorin@gmail.com
D: Minor patches to is_convertible.
@@ -74,6 +86,14 @@ D: Implemented Cityhash as the string hash function on 64-bit machines
N: Richard Smith
D: Minor patches.
+N: Joerg Sonnenberger
+E: joerg@NetBSD.org
+D: NetBSD port.
+
+N: Stephan Tolksdorf
+E: st@quanttec.com
+D: Minor <atomic> fix
+
N: Michael van der Westhuizen
E: r1mikey at gmail dot com
@@ -85,6 +105,10 @@ N: Zhang Xiongpang
E: zhangxiongpang@gmail.com
D: Minor patches and bug fixes.
+N: Zhihao Yuan
+E: lichray@gmail.com
+D: Standard compatibility fixes.
+
N: Jeffrey Yasskin
E: jyasskin@gmail.com
E: jyasskin@google.com
diff --git a/system/lib/libcxx/debug.cpp b/system/lib/libcxx/debug.cpp
index 2d4b094b..c9b09b7a 100644
--- a/system/lib/libcxx/debug.cpp
+++ b/system/lib/libcxx/debug.cpp
@@ -110,8 +110,7 @@ __libcpp_db::__find_c_from_i(void* __i) const
{
RLock _(mut());
__i_node* i = __find_iterator(__i);
- _LIBCPP_ASSERT(i != nullptr, "iterator constructed in translation unit with debug mode not enabled."
- " #define _LIBCPP_DEBUG2 1 for that translation unit.");
+ _LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database.");
return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
}
@@ -144,7 +143,7 @@ __libcpp_db::__insert_c(void* __c)
if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_))
{
size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
- __c_node** cbeg = (__c_node**)calloc(nc, sizeof(void*));
+ __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(void*)));
if (cbeg == nullptr)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
@@ -169,7 +168,8 @@ __libcpp_db::__insert_c(void* __c)
}
size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p = __cbeg_[hc];
- __c_node* r = __cbeg_[hc] = (__c_node*)malloc(sizeof(__c_node));
+ __c_node* r = __cbeg_[hc] =
+ static_cast<__c_node*>(malloc(sizeof(__c_node)));
if (__cbeg_[hc] == nullptr)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
@@ -302,7 +302,7 @@ __libcpp_db::__iterator_copy(void* __i, const void* __i0)
__i_node* i = __find_iterator(__i);
__i_node* i0 = __find_iterator(__i0);
__c_node* c0 = i0 != nullptr ? i0->__c_ : nullptr;
- if (i == nullptr && c0 != nullptr)
+ if (i == nullptr && i0 != nullptr)
i = __insert_iterator(__i);
__c_node* c = i != nullptr ? i->__c_ : nullptr;
if (c != c0)
@@ -354,7 +354,7 @@ __libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const
}
bool
-__libcpp_db::__comparable(const void* __i, const void* __j) const
+__libcpp_db::__less_than_comparable(const void* __i, const void* __j) const
{
RLock _(mut());
__i_node* i = __find_iterator(__i);
@@ -408,7 +408,8 @@ __c_node::__add(__i_node* i)
size_t nc = 2*static_cast<size_t>(cap_ - beg_);
if (nc == 0)
nc = 1;
- __i_node** beg = (__i_node**)malloc(nc * sizeof(__i_node*));
+ __i_node** beg =
+ static_cast<__i_node**>(malloc(nc * sizeof(__i_node*)));
if (beg == nullptr)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
@@ -434,7 +435,7 @@ __libcpp_db::__insert_iterator(void* __i)
if (__isz_ + 1 > static_cast<size_t>(__iend_ - __ibeg_))
{
size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1);
- __i_node** ibeg = (__i_node**)calloc(nc, sizeof(void*));
+ __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(void*)));
if (ibeg == nullptr)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
@@ -459,7 +460,8 @@ __libcpp_db::__insert_iterator(void* __i)
}
size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
__i_node* p = __ibeg_[hi];
- __i_node* r = __ibeg_[hi] = (__i_node*)malloc(sizeof(__i_node));
+ __i_node* r = __ibeg_[hi] =
+ static_cast<__i_node*>(malloc(sizeof(__i_node)));
if (r == nullptr)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
diff --git a/system/lib/libcxx/exception.cpp b/system/lib/libcxx/exception.cpp
index 1d2f6b25..d3e1b292 100644
--- a/system/lib/libcxx/exception.cpp
+++ b/system/lib/libcxx/exception.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
#include <stdlib.h>
+#include <stdio.h>
#include "exception"
@@ -88,12 +89,14 @@ terminate() _NOEXCEPT
#endif // _LIBCPP_NO_EXCEPTIONS
(*get_terminate())();
// handler should not return
+ printf("terminate_handler unexpectedly returned\n");
::abort ();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
// handler should not throw exception
+ printf("terminate_handler unexpectedly threw an exception\n");
::abort ();
}
#endif // _LIBCPP_NO_EXCEPTIONS
@@ -109,6 +112,7 @@ bool uncaught_exception() _NOEXCEPT
return __cxa_uncaught_exception();
#else // __APPLE__
#warning uncaught_exception not yet implemented
+ printf("uncaught_exception not yet implemented\n");
::abort();
#endif // __APPLE__
}
@@ -146,6 +150,7 @@ exception_ptr::~exception_ptr() _NOEXCEPT
__cxa_decrement_exception_refcount(__ptr_);
#else
#warning exception_ptr not yet implemented
+ printf("exception_ptr not yet implemented\n");
::abort();
#endif // __APPLE__
}
@@ -157,6 +162,7 @@ exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT
__cxa_increment_exception_refcount(__ptr_);
#else
#warning exception_ptr not yet implemented
+ printf("exception_ptr not yet implemented\n");
::abort();
#endif // __APPLE__
}
@@ -173,6 +179,7 @@ exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT
return *this;
#else // __APPLE__
#warning exception_ptr not yet implemented
+ printf("exception_ptr not yet implemented\n");
::abort();
#endif // __APPLE__
}
@@ -207,6 +214,7 @@ exception_ptr current_exception() _NOEXCEPT
return ptr;
#else // __APPLE__
#warning exception_ptr not yet implemented
+ printf("exception_ptr not yet implemented\n");
::abort();
#endif // __APPLE__
}
@@ -220,6 +228,7 @@ void rethrow_exception(exception_ptr p)
terminate();
#else // __APPLE__
#warning exception_ptr not yet implemented
+ printf("exception_ptr not yet implemented\n");
::abort();
#endif // __APPLE__
}
diff --git a/system/lib/libcxx/hash.cpp b/system/lib/libcxx/hash.cpp
index a0135002..388ab2eb 100644
--- a/system/lib/libcxx/hash.cpp
+++ b/system/lib/libcxx/hash.cpp
@@ -12,7 +12,9 @@
#include "stdexcept"
#include "type_traits"
+#ifdef __clang__
#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
+#endif
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -155,6 +157,8 @@ __check_for_overflow(size_t N)
#ifndef _LIBCPP_NO_EXCEPTIONS
if (N > 0xFFFFFFFB)
throw overflow_error("__next_prime overflow");
+#else
+ (void)N;
#endif
}
@@ -166,6 +170,8 @@ __check_for_overflow(size_t N)
#ifndef _LIBCPP_NO_EXCEPTIONS
if (N > 0xFFFFFFFFFFFFFFC5ull)
throw overflow_error("__next_prime overflow");
+#else
+ (void)N;
#endif
}
diff --git a/system/lib/libcxx/iostream.cpp b/system/lib/libcxx/iostream.cpp
index 7fc71df4..f413681f 100644
--- a/system/lib/libcxx/iostream.cpp
+++ b/system/lib/libcxx/iostream.cpp
@@ -54,13 +54,13 @@ ios_base::Init::Init()
ios_base::Init::~Init()
{
- ostream* cout_ptr = (ostream*)cout;
- ostream* clog_ptr = (ostream*)clog;
+ ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
+ ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
cout_ptr->flush();
clog_ptr->flush();
- wostream* wcout_ptr = (wostream*)wcout;
- wostream* wclog_ptr = (wostream*)wclog;
+ wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
+ wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
wcout_ptr->flush();
wclog_ptr->flush();
}
diff --git a/system/lib/libcxx/locale.cpp b/system/lib/libcxx/locale.cpp
index d9bc6f9a..d95d0c9c 100644
--- a/system/lib/libcxx/locale.cpp
+++ b/system/lib/libcxx/locale.cpp
@@ -18,19 +18,21 @@
#include "codecvt"
#include "vector"
#include "algorithm"
-#include "algorithm"
#include "typeinfo"
-#include "type_traits"
+#ifndef _LIBCPP_NO_EXCEPTIONS
+# include "type_traits"
+#endif
#include "clocale"
#include "cstring"
#include "cwctype"
#include "__sso_allocator"
-#ifdef _WIN32
+#ifdef _LIBCPP_MSVCRT
#include <support/win32/locale_win32.h>
-#else // _WIN32
+#else // _LIBCPP_MSVCRT
#include <langinfo.h>
-#endif // _!WIN32
+#endif // !_LIBCPP_MSVCRT
#include <stdlib.h>
+#include <stdio.h>
// On Linux, wint_t and wchar_t have different signed-ness, and this causes
// lots of noise in the build log, but no bugs that I know of.
@@ -230,8 +232,10 @@ locale::__imp::__imp(const string& name, size_t refs)
// NOTE avoid the `base class should be explicitly initialized in the
// copy constructor` warning emitted by GCC
+#if defined(__clang__) || _GNUC_VER >= 406
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wextra"
+#endif
locale::__imp::__imp(const __imp& other)
: facets_(max<size_t>(N, other.facets_.size())),
@@ -243,7 +247,9 @@ locale::__imp::__imp(const __imp& other)
facets_[i]->__add_shared();
}
+#if defined(__clang__) || _GNUC_VER >= 406
#pragma GCC diagnostic pop
+#endif
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
: facets_(N),
@@ -786,7 +792,7 @@ ctype<wchar_t>::do_toupper(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
-#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
#else
return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
@@ -799,7 +805,7 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
-#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
*low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
: *low;
#else
@@ -813,7 +819,7 @@ ctype<wchar_t>::do_tolower(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
-#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
#else
return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
@@ -826,7 +832,7 @@ ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
-#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
*low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
: *low;
#else
@@ -893,9 +899,11 @@ ctype<char>::do_toupper(char_type c) const
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
+#elif defined(__NetBSD__)
+ return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
return isascii(c) ?
- static_cast<char>(__classic_upper_table()[static_cast<size_t>(c)]) : c;
+ static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
#else
return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
#endif
@@ -908,6 +916,8 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
+#elif defined(__NetBSD__)
+ *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
*low = isascii(*low) ?
static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
@@ -923,7 +933,9 @@ ctype<char>::do_tolower(char_type c) const
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
-#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+#elif defined(__NetBSD__)
+ return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
return isascii(c) ?
static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
#else
@@ -937,6 +949,8 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
+#elif defined(__NetBSD__)
+ *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
*low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
#else
@@ -989,11 +1003,13 @@ ctype<char>::classic_table() _NOEXCEPT
{
#if defined(__APPLE__) || defined(__FreeBSD__)
return _DefaultRuneLocale.__runetype;
+#elif defined(__NetBSD__)
+ return _C_ctype_tab_ + 1;
#elif defined(__GLIBC__)
return __cloc()->__ctype_b;
#elif __sun__
return __ctype_mask;
-#elif defined(_WIN32)
+#elif defined(_LIBCPP_MSVCRT)
return _ctype+1; // internal ctype mask table defined in msvcrt.dll
// This is assumed to be safe, which is a nonsense assumption because we're
// going to end up dereferencing it later...
@@ -1003,6 +1019,7 @@ ctype<char>::classic_table() _NOEXCEPT
// Platform not supported: abort so the person doing the port knows what to
// fix
# warning ctype<char>::classic_table() is not implemented
+ printf("ctype<char>::classic_table() is not implemented\n");
abort();
return NULL;
#endif
@@ -1020,9 +1037,20 @@ ctype<char>::__classic_upper_table() _NOEXCEPT
{
return __cloc()->__ctype_toupper;
}
-#endif // __GLIBC__
+#elif __NetBSD__
+const short*
+ctype<char>::__classic_lower_table() _NOEXCEPT
+{
+ return _C_tolower_tab_ + 1;
+}
-#if defined(EMSCRIPTEN)
+const short*
+ctype<char>::__classic_upper_table() _NOEXCEPT
+{
+ return _C_toupper_tab_ + 1;
+}
+
+#elif defined(EMSCRIPTEN)
const int*
ctype<char>::__classic_lower_table() _NOEXCEPT
{
@@ -1034,7 +1062,7 @@ ctype<char>::__classic_upper_table() _NOEXCEPT
{
return *__ctype_toupper_loc();
}
-#endif // EMSCRIPTEN
+#endif // __GLIBC__ || EMSCRIPTEN || __NETBSD__
// template <> class ctype_byname<char>
@@ -1068,28 +1096,28 @@ ctype_byname<char>::~ctype_byname()
char
ctype_byname<char>::do_toupper(char_type c) const
{
- return static_cast<char>(toupper_l(c, __l));
+ return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
}
const char*
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = static_cast<char>(toupper_l(*low, __l));
+ *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
return low;
}
char
ctype_byname<char>::do_tolower(char_type c) const
{
- return static_cast<char>(tolower_l(c, __l));
+ return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
}
const char*
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
- *low = static_cast<char>(tolower_l(*low, __l));
+ *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
return low;
}
@@ -1372,7 +1400,7 @@ locale::id codecvt<wchar_t, char, mbstate_t>::id;
codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
: locale::facet(refs),
- __l(0)
+ __l(_LIBCPP_GET_C_LOCALE)
{
}
@@ -1389,7 +1417,7 @@ codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
codecvt<wchar_t, char, mbstate_t>::~codecvt()
{
- if (__l != 0)
+ if (__l != _LIBCPP_GET_C_LOCALE)
freelocale(__l);
}
@@ -1407,7 +1435,7 @@ codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
to_nxt = to;
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
{
- // save state in case needed to reover to_nxt on error
+ // save state in case it is needed to recover to_nxt on error
mbstate_t save_state = st;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
size_t n = wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
@@ -1476,7 +1504,7 @@ codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
to_nxt = to;
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
{
- // save state in case needed to reover to_nxt on error
+ // save state in case it is needed to recover to_nxt on error
mbstate_t save_state = st;
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
size_t n = mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
@@ -3176,14 +3204,25 @@ __codecvt_utf8<wchar_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
+#if _WIN32
+ const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
+ const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
+ const uint16_t* _frm_nxt = _frm;
+#else
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
+#endif
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
+#if _WIN32
+ result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
+ _Maxcode_, _Mode_);
+#else
result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
+#endif
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
@@ -3197,11 +3236,19 @@ __codecvt_utf8<wchar_t>::do_in(state_type&,
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
+#if _WIN32
+ uint16_t* _to = reinterpret_cast<uint16_t*>(to);
+ uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
+ uint16_t* _to_nxt = _to;
+ result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
+ _Maxcode_, _Mode_);
+#else
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
+#endif
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
@@ -5315,7 +5362,7 @@ __time_put::__time_put(const string& nm)
__time_put::~__time_put()
{
- if (__loc_)
+ if (__loc_ != _LIBCPP_GET_C_LOCALE)
freelocale(__loc_);
}
@@ -5801,19 +5848,19 @@ moneypunct_byname<char, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
-#ifdef _WIN32
+#ifdef _LIBCPP_MSVCRT
if (lc->p_sign_posn == 0)
-#else // _WIN32
+#else // _LIBCPP_MSVCRT
if (lc->int_p_sign_posn == 0)
-#endif //_WIN32
+#endif // !_LIBCPP_MSVCRT
__positive_sign_ = "()";
else
__positive_sign_ = lc->positive_sign;
-#ifdef _WIN32
+#ifdef _LIBCPP_MSVCRT
if(lc->n_sign_posn == 0)
-#else // _WIN32
+#else // _LIBCPP_MSVCRT
if (lc->int_n_sign_posn == 0)
-#endif // _WIN32
+#endif // !_LIBCPP_MSVCRT
__negative_sign_ = "()";
else
__negative_sign_ = lc->negative_sign;
@@ -5821,19 +5868,19 @@ moneypunct_byname<char, true>::init(const char* nm)
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
-#ifdef _WIN32
+#ifdef _LIBCPP_MSVCRT
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
-#else
+#else // _LIBCPP_MSVCRT
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->int_p_cs_precedes, lc->int_p_sep_by_space,
lc->int_p_sign_posn, ' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->int_n_cs_precedes, lc->int_n_sep_by_space,
lc->int_n_sign_posn, ' ');
-#endif // _WIN32
+#endif // !_LIBCPP_MSVCRT
}
template<>
@@ -5960,11 +6007,11 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
-#ifdef _WIN32
+#ifdef _LIBCPP_MSVCRT
if (lc->p_sign_posn == 0)
-#else // _WIN32
+#else // _LIBCPP_MSVCRT
if (lc->int_p_sign_posn == 0)
-#endif // _WIN32
+#endif // !_LIBCPP_MSVCRT
__positive_sign_ = L"()";
else
{
@@ -5980,11 +6027,11 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe);
}
-#ifdef _WIN32
+#ifdef _LIBCPP_MSVCRT
if (lc->n_sign_posn == 0)
-#else // _WIN32
+#else // _LIBCPP_MSVCRT
if (lc->int_n_sign_posn == 0)
-#endif // _WIN32
+#endif // !_LIBCPP_MSVCRT
__negative_sign_ = L"()";
else
{
@@ -6004,19 +6051,19 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
-#ifdef _WIN32
+#ifdef _LIBCPP_MSVCRT
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
-#else // _WIN32
+#else // _LIBCPP_MSVCRT
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->int_p_cs_precedes, lc->int_p_sep_by_space,
lc->int_p_sign_posn, L' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->int_n_cs_precedes, lc->int_n_sep_by_space,
lc->int_n_sign_posn, L' ');
-#endif // _WIN32
+#endif // !_LIBCPP_MSVCRT
}
void __do_nothing(void*) {}
@@ -6025,6 +6072,8 @@ void __throw_runtime_error(const char* msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw runtime_error(msg);
+#else
+ (void)msg;
#endif
}
diff --git a/system/lib/libcxx/readme.txt b/system/lib/libcxx/readme.txt
index 97d8db86..7687e5b2 100644
--- a/system/lib/libcxx/readme.txt
+++ b/system/lib/libcxx/readme.txt
@@ -1 +1 @@
-These files are from libc++, svn revision 178253, Mar 29 2013
+These files are from libc++, svn revision 187959, 2013-08-08.
diff --git a/system/lib/libcxx/stdexcept.cpp b/system/lib/libcxx/stdexcept.cpp
index 0c4e8323..8d25f3ee 100644
--- a/system/lib/libcxx/stdexcept.cpp
+++ b/system/lib/libcxx/stdexcept.cpp
@@ -61,7 +61,7 @@ __libcpp_nmstr::__libcpp_nmstr(const char* msg)
c[0] = c[1] = len;
str_ += offset;
count() = 0;
- std::strcpy(const_cast<char*>(c_str()), msg);
+ std::memcpy(const_cast<char*>(c_str()), msg, len + 1);
}
inline
diff --git a/system/lib/libcxx/string.cpp b/system/lib/libcxx/string.cpp
index c71af4fe..5a869116 100644
--- a/system/lib/libcxx/string.cpp
+++ b/system/lib/libcxx/string.cpp
@@ -11,9 +11,12 @@
#include "cstdlib"
#include "cwchar"
#include "cerrno"
-#ifdef _WIN32
+#include "limits"
+#include "stdexcept"
+#ifdef _LIBCPP_MSVCRT
#include "support/win32/support.h"
-#endif // _WIN32
+#endif // _LIBCPP_MSVCRT
+#include <stdio.h>
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -26,662 +29,500 @@ template
string
operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
-int
-stoi(const string& str, size_t* idx, int base)
+namespace
+{
+
+template<typename T>
+inline
+void throw_helper( const string& msg )
+{
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ throw T( msg );
+#else
+ printf("%s\n", msg.c_str());
+ abort();
+#endif
+}
+
+inline
+void throw_from_string_out_of_range( const string& func )
+{
+ throw_helper<out_of_range>(func + ": out of range");
+}
+
+inline
+void throw_from_string_invalid_arg( const string& func )
+{
+ throw_helper<invalid_argument>(func + ": no conversion");
+}
+
+// as_integer
+
+template<typename V, typename S, typename F>
+inline
+V
+as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
{
- char* ptr;
- const char* const p = str.c_str();
+ typename S::value_type* ptr;
+ const typename S::value_type* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
- long r = strtol(p, &ptr, base);
+ V r = f(p, &ptr, base);
swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- if (errno_save == ERANGE || r < numeric_limits<int>::min() ||
- numeric_limits<int>::max() < r)
- throw out_of_range("stoi: out of range");
+ if (errno_save == ERANGE)
+ throw_from_string_out_of_range(func);
if (ptr == p)
- throw invalid_argument("stoi: no conversion");
-#endif // _LIBCPP_NO_EXCEPTIONS
+ throw_from_string_invalid_arg(func);
if (idx)
*idx = static_cast<size_t>(ptr - p);
+ return r;
+}
+
+template<typename V, typename S>
+inline
+V
+as_integer(const string& func, const S& s, size_t* idx, int base);
+
+// string
+template<>
+inline
+int
+as_integer(const string& func, const string& s, size_t* idx, int base )
+{
+ // Use long as no Stantard string to integer exists.
+ long r = as_integer_helper<long>( func, s, idx, base, strtol );
+ if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
+ throw_from_string_out_of_range(func);
return static_cast<int>(r);
}
+template<>
+inline
+long
+as_integer(const string& func, const string& s, size_t* idx, int base )
+{
+ return as_integer_helper<long>( func, s, idx, base, strtol );
+}
+
+template<>
+inline
+unsigned long
+as_integer( const string& func, const string& s, size_t* idx, int base )
+{
+ return as_integer_helper<unsigned long>( func, s, idx, base, strtoul );
+}
+
+template<>
+inline
+long long
+as_integer( const string& func, const string& s, size_t* idx, int base )
+{
+ return as_integer_helper<long long>( func, s, idx, base, strtoll );
+}
+
+template<>
+inline
+unsigned long long
+as_integer( const string& func, const string& s, size_t* idx, int base )
+{
+ return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
+}
+
+// wstring
+template<>
+inline
int
-stoi(const wstring& str, size_t* idx, int base)
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
{
- wchar_t* ptr;
- const wchar_t* const p = str.c_str();
- typename remove_reference<decltype(errno)>::type errno_save = errno;
- errno = 0;
- long r = wcstol(p, &ptr, base);
- swap(errno, errno_save);
-#ifndef _LIBCPP_NO_EXCEPTIONS
- if (errno_save == ERANGE || r < numeric_limits<int>::min() ||
- numeric_limits<int>::max() < r)
- throw out_of_range("stoi: out of range");
- if (ptr == p)
- throw invalid_argument("stoi: no conversion");
-#endif // _LIBCPP_NO_EXCEPTIONS
- if (idx)
- *idx = static_cast<size_t>(ptr - p);
+ // Use long as no Stantard string to integer exists.
+ long r = as_integer_helper<long>( func, s, idx, base, wcstol );
+ if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
+ throw_from_string_out_of_range(func);
return static_cast<int>(r);
}
+template<>
+inline
long
-stol(const string& str, size_t* idx, int base)
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
+{
+ return as_integer_helper<long>( func, s, idx, base, wcstol );
+}
+
+template<>
+inline
+unsigned long
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
+{
+ return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul );
+}
+
+template<>
+inline
+long long
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
+{
+ return as_integer_helper<long long>( func, s, idx, base, wcstoll );
+}
+
+template<>
+inline
+unsigned long long
+as_integer( const string& func, const wstring& s, size_t* idx, int base )
+{
+ return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
+}
+
+// as_float
+
+template<typename V, typename S, typename F>
+inline
+V
+as_float_helper(const string& func, const S& str, size_t* idx, F f )
{
- char* ptr;
- const char* const p = str.c_str();
+ typename S::value_type* ptr;
+ const typename S::value_type* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
- long r = strtol(p, &ptr, base);
+ V r = f(p, &ptr);
swap(errno, errno_save);