aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chrono.cpp4
-rw-r--r--src/debug.cpp9
-rw-r--r--src/exception.cpp8
-rw-r--r--src/hash.cpp4
-rw-r--r--src/iostream.cpp14
-rw-r--r--src/locale.cpp161
-rw-r--r--src/memory.cpp10
-rw-r--r--src/new.cpp2
-rw-r--r--src/stdexcept.cpp2
-rw-r--r--src/string.cpp2
-rw-r--r--src/strstream.cpp2
-rw-r--r--src/system_error.cpp3
-rw-r--r--src/thread.cpp14
-rw-r--r--src/typeinfo.cpp18
14 files changed, 161 insertions, 92 deletions
diff --git a/src/chrono.cpp b/src/chrono.cpp
index 1ce2e2807a37..15a6f466a77d 100644
--- a/src/chrono.cpp
+++ b/src/chrono.cpp
@@ -9,7 +9,7 @@
#include "chrono"
#include <sys/time.h> //for gettimeofday and timeval
-#if __APPLE__
+#ifdef __APPLE__
#include <mach/mach_time.h> // mach_absolute_time, mach_timebase_info_data_t
#else /* !__APPLE__ */
#include <cerrno> // errno
@@ -50,7 +50,7 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
const bool steady_clock::is_steady;
-#if __APPLE__
+#ifdef __APPLE__
// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
// nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom
// are run time constants supplied by the OS. This clock has no relationship
diff --git a/src/debug.cpp b/src/debug.cpp
index f3a0262d1d5e..06040af902af 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -17,7 +17,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-_LIBCPP_VISIBLE
+_LIBCPP_FUNC_VIS
__libcpp_db*
__get_db()
{
@@ -25,7 +25,7 @@ __get_db()
return &db;
}
-_LIBCPP_VISIBLE
+_LIBCPP_FUNC_VIS
const __libcpp_db*
__get_const_db()
{
@@ -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;
}
@@ -302,7 +301,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)
diff --git a/src/exception.cpp b/src/exception.cpp
index 0cd182b716cb..1d2f6b25979e 100644
--- a/src/exception.cpp
+++ b/src/exception.cpp
@@ -14,7 +14,7 @@
#define __has_include(inc) 0
#endif
-#if __APPLE__
+#ifdef __APPLE__
#include <cxxabi.h>
using namespace __cxxabiv1;
@@ -77,6 +77,7 @@ get_terminate() _NOEXCEPT
return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
}
+#ifndef EMSCRIPTEN // We provide this in JS
_LIBCPP_NORETURN
void
terminate() _NOEXCEPT
@@ -97,12 +98,13 @@ terminate() _NOEXCEPT
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
+#endif // !EMSCRIPTEN
#endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION)
-#if !defined(LIBCXXRT) && !defined(__GLIBCXX__)
+#if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(EMSCRIPTEN)
bool uncaught_exception() _NOEXCEPT
{
-#if __APPLE__ || defined(_LIBCPPABI_VERSION)
+#if defined(__APPLE__) || defined(_LIBCPPABI_VERSION)
// on Darwin, there is a helper function so __cxa_get_globals is private
return __cxa_uncaught_exception();
#else // __APPLE__
diff --git a/src/hash.cpp b/src/hash.cpp
index a013500218e0..75e773a3a647 100644
--- a/src/hash.cpp
+++ b/src/hash.cpp
@@ -155,6 +155,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 +168,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/src/iostream.cpp b/src/iostream.cpp
index f5b959b4bb99..7fc71df44a45 100644
--- a/src/iostream.cpp
+++ b/src/iostream.cpp
@@ -13,6 +13,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+static mbstate_t state_types[6] = {};
+
_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)];
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
@@ -33,17 +35,17 @@ ios_base::Init __start_std_streams;
ios_base::Init::Init()
{
- istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin) );
- ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout));
- ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr));
+ istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, state_types+0) );
+ ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, state_types+1));
+ ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, state_types+2));
::new(clog) ostream(cerr_ptr->rdbuf());
cin_ptr->tie(cout_ptr);
_VSTD::unitbuf(*cerr_ptr);
cerr_ptr->tie(cout_ptr);
- wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin) );
- wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout));
- wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr));
+ wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, state_types+3) );
+ wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, state_types+4));
+ wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, state_types+5));
::new(wclog) wostream(wcerr_ptr->rdbuf());
wcin_ptr->tie(wcout_ptr);
_VSTD::unitbuf(*wcerr_ptr);
diff --git a/src/locale.cpp b/src/locale.cpp
index 53a8a4cc1f08..49c1cf22301f 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -25,13 +25,17 @@
#include "cstring"
#include "cwctype"
#include "__sso_allocator"
-#if _WIN32
+#ifdef _WIN32
#include <support/win32/locale_win32.h>
#else // _WIN32
#include <langinfo.h>
#endif // _!WIN32
#include <stdlib.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.
+#pragma clang diagnostic ignored "-Wsign-conversion"
+
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef __cloc_defined
@@ -782,7 +786,7 @@ ctype<wchar_t>::do_toupper(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
#else
return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
@@ -795,7 +799,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__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
*low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
: *low;
#else
@@ -809,7 +813,7 @@ ctype<wchar_t>::do_tolower(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
-#elif defined(__GLIBC__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
#else
return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
@@ -822,7 +826,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__)
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
*low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
: *low;
#else
@@ -889,8 +893,9 @@ 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(__GLIBC__)
- return isascii(c) ? __classic_upper_table()[static_cast<size_t>(c)] : c;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ return isascii(c) ?
+ static_cast<char>(__classic_upper_table()[static_cast<size_t>(c)]) : c;
#else
return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
#endif
@@ -903,8 +908,9 @@ 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(__GLIBC__)
- *low = isascii(*low) ? __classic_upper_table()[static_cast<size_t>(*low)] : *low;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ *low = isascii(*low) ?
+ static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
#else
*low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;
#endif
@@ -917,8 +923,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__)
- return isascii(c) ? __classic_lower_table()[static_cast<size_t>(c)] : c;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ return isascii(c) ?
+ static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
#else
return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
#endif
@@ -930,8 +937,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(__GLIBC__)
- *low = isascii(*low) ? __classic_lower_table()[static_cast<size_t>(*low)] : *low;
+#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
+ *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
#else
*low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
#endif
@@ -971,6 +978,12 @@ ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault,
return low;
}
+#ifdef EMSCRIPTEN
+extern "C" const unsigned short ** __ctype_b_loc();
+extern "C" const int ** __ctype_tolower_loc();
+extern "C" const int ** __ctype_toupper_loc();
+#endif
+
const ctype<char>::mask*
ctype<char>::classic_table() _NOEXCEPT
{
@@ -980,10 +993,12 @@ ctype<char>::classic_table() _NOEXCEPT
return __cloc()->__ctype_b;
#elif __sun__
return __ctype_mask;
-#elif _WIN32
+#elif defined(_WIN32)
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...
+#elif defined(EMSCRIPTEN)
+ return *__ctype_b_loc();
#else
// Platform not supported: abort so the person doing the port knows what to
// fix
@@ -1007,6 +1022,20 @@ ctype<char>::__classic_upper_table() _NOEXCEPT
}
#endif // __GLIBC__
+#if defined(EMSCRIPTEN)
+const int*
+ctype<char>::__classic_lower_table() _NOEXCEPT
+{
+ return *__ctype_tolower_loc();
+}
+
+const int*
+ctype<char>::__classic_upper_table() _NOEXCEPT
+{
+ return *__ctype_toupper_loc();
+}
+#endif // EMSCRIPTEN
+
// template <> class ctype_byname<char>
ctype_byname<char>::ctype_byname(const char* name, size_t refs)
@@ -1100,16 +1129,17 @@ ctype_byname<wchar_t>::do_is(mask m, char_type c) const
return static_cast<bool>(iswctype_l(c, m, __l));
#else
bool result = false;
- if (m & space) result |= (iswspace_l(c, __l) != 0);
- if (m & print) result |= (iswprint_l(c, __l) != 0);
- if (m & cntrl) result |= (iswcntrl_l(c, __l) != 0);
- if (m & upper) result |= (iswupper_l(c, __l) != 0);
- if (m & lower) result |= (iswlower_l(c, __l) != 0);
- if (m & alpha) result |= (iswalpha_l(c, __l) != 0);
- if (m & digit) result |= (iswdigit_l(c, __l) != 0);
- if (m & punct) result |= (iswpunct_l(c, __l) != 0);
- if (m & xdigit) result |= (iswxdigit_l(c, __l) != 0);
- if (m & blank) result |= (iswblank_l(c, __l) != 0);
+ wint_t ch = static_cast<wint_t>(c);
+ if (m & space) result |= (iswspace_l(ch, __l) != 0);
+ if (m & print) result |= (iswprint_l(ch, __l) != 0);
+ if (m & cntrl) result |= (iswcntrl_l(ch, __l) != 0);
+ if (m & upper) result |= (iswupper_l(ch, __l) != 0);
+ if (m & lower) result |= (iswlower_l(ch, __l) != 0);
+ if (m & alpha) result |= (iswalpha_l(ch, __l) != 0);
+ if (m & digit) result |= (iswdigit_l(ch, __l) != 0);
+ if (m & punct) result |= (iswpunct_l(ch, __l) != 0);
+ if (m & xdigit) result |= (iswxdigit_l(ch, __l) != 0);
+ if (m & blank) result |= (iswblank_l(ch, __l) != 0);
return result;
#endif
}
@@ -1124,23 +1154,24 @@ ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask*
else
{
*vec = 0;
- if (iswspace_l(*low, __l))
+ wint_t ch = static_cast<wint_t>(*low);
+ if (iswspace_l(ch, __l))
*vec |= space;
- if (iswprint_l(*low, __l))
+ if (iswprint_l(ch, __l))
*vec |= print;
- if (iswcntrl_l(*low, __l))
+ if (iswcntrl_l(ch, __l))
*vec |= cntrl;
- if (iswupper_l(*low, __l))
+ if (iswupper_l(ch, __l))
*vec |= upper;
- if (iswlower_l(*low, __l))
+ if (iswlower_l(ch, __l))
*vec |= lower;
- if (iswalpha_l(*low, __l))
+ if (iswalpha_l(ch, __l))
*vec |= alpha;
- if (iswdigit_l(*low, __l))
+ if (iswdigit_l(ch, __l))
*vec |= digit;
- if (iswpunct_l(*low, __l))
+ if (iswpunct_l(ch, __l))
*vec |= punct;
- if (iswxdigit_l(*low, __l))
+ if (iswxdigit_l(ch, __l))
*vec |= xdigit;
}
}
@@ -1156,16 +1187,17 @@ ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type*
if (iswctype_l(*low, m, __l))
break;
#else
- if (m & space && iswspace_l(*low, __l)) break;
- if (m & print && iswprint_l(*low, __l)) break;
- if (m & cntrl && iswcntrl_l(*low, __l)) break;
- if (m & upper && iswupper_l(*low, __l)) break;
- if (m & lower && iswlower_l(*low, __l)) break;
- if (m & alpha && iswalpha_l(*low, __l)) break;
- if (m & digit && iswdigit_l(*low, __l)) break;
- if (m & punct && iswpunct_l(*low, __l)) break;
- if (m & xdigit && iswxdigit_l(*low, __l)) break;
- if (m & blank && iswblank_l(*low, __l)) break;
+ wint_t ch = static_cast<wint_t>(*low);
+ if (m & space && iswspace_l(ch, __l)) break;
+ if (m & print && iswprint_l(ch, __l)) break;
+ if (m & cntrl && iswcntrl_l(ch, __l)) break;
+ if (m & upper && iswupper_l(ch, __l)) break;
+ if (m & lower && iswlower_l(ch, __l)) break;
+ if (m & alpha && iswalpha_l(ch, __l)) break;
+ if (m & digit && iswdigit_l(ch, __l)) break;
+ if (m & punct && iswpunct_l(ch, __l)) break;
+ if (m & xdigit && iswxdigit_l(ch, __l)) break;
+ if (m & blank && iswblank_l(ch, __l)) break;
#endif
}
return low;
@@ -1180,16 +1212,17 @@ ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type
if (!iswctype_l(*low, m, __l))
break;
#else
- if (m & space && iswspace_l(*low, __l)) continue;
- if (m & print && iswprint_l(*low, __l)) continue;
- if (m & cntrl && iswcntrl_l(*low, __l)) continue;
- if (m & upper && iswupper_l(*low, __l)) continue;
- if (m & lower && iswlower_l(*low, __l)) continue;
- if (m & alpha && iswalpha_l(*low, __l)) continue;
- if (m & digit && iswdigit_l(*low, __l)) continue;
- if (m & punct && iswpunct_l(*low, __l)) continue;
- if (m & xdigit && iswxdigit_l(*low, __l)) continue;
- if (m & blank && iswblank_l(*low, __l)) continue;
+ wint_t ch = static_cast<wint_t>(*low);
+ if (m & space && iswspace_l(ch, __l)) continue;
+ if (m & print && iswprint_l(ch, __l)) continue;
+ if (m & cntrl && iswcntrl_l(ch, __l)) continue;
+ if (m & upper && iswupper_l(ch, __l)) continue;
+ if (m & lower && iswlower_l(ch, __l)) continue;
+ if (m & alpha && iswalpha_l(ch, __l)) continue;
+ if (m & digit && iswdigit_l(ch, __l)) continue;
+ if (m & punct && iswpunct_l(ch, __l)) continue;
+ if (m & xdigit && iswxdigit_l(ch, __l)) continue;
+ if (m & blank && iswblank_l(ch, __l)) continue;
break;
#endif
}
@@ -1374,7 +1407,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),
@@ -1443,7 +1476,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),
@@ -1589,9 +1622,9 @@ int
codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
{
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
+ return __l == 0 ? 1 : static_cast<int>( MB_CUR_MAX_L(__l));
#else
- return __l == 0 ? 1 : __mb_cur_max_l(__l);
+ return __l == 0 ? 1 : static_cast<int>(__mb_cur_max_l(__l));
#endif
}
@@ -5768,7 +5801,7 @@ moneypunct_byname<char, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
-#if _WIN32
+#ifdef _WIN32
if (lc->p_sign_posn == 0)
#else // _WIN32
if (lc->int_p_sign_posn == 0)
@@ -5776,7 +5809,7 @@ moneypunct_byname<char, true>::init(const char* nm)
__positive_sign_ = "()";
else
__positive_sign_ = lc->positive_sign;
-#if _WIN32
+#ifdef _WIN32
if(lc->n_sign_posn == 0)
#else // _WIN32
if (lc->int_n_sign_posn == 0)
@@ -5788,7 +5821,7 @@ 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_;
-#if _WIN32
+#ifdef _WIN32
__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,
@@ -5927,7 +5960,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
-#if _WIN32
+#ifdef _WIN32
if (lc->p_sign_posn == 0)
#else // _WIN32
if (lc->int_p_sign_posn == 0)
@@ -5947,7 +5980,7 @@ moneypunct_byname<wchar_t, true>::init(const char* nm)
wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe);
}
-#if _WIN32
+#ifdef _WIN32
if (lc->n_sign_posn == 0)
#else // _WIN32
if (lc->int_n_sign_posn == 0)
@@ -5971,7 +6004,7 @@ 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_;
-#if _WIN32
+#ifdef _WIN32
__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,
@@ -5992,6 +6025,8 @@ void __throw_runtime_error(const char* msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw runtime_error(msg);
+#else
+ (void)msg;
#endif
}
diff --git a/src/memory.cpp b/src/memory.cpp
index 14084a5206aa..98bcc864eeb0 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -122,7 +122,15 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
#if __has_feature(cxx_atomic)
static const std::size_t __sp_mut_count = 16;
-static mutex mut_back[__sp_mut_count];
+static pthread_mutex_t mut_back_imp[__sp_mut_count] =
+{
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER
+};
+
+static mutex* mut_back = reinterpret_cast<std::mutex*>(mut_back_imp);
_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
: __lx(p)
diff --git a/src/new.cpp b/src/new.cpp
index 3ad593a3c0e0..b23a516ff37f 100644
--- a/src/new.cpp
+++ b/src/new.cpp
@@ -15,7 +15,7 @@
#define __has_include(inc) 0
#endif
-#if __APPLE__
+#ifdef __APPLE__
#include <cxxabi.h>
#ifndef _LIBCPPABI_VERSION
diff --git a/src/stdexcept.cpp b/src/stdexcept.cpp
index 660ebfe27355..0c4e8323abf3 100644
--- a/src/stdexcept.cpp
+++ b/src/stdexcept.cpp
@@ -20,7 +20,7 @@
#define __has_include(inc) 0
#endif
-#if __APPLE__
+#ifdef __APPLE__
#include <cxxabi.h>
#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
#include <cxxabi.h>
diff --git a/src/string.cpp b/src/string.cpp
index 40723e74a156..c71af4feb944 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -11,7 +11,7 @@
#include "cstdlib"
#include "cwchar"
#include "cerrno"
-#if _WIN32
+#ifdef _WIN32
#include "support/win32/support.h"
#endif // _WIN32
diff --git a/src/strstream.cpp b/src/strstream.cpp
index 8cd19e6a353c..518422bd2428 100644
--- a/src/strstream.cpp
+++ b/src/strstream.cpp
@@ -158,6 +158,8 @@ strstreambuf::overflow(int_type __c)
return int_type(EOF);
streamsize old_size = (epptr() ? epptr() : egptr()) - eback();
streamsize new_size = max<streamsize>(__alsize_, 2*old_size);
+ if (new_size == 0)
+ new_size = __default_alsize;
char* buf = nullptr;
if (__palloc_)
buf = static_cast<char*>(__palloc_(static_cast<size_t>(new_size)));
diff --git a/src/system_error.cpp b/src/system_error.cpp
index 763d62c2a0b4..7376b770ecf8 100644
--- a/src/system_error.cpp
+++ b/src/system_error.cpp
@@ -195,6 +195,9 @@ __throw_system_error(int ev, const char* what_arg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw system_error(error_code(ev, system_category()), what_arg);
+#else
+ (void)ev;
+ (void)what_arg;
#endif
}
diff --git a/src/thread.cpp b/src/thread.cpp
index b2bd07e9d3ba..c6f6748f01b3 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -13,8 +13,8 @@
#include "future"
#include "limits"
#include <sys/types.h>
-#if !_WIN32
-#if !__sun__ && !__linux__
+#if !defined(_WIN32)
+#if !defined(__sun__) && !defined(__linux__)
#include <sys/sysctl.h>
#else
#include <unistd.h>
@@ -36,6 +36,8 @@ thread::join()
#ifndef _LIBCPP_NO_EXCEPTIONS
if (ec)
throw system_error(error_code(ec, system_category()), "thread::join failed");
+#else
+ (void)ec;
#endif // _LIBCPP_NO_EXCEPTIONS
__t_ = 0;
}
@@ -65,13 +67,15 @@ thread::hardware_concurrency() _NOEXCEPT
std::size_t s = sizeof(n);
sysctl(mib, 2, &n, &s, 0, 0);
return n;
-#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN)
+#elif (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && defined(_SC_NPROCESSORS_ONLN)) || defined(EMSCRIPTEN)
long result = sysconf(_SC_NPROCESSORS_ONLN);
// sysconf returns -1 if the name is invalid, the option does not exist or
// does not have a definite limit.
- if (result == -1)
+ // if sysconf returns some other negative number, we have no idea
+ // what is going on. Default to something safe.
+ if (result < 0)
return 0;
- return result;
+ return static_cast<unsigned>(result);
#else // defined(CTL_HW) && defined(HW_NCPU)
// TODO: grovel through /proc or check cpuid on x86 and similar
// instructions on other architectures.
diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp
index 6bab0771f427..60828944a1bc 100644
--- a/src/typeinfo.cpp
+++ b/src/typeinfo.cpp
@@ -12,7 +12,7 @@
#define __has_include(inc) 0
#endif
-#if __APPLE__
+#ifdef __APPLE__
#include <cxxabi.h>
#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
#include <cxxabi.h>
@@ -50,11 +50,21 @@ std::bad_typeid::what() const _NOEXCEPT
return "std::bad_typeid";
}
-#if __APPLE__
+#ifdef __APPLE__
// On Darwin, the cxa_bad_* functions cannot be in the lower level library
// because bad_cast and bad_typeid are defined in his higher level library
- void __cxxabiv1::__cxa_bad_typeid() { throw std::bad_typeid(); }
- void __cxxabiv1::__cxa_bad_cast() { throw std::bad_cast(); }
+ void __cxxabiv1::__cxa_bad_typeid()
+ {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ throw std::bad_typeid();
+#endif
+ }
+ void __cxxabiv1::__cxa_bad_cast()
+ {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ throw std::bad_cast();
+#endif
+ }
#endif
#endif // _LIBCPPABI_VERSION