summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/src
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2012-10-22 18:25:04 +0000
committerdim <dim@FreeBSD.org>2012-10-22 18:25:04 +0000
commit708d8e446e991358da23bb52ec5320440221f12f (patch)
tree3a061d75674cd5b60d9f6df45d0b8d755da3782f /contrib/libc++/src
parentb8c74d455d2690e710a0802a98a9d310995a52eb (diff)
parent13334223d751d249ccd6475b8cba36ff71ddc972 (diff)
downloadFreeBSD-src-708d8e446e991358da23bb52ec5320440221f12f.zip
FreeBSD-src-708d8e446e991358da23bb52ec5320440221f12f.tar.gz
Import libc++ trunk r165949. Among other improvements and bug fixes,
this has many visibility problems fixed, which should help with compiling certain ports that exercise C++11 mode (i.e. Firefox). Also, belatedly add the LICENSE.TXT and accompanying CREDITS.TXT files, which are referred to in all the source files. MFC after: 1 month
Diffstat (limited to 'contrib/libc++/src')
-rw-r--r--contrib/libc++/src/condition_variable.cpp20
-rw-r--r--contrib/libc++/src/debug.cpp20
-rw-r--r--contrib/libc++/src/exception.cpp27
-rw-r--r--contrib/libc++/src/future.cpp2
-rw-r--r--contrib/libc++/src/ios.cpp2
-rw-r--r--contrib/libc++/src/iostream.cpp28
-rw-r--r--contrib/libc++/src/locale.cpp45
-rw-r--r--contrib/libc++/src/memory.cpp50
-rw-r--r--contrib/libc++/src/mutex.cpp17
-rw-r--r--contrib/libc++/src/new.cpp11
-rw-r--r--contrib/libc++/src/random.cpp2
-rw-r--r--contrib/libc++/src/stdexcept.cpp15
-rw-r--r--contrib/libc++/src/support/win32/locale_win32.cpp94
-rw-r--r--contrib/libc++/src/support/win32/support.cpp70
-rw-r--r--contrib/libc++/src/thread.cpp33
-rw-r--r--contrib/libc++/src/typeinfo.cpp7
16 files changed, 203 insertions, 240 deletions
diff --git a/contrib/libc++/src/condition_variable.cpp b/contrib/libc++/src/condition_variable.cpp
index b53b836..de0f6f4 100644
--- a/contrib/libc++/src/condition_variable.cpp
+++ b/contrib/libc++/src/condition_variable.cpp
@@ -20,13 +20,13 @@ condition_variable::~condition_variable()
}
void
-condition_variable::notify_one()
+condition_variable::notify_one() _NOEXCEPT
{
pthread_cond_signal(&__cv_);
}
void
-condition_variable::notify_all()
+condition_variable::notify_all() _NOEXCEPT
{
pthread_cond_broadcast(&__cv_);
}
@@ -51,10 +51,22 @@ condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
__throw_system_error(EPERM,
"condition_variable::timed wait: mutex not locked");
nanoseconds d = tp.time_since_epoch();
+ if (d > nanoseconds(0x59682F000000E941))
+ d = nanoseconds(0x59682F000000E941);
timespec ts;
seconds s = duration_cast<seconds>(d);
- ts.tv_sec = static_cast<decltype(ts.tv_sec)>(s.count());
- ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
+ typedef decltype(ts.tv_sec) ts_sec;
+ _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
+ if (s.count() < ts_sec_max)
+ {
+ ts.tv_sec = static_cast<ts_sec>(s.count());
+ ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
+ }
+ else
+ {
+ ts.tv_sec = ts_sec_max;
+ ts.tv_nsec = giga::num - 1;
+ }
int ec = pthread_cond_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
if (ec != 0 && ec != ETIMEDOUT)
__throw_system_error(ec, "condition_variable timed_wait failed");
diff --git a/contrib/libc++/src/debug.cpp b/contrib/libc++/src/debug.cpp
index 406b247..b8af4dd 100644
--- a/contrib/libc++/src/debug.cpp
+++ b/contrib/libc++/src/debug.cpp
@@ -146,7 +146,11 @@ __libcpp_db::__insert_c(void* __c)
size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
__c_node** cbeg = (__c_node**)calloc(nc, sizeof(void*));
if (cbeg == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
+#else
+ abort();
+#endif
for (__c_node** p = __cbeg_; p != __cend_; ++p)
{
__c_node* q = *p;
@@ -167,7 +171,11 @@ __libcpp_db::__insert_c(void* __c)
__c_node* p = __cbeg_[hc];
__c_node* r = __cbeg_[hc] = (__c_node*)malloc(sizeof(__c_node));
if (__cbeg_[hc] == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
+#else
+ abort();
+#endif
r->__c_ = __c;
r->__next_ = p;
++__csz_;
@@ -402,7 +410,11 @@ __c_node::__add(__i_node* i)
nc = 1;
__i_node** beg = (__i_node**)malloc(nc * sizeof(__i_node*));
if (beg == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
+#else
+ abort();
+#endif
if (nc > 1)
memcpy(beg, beg_, nc/2*sizeof(__i_node*));
free(beg_);
@@ -424,7 +436,11 @@ __libcpp_db::__insert_iterator(void* __i)
size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1);
__i_node** ibeg = (__i_node**)calloc(nc, sizeof(void*));
if (ibeg == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
+#else
+ abort();
+#endif
for (__i_node** p = __ibeg_; p != __iend_; ++p)
{
__i_node* q = *p;
@@ -445,7 +461,11 @@ __libcpp_db::__insert_iterator(void* __i)
__i_node* p = __ibeg_[hi];
__i_node* r = __ibeg_[hi] = (__i_node*)malloc(sizeof(__i_node));
if (r == nullptr)
+#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
+#else
+ abort();
+#endif
::new(r) __i_node(__i, p, nullptr);
++__isz_;
return r;
diff --git a/contrib/libc++/src/exception.cpp b/contrib/libc++/src/exception.cpp
index 6a5803d..0dbb660 100644
--- a/contrib/libc++/src/exception.cpp
+++ b/contrib/libc++/src/exception.cpp
@@ -10,6 +10,10 @@
#include "exception"
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
#if __APPLE__
#include <cxxabi.h>
@@ -23,14 +27,16 @@
#define __terminate_handler __cxxabiapple::__cxa_terminate_handler
#define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler
#endif // _LIBCPPABI_VERSION
-#elif defined(LIBCXXRT)
+#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
#include <cxxabi.h>
using namespace __cxxabiv1;
- #define HAVE_DEPENDENT_EH_ABI 1
-#else // __APPLE__
+ #if defined(LIBCXXRT) || defined(_LIBCPPABI_VERSION)
+ #define HAVE_DEPENDENT_EH_ABI 1
+ #endif
+#else // __has_include(<cxxabi.h>)
static std::terminate_handler __terminate_handler;
static std::unexpected_handler __unexpected_handler;
-#endif // __APPLE__
+#endif // __has_include(<cxxabi.h>)
namespace std
{
@@ -50,7 +56,7 @@ get_unexpected() _NOEXCEPT
return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0);
}
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
void
unexpected()
{
@@ -71,7 +77,7 @@ get_terminate() _NOEXCEPT
return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0);
}
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
void
terminate() _NOEXCEPT
{
@@ -96,12 +102,9 @@ terminate() _NOEXCEPT
#ifndef LIBCXXRT
bool uncaught_exception() _NOEXCEPT
{
-#if __APPLE__
+#if __APPLE__ || defined(_LIBCPPABI_VERSION)
// on Darwin, there is a helper function so __cxa_get_globals is private
return __cxa_uncaught_exception();
-#elif LIBCXXRT
- __cxa_eh_globals * globals = __cxa_get_globals();
- return (globals->uncaughtExceptions != 0);
#else // __APPLE__
#warning uncaught_exception not yet implemented
::abort();
@@ -181,7 +184,7 @@ nested_exception::~nested_exception() _NOEXCEPT
{
}
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
void
nested_exception::rethrow_nested() const
{
@@ -206,7 +209,7 @@ exception_ptr current_exception() _NOEXCEPT
#endif // __APPLE__
}
-_ATTRIBUTE(noreturn)
+_LIBCPP_NORETURN
void rethrow_exception(exception_ptr p)
{
#if HAVE_DEPENDENT_EH_ABI
diff --git a/contrib/libc++/src/future.cpp b/contrib/libc++/src/future.cpp
index 2935711..feb37e4 100644
--- a/contrib/libc++/src/future.cpp
+++ b/contrib/libc++/src/future.cpp
@@ -47,7 +47,7 @@ __future_error_category::message(int ev) const
}
const error_category&
-future_category()
+future_category() _NOEXCEPT
{
static __future_error_category __f;
return __f;
diff --git a/contrib/libc++/src/ios.cpp b/contrib/libc++/src/ios.cpp
index 80917a0..732a61b 100644
--- a/contrib/libc++/src/ios.cpp
+++ b/contrib/libc++/src/ios.cpp
@@ -401,7 +401,7 @@ ios_base::move(ios_base& rhs)
}
void
-ios_base::swap(ios_base& rhs)
+ios_base::swap(ios_base& rhs) _NOEXCEPT
{
_VSTD::swap(__fmtflags_, rhs.__fmtflags_);
_VSTD::swap(__precision_, rhs.__precision_);
diff --git a/contrib/libc++/src/iostream.cpp b/contrib/libc++/src/iostream.cpp
index bfb1bfb..f5b959b 100644
--- a/contrib/libc++/src/iostream.cpp
+++ b/contrib/libc++/src/iostream.cpp
@@ -13,21 +13,21 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-alignas (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)];
-alignas (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
-alignas (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
-alignas (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)];
-alignas (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
-alignas (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
+_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>)];
+_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)];
+_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
+_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
-alignas (istream) char cin [sizeof(istream)];
-alignas (ostream) char cout[sizeof(ostream)];
-alignas (ostream) char cerr[sizeof(ostream)];
-alignas (ostream) char clog[sizeof(ostream)];
-alignas (wistream) char wcin [sizeof(wistream)];
-alignas (wostream) char wcout[sizeof(wostream)];
-alignas (wostream) char wcerr[sizeof(wostream)];
-alignas (wostream) char wclog[sizeof(wostream)];
+_ALIGNAS_TYPE (istream) char cin [sizeof(istream)];
+_ALIGNAS_TYPE (ostream) char cout[sizeof(ostream)];
+_ALIGNAS_TYPE (ostream) char cerr[sizeof(ostream)];
+_ALIGNAS_TYPE (ostream) char clog[sizeof(ostream)];
+_ALIGNAS_TYPE (wistream) char wcin [sizeof(wistream)];
+_ALIGNAS_TYPE (wostream) char wcout[sizeof(wostream)];
+_ALIGNAS_TYPE (wostream) char wcerr[sizeof(wostream)];
+_ALIGNAS_TYPE (wostream) char wclog[sizeof(wostream)];
ios_base::Init __start_std_streams;
diff --git a/contrib/libc++/src/locale.cpp b/contrib/libc++/src/locale.cpp
index fe99488..542c0d7 100644
--- a/contrib/libc++/src/locale.cpp
+++ b/contrib/libc++/src/locale.cpp
@@ -1052,17 +1052,17 @@ ctype_byname<wchar_t>::do_is(mask m, char_type c) const
#ifdef _LIBCPP_WCTYPE_IS_MASK
return static_cast<bool>(iswctype_l(c, m, __l));
#else
- bool result = true;
- if (m & space && !iswspace_l(c, __l)) result = false;
- if (m & print && !iswprint_l(c, __l)) result = false;
- if (m & cntrl && !iswcntrl_l(c, __l)) result = false;
- if (m & upper && !iswupper_l(c, __l)) result = false;
- if (m & lower && !iswlower_l(c, __l)) result = false;
- if (m & alpha && !iswalpha_l(c, __l)) result = false;
- if (m & digit && !iswdigit_l(c, __l)) result = false;
- if (m & punct && !iswpunct_l(c, __l)) result = false;
- if (m & xdigit && !iswxdigit_l(c, __l)) result = false;
- if (m & blank && !iswblank_l(c, __l)) result = false;
+ 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);
return result;
#endif
}
@@ -1109,17 +1109,16 @@ 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)) 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;
- break;
+ 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;
#endif
}
return low;
@@ -4865,7 +4864,7 @@ template <>
void
__time_get_storage<char>::init(const ctype<char>& ct)
{
- tm t;
+ tm t = {0};
char buf[100];
// __weeks_
for (int i = 0; i < 7; ++i)
diff --git a/contrib/libc++/src/memory.cpp b/contrib/libc++/src/memory.cpp
index a892e75..3884a2b 100644
--- a/contrib/libc++/src/memory.cpp
+++ b/contrib/libc++/src/memory.cpp
@@ -7,7 +7,10 @@
//
//===----------------------------------------------------------------------===//
+#define _LIBCPP_BUILDING_MEMORY
#include "memory"
+#include "mutex"
+#include "thread"
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -116,6 +119,53 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
#endif // _LIBCPP_NO_RTTI
+#if __has_feature(cxx_atomic)
+
+static const std::size_t __sp_mut_count = 16;
+static mutex mut_back[__sp_mut_count];
+
+_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
+ : _(p)
+{
+}
+
+void
+__sp_mut::lock() _NOEXCEPT
+{
+ mutex& m = *static_cast<mutex*>(_);
+ unsigned count = 0;
+ while (!m.try_lock())
+ {
+ if (++count > 16)
+ {
+ m.lock();
+ break;
+ }
+ this_thread::yield();
+ }
+}
+
+void
+__sp_mut::unlock() _NOEXCEPT
+{
+ static_cast<mutex*>(_)->unlock();
+}
+
+__sp_mut&
+__get_sp_mut(const void* p)
+{
+ static __sp_mut muts[__sp_mut_count]
+ {
+ &mut_back[ 0], &mut_back[ 1], &mut_back[ 2], &mut_back[ 3],
+ &mut_back[ 4], &mut_back[ 5], &mut_back[ 6], &mut_back[ 7],
+ &mut_back[ 8], &mut_back[ 9], &mut_back[10], &mut_back[11],
+ &mut_back[12], &mut_back[13], &mut_back[14], &mut_back[15]
+ };
+ return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
+}
+
+#endif // __has_feature(cxx_atomic)
+
void
declare_reachable(void*)
{
diff --git a/contrib/libc++/src/mutex.cpp b/contrib/libc++/src/mutex.cpp
index 9aa051b..42195aa 100644
--- a/contrib/libc++/src/mutex.cpp
+++ b/contrib/libc++/src/mutex.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#define _LIBCPP_BUILDING_MUTEX
#include "mutex"
#include "limits"
#include "system_error"
@@ -32,13 +33,13 @@ mutex::lock()
}
bool
-mutex::try_lock()
+mutex::try_lock() _NOEXCEPT
{
return pthread_mutex_trylock(&__m_) == 0;
}
void
-mutex::unlock()
+mutex::unlock() _NOEXCEPT
{
int ec = pthread_mutex_unlock(&__m_);
assert(ec == 0);
@@ -90,14 +91,14 @@ recursive_mutex::lock()
}
void
-recursive_mutex::unlock()
+recursive_mutex::unlock() _NOEXCEPT
{
int e = pthread_mutex_unlock(&__m_);
assert(e == 0);
}
bool
-recursive_mutex::try_lock()
+recursive_mutex::try_lock() _NOEXCEPT
{
return pthread_mutex_trylock(&__m_) == 0;
}
@@ -124,7 +125,7 @@ timed_mutex::lock()
}
bool
-timed_mutex::try_lock()
+timed_mutex::try_lock() _NOEXCEPT
{
unique_lock<mutex> lk(__m_, try_to_lock);
if (lk.owns_lock() && !__locked_)
@@ -136,7 +137,7 @@ timed_mutex::try_lock()
}
void
-timed_mutex::unlock()
+timed_mutex::unlock() _NOEXCEPT
{
lock_guard<mutex> _(__m_);
__locked_ = false;
@@ -175,7 +176,7 @@ recursive_timed_mutex::lock()
}
bool
-recursive_timed_mutex::try_lock()
+recursive_timed_mutex::try_lock() _NOEXCEPT
{
pthread_t id = pthread_self();
unique_lock<mutex> lk(__m_, try_to_lock);
@@ -191,7 +192,7 @@ recursive_timed_mutex::try_lock()
}
void
-recursive_timed_mutex::unlock()
+recursive_timed_mutex::unlock() _NOEXCEPT
{
unique_lock<mutex> lk(__m_);
if (--__count_ == 0)
diff --git a/contrib/libc++/src/new.cpp b/contrib/libc++/src/new.cpp
index 1fb4b2d..3ad593a 100644
--- a/contrib/libc++/src/new.cpp
+++ b/contrib/libc++/src/new.cpp
@@ -11,6 +11,10 @@
#include "new"
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
#if __APPLE__
#include <cxxabi.h>
@@ -21,7 +25,12 @@
#define __new_handler __cxxabiapple::__cxa_new_handler
#endif
#else // __APPLE__
- static std::new_handler __new_handler;
+ #if defined(LIBCXXRT) || __has_include(<cxxabi.h>)
+ #include <cxxabi.h>
+ #endif // __has_include(<cxxabi.h>)
+ #ifndef _LIBCPPABI_VERSION
+ static std::new_handler __new_handler;
+ #endif // _LIBCPPABI_VERSION
#endif
// Implement all new and delete operators as weak definitions
diff --git a/contrib/libc++/src/random.cpp b/contrib/libc++/src/random.cpp
index 6140b74..97a40c5 100644
--- a/contrib/libc++/src/random.cpp
+++ b/contrib/libc++/src/random.cpp
@@ -40,7 +40,7 @@ random_device::operator()()
}
double
-random_device::entropy() const
+random_device::entropy() const _NOEXCEPT
{
return 0;
}
diff --git a/contrib/libc++/src/stdexcept.cpp b/contrib/libc++/src/stdexcept.cpp
index 9fa4f59..660ebfe 100644
--- a/contrib/libc++/src/stdexcept.cpp
+++ b/contrib/libc++/src/stdexcept.cpp
@@ -16,8 +16,13 @@
#include <cstddef>
#include "system_error"
-// Use <cxxabi.h> to determine whether we're linking against libc++abi.
-#if __has_include(<cxxabi.h>)
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
+#if __APPLE__
+#include <cxxabi.h>
+#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
#include <cxxabi.h>
#endif
@@ -34,7 +39,7 @@ private:
const char* str_;
typedef std::size_t unused_t;
- typedef std::int32_t count_t;
+ typedef std::ptrdiff_t count_t;
static const std::ptrdiff_t offset = static_cast<std::ptrdiff_t>(2*sizeof(unused_t) +
sizeof(count_t));
@@ -72,7 +77,7 @@ __libcpp_nmstr::operator=(const __libcpp_nmstr& s)
const char* p = str_;
str_ = s.str_;
__sync_add_and_fetch(&count(), 1);
- if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), -1) < 0)
+ if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), count_t(-1)) < 0)
delete [] (p-offset);
return *this;
}
@@ -80,7 +85,7 @@ __libcpp_nmstr::operator=(const __libcpp_nmstr& s)
inline
__libcpp_nmstr::~__libcpp_nmstr()
{
- if (__sync_add_and_fetch(&count(), -1) < 0)
+ if (__sync_add_and_fetch(&count(), count_t(-1)) < 0)
delete [] (str_ - offset);
}
diff --git a/contrib/libc++/src/support/win32/locale_win32.cpp b/contrib/libc++/src/support/win32/locale_win32.cpp
deleted file mode 100644
index 02b5874..0000000
--- a/contrib/libc++/src/support/win32/locale_win32.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-// -*- C++ -*-
-//===-------------------- support/win32/locale_win32.cpp ------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "support/win32/locale_win32.h"
-
-#include <stdarg.h> // va_start, va_end
-
-// FIXME: base currently unused. Needs manual work to construct the new locale
-locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
-{
- return _create_locale( mask, locale );
-}
-locale_t uselocale( locale_t newloc )
-{
- locale_t old_locale = _get_current_locale();
- // uselocale sets the thread's locale by definition, so unconditionally use thread-local locale
- _configthreadlocale( _ENABLE_PER_THREAD_LOCALE );
- // uselocale sets all categories
- setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale );
- // uselocale returns the old locale_t
- return old_locale;
-}
-lconv *localeconv_l( locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return localeconv();
-}
-size_t mbrlen_l( const char *__restrict__ s, size_t n,
- mbstate_t *__restrict__ ps, locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return mbrlen( s, n, ps );
-}
-size_t mbsrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
- size_t len, mbstate_t *__restrict__ ps, locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return mbsrtowcs( dst, src, len, ps );
-}
-size_t wcrtomb_l( char *__restrict__ s, wchar_t wc, mbstate_t *__restrict__ ps,
- locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return wcrtomb( s, wc, ps );
-}
-size_t mbrtowc_l( wchar_t *__restrict__ pwc, const char *__restrict__ s,
- size_t n, mbstate_t *__restrict__ ps, locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return mbrtowc( pwc, s, n, ps );
-}
-size_t mbsnrtowcs_l( wchar_t *__restrict__ dst, const char **__restrict__ src,
- size_t nms, size_t len, mbstate_t *__restrict__ ps, locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return mbsnrtowcs( dst, src, nms, len, ps );
-}
-size_t wcsnrtombs_l( char *__restrict__ dst, const wchar_t **__restrict__ src,
- size_t nwc, size_t len, mbstate_t *__restrict__ ps, locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return wcsnrtombs( dst, src, nwc, len, ps );
-}
-wint_t btowc_l( int c, locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return btowc( c );
-}
-int wctob_l( wint_t c, locale_t loc )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return wctob( c );
-}
-
-int asprintf_l( char **ret, locale_t loc, const char *format, ... )
-{
- va_list ap;
- va_start( ap, format );
- int result = vasprintf_l( ret, loc, format, ap );
- va_end(ap);
- return result;
-}
-int vasprintf_l( char **ret, locale_t loc, const char *format, va_list ap )
-{
- __locale_raii __current( uselocale(loc), uselocale );
- return vasprintf( ret, format, ap );
-}
diff --git a/contrib/libc++/src/support/win32/support.cpp b/contrib/libc++/src/support/win32/support.cpp
deleted file mode 100644
index 9e85077..0000000
--- a/contrib/libc++/src/support/win32/support.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-// -*- C++ -*-
-//===----------------------- support/win32/support.h ----------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include <support/win32/support.h>
-#include <stdarg.h> // va_start, va_end
-#include <stddef.h> // size_t
-#include <stdlib.h> // malloc
-#include <stdio.h> // vsprintf, vsnprintf
-#include <string.h> // strcpy, wcsncpy
-
-int asprintf(char **sptr, const char *__restrict fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- int result = vasprintf(sptr, fmt, ap);
- va_end(ap);
- return result;
-}
-int vasprintf( char **sptr, const char *__restrict fmt, va_list ap )
-{
- *sptr = NULL;
- int count = vsnprintf( *sptr, 0, fmt, ap );
- if( (count >= 0) && ((*sptr = (char*)malloc(count+1)) != NULL) )
- {
- vsprintf( *sptr, fmt, ap );
- sptr[count] = '\0';
- }
-
- 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;
-}
diff --git a/contrib/libc++/src/thread.cpp b/contrib/libc++/src/thread.cpp
index f27136a..8747adf 100644
--- a/contrib/libc++/src/thread.cpp
+++ b/contrib/libc++/src/thread.cpp
@@ -11,10 +11,15 @@
#include "exception"
#include "vector"
#include "future"
+#include "limits"
#include <sys/types.h>
-#if !_WIN32 && !__sun__
+#if !_WIN32
+#if !__sun__ && !__linux__
#include <sys/sysctl.h>
-#endif // _WIN32
+#else
+#include <unistd.h>
+#endif // !__sun__ && !__linux__
+#endif // !_WIN32
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -52,7 +57,7 @@ thread::detach()
}
unsigned
-thread::hardware_concurrency()
+thread::hardware_concurrency() _NOEXCEPT
{
#if defined(CTL_HW) && defined(HW_NCPU)
unsigned n;
@@ -60,6 +65,11 @@ thread::hardware_concurrency()
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)
+ long result = sysconf(_SC_NPROCESSORS_ONLN);
+ if (result < 0 || result > UINT_MAX)
+ result = 0;
+ return result;
#else // defined(CTL_HW) && defined(HW_NCPU)
// TODO: grovel through /proc or check cpuid on x86 and similar
// instructions on other architectures.
@@ -74,11 +84,22 @@ void
sleep_for(const chrono::nanoseconds& ns)
{
using namespace chrono;
- if (ns >= nanoseconds::zero())
+ if (ns > nanoseconds::zero())
{
+ seconds s = duration_cast<seconds>(ns);
timespec ts;
- ts.tv_sec = static_cast<decltype(ts.tv_sec)>(duration_cast<seconds>(ns).count());
- ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((ns - seconds(ts.tv_sec)).count());
+ typedef decltype(ts.tv_sec) ts_sec;
+ _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
+ if (s.count() < ts_sec_max)
+ {
+ ts.tv_sec = static_cast<ts_sec>(s.count());
+ ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((ns-s).count());
+ }
+ else
+ {
+ ts.tv_sec = ts_sec_max;
+ ts.tv_nsec = giga::num - 1;
+ }
nanosleep(&ts, 0);
}
}
diff --git a/contrib/libc++/src/typeinfo.cpp b/contrib/libc++/src/typeinfo.cpp
index cfc64ef..6bab077 100644
--- a/contrib/libc++/src/typeinfo.cpp
+++ b/contrib/libc++/src/typeinfo.cpp
@@ -7,8 +7,15 @@
//
//===----------------------------------------------------------------------===//
#include <stdlib.h>
+
+#ifndef __has_include
+#define __has_include(inc) 0
+#endif
+
#if __APPLE__
#include <cxxabi.h>
+#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
+#include <cxxabi.h>
#endif
#include "typeinfo"
OpenPOWER on IntegriCloud