summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/src
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2015-02-13 22:05:54 +0000
committerdim <dim@FreeBSD.org>2015-02-13 22:05:54 +0000
commit3678f64ad386927abc67f2fa9c29e9d841865db8 (patch)
tree3f1fe901534b9de961c0c7ea660ae37c69fea14b /contrib/libc++/src
parentd8b2164f70a462483fbb9be8e8edadf15b5c13a3 (diff)
downloadFreeBSD-src-3678f64ad386927abc67f2fa9c29e9d841865db8.zip
FreeBSD-src-3678f64ad386927abc67f2fa9c29e9d841865db8.tar.gz
Synchronize the default C++ stack in stable/10 with head, by merging
almost all recent changes to libc++ and libcxxrt. MFC r256642: Since C++ typeinfo objects are currently not guaranteed to be merged at runtime by the dynamic linker, check for their equality in libcxxrt by not only comparing the typeinfo's name pointers, but also comparing the full names, if necessary. (This is similar to what GNU libstdc++ does in its default configuration.) The 'deep' check can be turned off again by defining LIBCXXRT_MERGED_TYPEINFO, and recompiling libcxxrt. Reviewed by: theraven MFC r270522 (by rdivacky): The standard we compile libc++ with is called c++11 not c++0x. MFC r273066 (by bapt): Import patch from libc++ r197313 which allows using libc++ headers with gcc Differential Revision: https://reviews.freebsd.org/D942 Reviewed by: imp MFC r273381 (by bapt): Add support for __cxa_throw_bad_array_new_length in libcxxrt It is required for use with newer g++49 Differential Revision: https://reviews.freebsd.org/D982 Reviewed by: theraven Approved by: theraven MFC r273382 (by bapt): Fix build by marking the new functions as weak This is a temporary fix MFC r273407 (by bapt): When using an external gcc 4.8+ and not building libstdc++ then create in the objectdir a fake libstdc++.so and libstdc++.a which is a symlink on libc++ that allow g++ to satisfy its links dependencies in the least hackish way. Please note that this hacky libstds++ never get installed on the final system Reviewed by: imp MFC r273434 (by bapt): Do not define bad_array_new_length::bad_array_new_length in libc++ anymore when used in combinaison with libcxxrt since it is now defined there already. This fixes building world MFC r276417: Import libcxxrt master 00bc29eb6513624824a6d7db2ebc768a4216a604. Interesting fixes: 76584a0 Reorganize code to use only 32bit atomic ops for 32bit platforms 30d2ae5 Implement __cxa_throw_bad_array_new_length Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D1390 MFC r277217: Import libc++ trunk r224926. This fixes a number of bugs, completes C++14 support[1], adds more C++1z features[2], and fixes the following LWG issues[3]: 1450: Contradiction in regex_constants 2003: String exception inconsistency in erase. 2075: Progress guarantees, lock-free property, and scheduling assumptions 2104: unique_lock move-assignment should not be noexcept 2112: User-defined classes that cannot be derived from 2132: std::function ambiguity 2135: Unclear requirement for exceptions thrown in condition_variable::wait() 2142: packaged_task::operator() synchronization too broad? 2182: Container::[const_]reference types are misleadingly specified 2186: Incomplete action on async/launch::deferred 2188: Reverse iterator does not fully support targets that overload operator& 2193: Default constructors for standard library containers are explicit 2205: Problematic postconditions of regex_match and regex_search 2213: Return value of std::regex_replace 2240: Probable misuse of term "function scope" in [thread.condition] 2252: Strong guarantee on vector::push_back() still broken with C++11? 2257: Simplify container requirements with the new algorithms 2258: a.erase(q1, q2) unable to directly return q2 2263: Comparing iterators and allocator pointers with different const-character 2268: Setting a default argument in the declaration of a member function assign of std::basic_string 2271: regex_traits::lookup_classname specification unclear 2272: quoted should use char_traits::eq for character comparison 2278: User-defined literals for Standard Library types 2280: begin / end for arrays should be constexpr and noexcept 2285: make_reverse_iterator 2288: Inconsistent requirements for shared mutexes 2291: std::hash is vulnerable to collision DoS attack 2293: Wrong facet used by num_put::do_put 2299: Effects of inaccessible key_compare::is_transparent type are not clear 2301: Why is std::tie not constexpr? 2304: Complexity of count in unordered associative containers 2306: match_results::reference should be value_type&, not const value_type& 2308: Clarify container destructor requirements w.r.t. std::array 2313: tuple_size should always derive from integral_constant<size_t, N> 2314: apply() should return decltype(auto) and use decay_t before tuple_size 2315: weak_ptr should be movable 2316: weak_ptr::lock() should be atomic 2317: The type property queries should be UnaryTypeTraits returning size_t 2320: select_on_container_copy_construction() takes allocators, not containers 2322: Associative(initializer_list, stuff) constructors are underspecified 2323: vector::resize(n, t)'s specification should be simplified 2324: Insert iterator constructors should use addressof() 2329: regex_match()/regex_search() with match_results should forbid temporary strings 2330: regex("meow", regex::icase) is technically forbidden but should be permitted 2332: regex_iterator/regex_token_iterator should forbid temporary regexes 2339: Wording issue in nth_element 2341: Inconsistency between basic_ostream::seekp(pos) and basic_ostream::seekp(off, dir) 2344: quoted()'s interaction with padding is unclear 2346: integral_constant's member functions should be marked noexcept 2350: min, max, and minmax should be constexpr 2356: Stability of erasure in unordered associative containers 2357: Remaining "Assignable" requirement 2359: How does regex_constants::nosubs affect basic_regex::mark_count()? 2360: reverse_iterator::operator*() is unimplementable [1] http://libcxx.llvm.org/cxx1y_status.html [2] http://libcxx.llvm.org/cxx1z_status.html [3] http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html Exp-run: antoine MFC r277944: Partially revert r273382, to reduce diffs against upstream. This was a temporary fix to solve a conflict with an older version of libc++, and it is no longer relevant. MFC r278010: Revert r256642, not only to reduce diffs against upstream libcxxrt, but also because it is the wrong approach: comparing typeinfo names deeply causes trouble if two loaded DSOs use independent types of the same name. In addition, this particular change was never merged to FreeBSD 10.x and 9.x, so let's get rid of it before it ends up in an 11.x release. Discussed with: theraven, joerg@netbsd MFC r278016: Import libcxxrt master 1cb607e89f6135bbc10f3d3b6fba1f983e258dcc. Interesting fixes: 1cb607e Correct gcc version check for __cxa_begin_catch() declaration with or without throw()
Diffstat (limited to 'contrib/libc++/src')
-rw-r--r--contrib/libc++/src/algorithm.cpp9
-rw-r--r--contrib/libc++/src/chrono.cpp9
-rw-r--r--contrib/libc++/src/condition_variable.cpp10
-rw-r--r--contrib/libc++/src/debug.cpp40
-rw-r--r--contrib/libc++/src/exception.cpp2
-rw-r--r--contrib/libc++/src/future.cpp15
-rw-r--r--contrib/libc++/src/hash.cpp2
-rw-r--r--contrib/libc++/src/ios.cpp88
-rw-r--r--contrib/libc++/src/locale.cpp52
-rw-r--r--contrib/libc++/src/memory.cpp10
-rw-r--r--contrib/libc++/src/mutex.cpp27
-rw-r--r--contrib/libc++/src/new.cpp20
-rw-r--r--contrib/libc++/src/optional.cpp5
-rw-r--r--contrib/libc++/src/random.cpp68
-rw-r--r--contrib/libc++/src/regex.cpp14
-rw-r--r--contrib/libc++/src/shared_mutex.cpp19
-rw-r--r--contrib/libc++/src/stdexcept.cpp122
-rw-r--r--contrib/libc++/src/string.cpp6
-rw-r--r--contrib/libc++/src/strstream.cpp14
-rw-r--r--contrib/libc++/src/system_error.cpp21
-rw-r--r--contrib/libc++/src/thread.cpp19
-rw-r--r--contrib/libc++/src/valarray.cpp2
22 files changed, 324 insertions, 250 deletions
diff --git a/contrib/libc++/src/algorithm.cpp b/contrib/libc++/src/algorithm.cpp
index 10c4c331..e548856 100644
--- a/contrib/libc++/src/algorithm.cpp
+++ b/contrib/libc++/src/algorithm.cpp
@@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
#include "algorithm"
#include "random"
#include "mutex"
@@ -48,12 +47,16 @@ template bool __insertion_sort_incomplete<__less<long double>&, long double*>(lo
template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
+#ifndef _LIBCPP_HAS_NO_THREADS
static pthread_mutex_t __rs_mut = PTHREAD_MUTEX_INITIALIZER;
+#endif
unsigned __rs_default::__c_ = 0;
__rs_default::__rs_default()
{
+#ifndef _LIBCPP_HAS_NO_THREADS
pthread_mutex_lock(&__rs_mut);
+#endif
__c_ = 1;
}
@@ -64,8 +67,12 @@ __rs_default::__rs_default(const __rs_default&)
__rs_default::~__rs_default()
{
+#ifndef _LIBCPP_HAS_NO_THREADS
if (--__c_ == 0)
pthread_mutex_unlock(&__rs_mut);
+#else
+ --__c_;
+#endif
}
__rs_default::result_type
diff --git a/contrib/libc++/src/chrono.cpp b/contrib/libc++/src/chrono.cpp
index 15a6f46..4569411 100644
--- a/contrib/libc++/src/chrono.cpp
+++ b/contrib/libc++/src/chrono.cpp
@@ -46,6 +46,7 @@ system_clock::from_time_t(time_t t) _NOEXCEPT
return system_clock::time_point(seconds(t));
}
+#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
// steady_clock
const bool steady_clock::is_steady;
@@ -108,10 +109,8 @@ steady_clock::now() _NOEXCEPT
}
#else // __APPLE__
-// FIXME: We assume that clock_gettime(CLOCK_MONOTONIC) works on
-// non-apple systems. Instead, we should check _POSIX_TIMERS and
-// _POSIX_MONOTONIC_CLOCK and fall back to something else if those
-// don't exist.
+// FIXME: if _LIBCPP_HAS_NO_MONOTONIC_CLOCK, then clock_gettime isn't going to
+// work. It may be possible to fall back on something else, depending on the system.
// Warning: If this is not truly steady, then it is non-conforming. It is
// better for it to not exist and have the rest of libc++ use system_clock
@@ -127,6 +126,8 @@ steady_clock::now() _NOEXCEPT
}
#endif // __APPLE__
+#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
+
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/libc++/src/condition_variable.cpp b/contrib/libc++/src/condition_variable.cpp
index de0f6f4..5fd5fc8 100644
--- a/contrib/libc++/src/condition_variable.cpp
+++ b/contrib/libc++/src/condition_variable.cpp
@@ -7,6 +7,10 @@
//
//===----------------------------------------------------------------------===//
+#include "__config"
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
#include "condition_variable"
#include "thread"
#include "system_error"
@@ -32,7 +36,7 @@ condition_variable::notify_all() _NOEXCEPT
}
void
-condition_variable::wait(unique_lock<mutex>& lk)
+condition_variable::wait(unique_lock<mutex>& lk) _NOEXCEPT
{
if (!lk.owns_lock())
__throw_system_error(EPERM,
@@ -44,7 +48,7 @@ condition_variable::wait(unique_lock<mutex>& lk)
void
condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
- chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp)
+ chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) _NOEXCEPT
{
using namespace chrono;
if (!lk.owns_lock())
@@ -79,3 +83,5 @@ notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
}
_LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/libc++/src/debug.cpp b/contrib/libc++/src/debug.cpp
index d0e8679..60694a3 100644
--- a/contrib/libc++/src/debug.cpp
+++ b/contrib/libc++/src/debug.cpp
@@ -35,6 +35,7 @@ __get_const_db()
namespace
{
+#ifndef _LIBCPP_HAS_NO_THREADS
typedef mutex mutex_type;
typedef lock_guard<mutex_type> WLock;
typedef lock_guard<mutex_type> RLock;
@@ -45,6 +46,7 @@ mut()
static mutex_type m;
return m;
}
+#endif // !_LIBCPP_HAS_NO_THREADS
} // unnamed namespace
@@ -108,7 +110,9 @@ __libcpp_db::~__libcpp_db()
void*
__libcpp_db::__find_c_from_i(void* __i) const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
RLock _(mut());
+#endif
__i_node* i = __find_iterator(__i);
_LIBCPP_ASSERT(i != nullptr, "iterator not found in debug database.");
return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
@@ -117,7 +121,9 @@ __libcpp_db::__find_c_from_i(void* __i) const
void
__libcpp_db::__insert_ic(void* __i, const void* __c)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
if (__cbeg_ == __cend_)
return;
size_t hc = hash<const void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
@@ -138,7 +144,9 @@ __libcpp_db::__insert_ic(void* __i, const void* __c)
__c_node*
__libcpp_db::__insert_c(void* __c)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_))
{
size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1);
@@ -184,7 +192,9 @@ __libcpp_db::__insert_c(void* __c)
void
__libcpp_db::__erase_i(void* __i)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
if (__ibeg_ != __iend_)
{
size_t hi = hash<void*>()(__i) % static_cast<size_t>(__iend_ - __ibeg_);
@@ -215,7 +225,9 @@ __libcpp_db::__erase_i(void* __i)
void
__libcpp_db::__invalidate_all(void* __c)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
if (__cend_ != __cbeg_)
{
size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
@@ -239,17 +251,23 @@ __libcpp_db::__invalidate_all(void* __c)
__c_node*
__libcpp_db::__find_c_and_lock(void* __c) const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
mut().lock();
+#endif
if (__cend_ == __cbeg_)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
mut().unlock();
+#endif
return nullptr;
}
size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p = __cbeg_[hc];
if (p == nullptr)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
mut().unlock();
+#endif
return nullptr;
}
while (p->__c_ != __c)
@@ -257,7 +275,9 @@ __libcpp_db::__find_c_and_lock(void* __c) const
p = p->__next_;
if (p == nullptr)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
mut().unlock();
+#endif
return nullptr;
}
}
@@ -281,13 +301,17 @@ __libcpp_db::__find_c(void* __c) const
void
__libcpp_db::unlock() const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
mut().unlock();
+#endif
}
void
__libcpp_db::__erase_c(void* __c)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
if (__cend_ != __cbeg_)
{
size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_);
@@ -322,7 +346,9 @@ __libcpp_db::__erase_c(void* __c)
void
__libcpp_db::__iterator_copy(void* __i, const void* __i0)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
__i_node* i = __find_iterator(__i);
__i_node* i0 = __find_iterator(__i0);
__c_node* c0 = i0 != nullptr ? i0->__c_ : nullptr;
@@ -348,7 +374,9 @@ __libcpp_db::__iterator_copy(void* __i, const void* __i0)
bool
__libcpp_db::__dereferenceable(const void* __i) const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
RLock _(mut());
+#endif
__i_node* i = __find_iterator(__i);
return i != nullptr && i->__c_ != nullptr && i->__c_->__dereferenceable(__i);
}
@@ -356,7 +384,9 @@ __libcpp_db::__dereferenceable(const void* __i) const
bool
__libcpp_db::__decrementable(const void* __i) const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
RLock _(mut());
+#endif
__i_node* i = __find_iterator(__i);
return i != nullptr && i->__c_ != nullptr && i->__c_->__decrementable(__i);
}
@@ -364,7 +394,9 @@ __libcpp_db::__decrementable(const void* __i) const
bool
__libcpp_db::__addable(const void* __i, ptrdiff_t __n) const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
RLock _(mut());
+#endif
__i_node* i = __find_iterator(__i);
return i != nullptr && i->__c_ != nullptr && i->__c_->__addable(__i, __n);
}
@@ -372,7 +404,9 @@ __libcpp_db::__addable(const void* __i, ptrdiff_t __n) const
bool
__libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
RLock _(mut());
+#endif
__i_node* i = __find_iterator(__i);
return i != nullptr && i->__c_ != nullptr && i->__c_->__subscriptable(__i, __n);
}
@@ -380,7 +414,9 @@ __libcpp_db::__subscriptable(const void* __i, ptrdiff_t __n) const
bool
__libcpp_db::__less_than_comparable(const void* __i, const void* __j) const
{
+#ifndef _LIBCPP_HAS_NO_THREADS
RLock _(mut());
+#endif
__i_node* i = __find_iterator(__i);
__i_node* j = __find_iterator(__j);
__c_node* ci = i != nullptr ? i->__c_ : nullptr;
@@ -391,7 +427,9 @@ __libcpp_db::__less_than_comparable(const void* __i, const void* __j) const
void
__libcpp_db::swap(void* c1, void* c2)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
size_t hc = hash<void*>()(c1) % static_cast<size_t>(__cend_ - __cbeg_);
__c_node* p1 = __cbeg_[hc];
_LIBCPP_ASSERT(p1 != nullptr, "debug mode internal logic error swap A");
@@ -420,7 +458,9 @@ __libcpp_db::swap(void* c1, void* c2)
void
__libcpp_db::__insert_i(void* __i)
{
+#ifndef _LIBCPP_HAS_NO_THREADS
WLock _(mut());
+#endif
__insert_iterator(__i);
}
diff --git a/contrib/libc++/src/exception.cpp b/contrib/libc++/src/exception.cpp
index 3ce6f2e..b5c46c0 100644
--- a/contrib/libc++/src/exception.cpp
+++ b/contrib/libc++/src/exception.cpp
@@ -16,7 +16,7 @@
#define __has_include(inc) 0
#endif
-#ifdef __APPLE__
+#if defined(__APPLE__) && !defined(LIBCXXRT)
#include <cxxabi.h>
using namespace __cxxabiv1;
diff --git a/contrib/libc++/src/future.cpp b/contrib/libc++/src/future.cpp
index 70919ab..0c5c2c4 100644
--- a/contrib/libc++/src/future.cpp
+++ b/contrib/libc++/src/future.cpp
@@ -7,6 +7,10 @@
//
//===----------------------------------------------------------------------===//
+#include "__config"
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
#include "future"
#include "string"
@@ -26,8 +30,13 @@ __future_error_category::name() const _NOEXCEPT
return "future";
}
+#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wswitch"
+#elif defined(__GNUC__) || defined(__GNUG__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wswitch"
+#endif
string
__future_error_category::message(int ev) const
@@ -50,7 +59,11 @@ __future_error_category::message(int ev) const
return string("unspecified future_errc value\n");
}
+#if defined(__clang__)
#pragma clang diagnostic pop
+#elif defined(__GNUC__) || defined(__GNUG__)
+#pragma GCC diagnostic pop
+#endif
const error_category&
future_category() _NOEXCEPT
@@ -289,3 +302,5 @@ shared_future<void>::operator=(const shared_future& __rhs)
}
_LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/libc++/src/hash.cpp b/contrib/libc++/src/hash.cpp
index 388ab2e..dc90f78 100644
--- a/contrib/libc++/src/hash.cpp
+++ b/contrib/libc++/src/hash.cpp
@@ -136,7 +136,7 @@ const unsigned indices[] =
// The algorithm creates a list of small primes, plus an open-ended list of
// potential primes. All prime numbers are potential prime numbers. However
// some potential prime numbers are not prime. In an ideal world, all potential
-// prime numbers would be prime. Candiate prime numbers are chosen as the next
+// prime numbers would be prime. Candidate prime numbers are chosen as the next
// highest potential prime. Then this number is tested for prime by dividing it
// by all potential prime numbers less than the sqrt of the candidate.
//
diff --git a/contrib/libc++/src/ios.cpp b/contrib/libc++/src/ios.cpp
index bbe3c07..d879beb 100644
--- a/contrib/libc++/src/ios.cpp
+++ b/contrib/libc++/src/ios.cpp
@@ -7,8 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
+#include "__config"
#include "ios"
#include "streambuf"
#include "istream"
@@ -54,9 +53,9 @@ string
__iostream_category::message(int ev) const
{
if (ev != static_cast<int>(io_errc::stream)
-#ifdef ELAST
- && ev <= ELAST
-#endif
+#ifdef _LIBCPP_ELAST
+ && ev <= _LIBCPP_ELAST
+#endif // _LIBCPP_ELAST
)
return __do_message::message(ev);
return string("unspecified iostream_category error");
@@ -134,7 +133,7 @@ locale
ios_base::imbue(const locale& newloc)
{
static_assert(sizeof(locale) == sizeof(__loc_), "");
- locale& loc_storage = *(locale*)&__loc_;
+ locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
locale oldloc = loc_storage;
loc_storage = newloc;
__call_callbacks(imbue_event);
@@ -144,17 +143,27 @@ ios_base::imbue(const locale& newloc)
locale
ios_base::getloc() const
{
- const locale& loc_storage = *(locale*)&__loc_;
+ const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
return loc_storage;
}
// xalloc
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
#else
int ios_base::__xindex_ = 0;
#endif
+template <typename _Tp>
+static size_t __ios_new_cap(size_t __req_size, size_t __current_cap)
+{ // Precondition: __req_size > __current_cap
+ const size_t mx = std::numeric_limits<size_t>::max() / sizeof(_Tp);
+ if (__req_size < mx/2)
+ return _VSTD::max(2 * __current_cap, __req_size);
+ else
+ return mx;
+}
+
int
ios_base::xalloc()
{
@@ -167,13 +176,8 @@ ios_base::iword(int index)
size_t req_size = static_cast<size_t>(index)+1;
if (req_size > __iarray_cap_)
{
- size_t newcap;
- const size_t mx = std::numeric_limits<size_t>::max();
- if (req_size < mx/2)
- newcap = _VSTD::max(2 * __iarray_cap_, req_size);
- else
- newcap = mx;
- long* iarray = (long*)realloc(__iarray_, newcap * sizeof(long));
+ size_t newcap = __ios_new_cap<long>(req_size, __iarray_cap_);
+ long* iarray = static_cast<long*>(realloc(__iarray_, newcap * sizeof(long)));
if (iarray == 0)
{
setstate(badbit);
@@ -182,8 +186,9 @@ ios_base::iword(int index)
return error;
}
__iarray_ = iarray;
- for (long* p = __iarray_ + __iarray_size_; __iarray_cap_ < newcap; ++__iarray_cap_, ++p)
+ for (long* p = __iarray_ + __iarray_size_; p < __iarray_ + newcap; ++p)
*p = 0;
+ __iarray_cap_ = newcap;
}
__iarray_size_ = max<size_t>(__iarray_size_, req_size);
return __iarray_[index];
@@ -195,13 +200,8 @@ ios_base::pword(int index)
size_t req_size = static_cast<size_t>(index)+1;
if (req_size > __parray_cap_)
{
- size_t newcap;
- const size_t mx = std::numeric_limits<size_t>::max();
- if (req_size < mx/2)
- newcap = _VSTD::max(2 * __parray_cap_, req_size);
- else
- newcap = mx;
- void** parray = (void**)realloc(__parray_, newcap * sizeof(void*));
+ size_t newcap = __ios_new_cap<void *>(req_size, __iarray_cap_);
+ void** parray = static_cast<void**>(realloc(__parray_, newcap * sizeof(void *)));
if (parray == 0)
{
setstate(badbit);
@@ -210,8 +210,9 @@ ios_base::pword(int index)
return error;
}
__parray_ = parray;
- for (void** p = __parray_ + __parray_size_; __parray_cap_ < newcap; ++__parray_cap_, ++p)
+ for (void** p = __parray_ + __parray_size_; p < __parray_ + newcap; ++p)
*p = 0;
+ __parray_cap_ = newcap;
}
__parray_size_ = max<size_t>(__parray_size_, req_size);
return __parray_[index];
@@ -225,20 +226,16 @@ ios_base::register_callback(event_callback fn, int index)
size_t req_size = __event_size_ + 1;
if (req_size > __event_cap_)
{
- size_t newcap;
- const size_t mx = std::numeric_limits<size_t>::max();
- if (req_size < mx/2)
- newcap = _VSTD::max(2 * __event_cap_, req_size);
- else
- newcap = mx;
- event_callback* fns = (event_callback*)realloc(__fn_, newcap * sizeof(event_callback));
+ size_t newcap = __ios_new_cap<event_callback>(req_size, __event_cap_);
+ event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newcap * sizeof(event_callback)));
if (fns == 0)
setstate(badbit);
__fn_ = fns;
- int* indxs = (int*)realloc(__index_, newcap * sizeof(int));
+ int* indxs = static_cast<int *>(realloc(__index_, newcap * sizeof(int)));
if (indxs == 0)
setstate(badbit);
__index_ = indxs;
+ __event_cap_ = newcap;
}
__fn_[__event_size_] = fn;
__index_[__event_size_] = index;
@@ -248,7 +245,7 @@ ios_base::register_callback(event_callback fn, int index)
ios_base::~ios_base()
{
__call_callbacks(erase_event);
- locale& loc_storage = *(locale*)&__loc_;
+ locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
loc_storage.~locale();
free(__fn_);
free(__index_);
@@ -299,19 +296,22 @@ void
ios_base::copyfmt(const ios_base& rhs)
{
// If we can't acquire the needed resources, throw bad_alloc (can't set badbit)
- // Don't alter *this until all needed resources are aquired
+ // Don't alter *this until all needed resources are acquired
unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free);
unique_ptr<int, void (*)(void*)> new_ints(0, free);
unique_ptr<long, void (*)(void*)> new_longs(0, free);
unique_ptr<void*, void (*)(void*)> new_pointers(0, free);
if (__event_cap_ < rhs.__event_size_)
{
- new_callbacks.reset((event_callback*)malloc(sizeof(event_callback) * rhs.__event_size_));
+ size_t newesize = sizeof(event_callback) * rhs.__event_size_;
+ new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!new_callbacks)
throw bad_alloc();
#endif // _LIBCPP_NO_EXCEPTIONS
- new_ints.reset((int*)malloc(sizeof(int) * rhs.__event_size_));
+
+ size_t newisize = sizeof(int) * rhs.__event_size_;
+ new_ints.reset(static_cast<int *>(malloc(newisize)));
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!new_ints)
throw bad_alloc();
@@ -319,7 +319,8 @@ ios_base::copyfmt(const ios_base& rhs)
}
if (__iarray_cap_ < rhs.__iarray_size_)
{
- new_longs.reset((long*)malloc(sizeof(long) * rhs.__iarray_size_));
+ size_t newsize = sizeof(long) * rhs.__iarray_size_;
+ new_longs.reset(static_cast<long*>(malloc(newsize)));
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!new_longs)
throw bad_alloc();
@@ -327,7 +328,8 @@ ios_base::copyfmt(const ios_base& rhs)
}
if (__parray_cap_ < rhs.__parray_size_)
{
- new_pointers.reset((void**)malloc(sizeof(void*) * rhs.__parray_size_));
+ size_t newsize = sizeof(void*) * rhs.__parray_size_;
+ new_pointers.reset(static_cast<void**>(malloc(newsize)));
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!new_pointers)
throw bad_alloc();
@@ -337,8 +339,8 @@ ios_base::copyfmt(const ios_base& rhs)
__fmtflags_ = rhs.__fmtflags_;
__precision_ = rhs.__precision_;
__width_ = rhs.__width_;
- locale& lhs_loc = *(locale*)&__loc_;
- locale& rhs_loc = *(locale*)&rhs.__loc_;
+ locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
+ const locale& rhs_loc = *reinterpret_cast<const locale*>(&rhs.__loc_);
lhs_loc = rhs_loc;
if (__event_cap_ < rhs.__event_size_)
{
@@ -381,7 +383,7 @@ ios_base::move(ios_base& rhs)
__rdstate_ = rhs.__rdstate_;
__exceptions_ = rhs.__exceptions_;
__rdbuf_ = 0;
- locale& rhs_loc = *(locale*)&rhs.__loc_;
+ locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
::new(&__loc_) locale(rhs_loc);
__fn_ = rhs.__fn_;
rhs.__fn_ = 0;
@@ -413,8 +415,8 @@ ios_base::swap(ios_base& rhs) _NOEXCEPT
_VSTD::swap(__width_, rhs.__width_);
_VSTD::swap(__rdstate_, rhs.__rdstate_);
_VSTD::swap(__exceptions_, rhs.__exceptions_);
- locale& lhs_loc = *(locale*)&__loc_;
- locale& rhs_loc = *(locale*)&rhs.__loc_;
+ locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
+ locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
_VSTD::swap(lhs_loc, rhs_loc);
_VSTD::swap(__fn_, rhs.__fn_);
_VSTD::swap(__index_, rhs.__index_);
diff --git a/contrib/libc++/src/locale.cpp b/contrib/libc++/src/locale.cpp
index a326323..f21e35d 100644
--- a/contrib/libc++/src/locale.cpp
+++ b/contrib/libc++/src/locale.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
// On Solaris, we need to define something to make the C99 parts of localeconv
// visible.
#ifdef __sun__
@@ -30,9 +28,9 @@
#include "__sso_allocator"
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
#include <support/win32/locale_win32.h>
-#else // _LIBCPP_MSVCRT
+#elif !defined(__ANDROID__)
#include <langinfo.h>
-#endif // !_LIBCPP_MSVCRT
+#endif
#include <stdlib.h>
#include <stdio.h>
@@ -68,7 +66,7 @@ make(A0 a0)
{
static typename aligned_storage<sizeof(T)>::type buf;
::new (&buf) T(a0);
- return *(T*)&buf;
+ return *reinterpret_cast<T*>(&buf);
}
template <class T, class A0, class A1>
@@ -78,7 +76,7 @@ make(A0 a0, A1 a1)
{
static typename aligned_storage<sizeof(T)>::type buf;
::new (&buf) T(a0, a1);
- return *(T*)&buf;
+ return *reinterpret_cast<T*>(&buf);
}
template <class T, class A0, class A1, class A2>
@@ -88,7 +86,7 @@ make(A0 a0, A1 a1, A2 a2)
{
static typename aligned_storage<sizeof(T)>::type buf;
::new (&buf) T(a0, a1, a2);
- return *(T*)&buf;
+ return *reinterpret_cast<T*>(&buf);
}
template <typename T, size_t N>
@@ -177,7 +175,7 @@ locale::__imp::__imp(size_t refs)
facets_.clear();
install(&make<_VSTD::collate<char> >(1u));
install(&make<_VSTD::collate<wchar_t> >(1u));
- install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1u));
+ install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
install(&make<_VSTD::ctype<wchar_t> >(1u));
install(&make<codecvt<char, char, mbstate_t> >(1u));
install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
@@ -461,7 +459,7 @@ locale::__imp::make_classic()
{
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
- locale* c = (locale*)&buf;
+ locale* c = reinterpret_cast<locale*>(&buf);
c->__locale_ = &make<__imp>(1u);
return *c;
}
@@ -479,7 +477,7 @@ locale::__imp::make_global()
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
::new (&buf) locale(locale::classic());
- return *(locale*)&buf;
+ return *reinterpret_cast<locale*>(&buf);
}
locale&
@@ -1036,7 +1034,9 @@ ctype<char>::classic_table() _NOEXCEPT
#elif defined(__EMSCRIPTEN__)
return *__ctype_b_loc();
#elif defined(_AIX)
- return (const unsigned long *)__lc_ctype_ptr->obj->mask;
+ return (const unsigned int *)__lc_ctype_ptr->obj->mask;
+#elif defined(__ANDROID__)
+ return reinterpret_cast<const unsigned char*>(_ctype_) + 1;
#else
// Platform not supported: abort so the person doing the port knows what to
// fix
@@ -1615,9 +1615,9 @@ int
codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
{
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
- if (mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
+ if (mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
#else
- if (__mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
+ if (__mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) == 0)
#endif
{
// stateless encoding
@@ -1743,8 +1743,8 @@ utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm
return codecvt_base::error;
if (to_end-to_nxt < 4)
return codecvt_base::partial;
- if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
- (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
+ if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
+ ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
return codecvt_base::error;
++frm_nxt;
uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
@@ -1820,8 +1820,8 @@ utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm
return codecvt_base::error;
if (to_end-to_nxt < 4)
return codecvt_base::partial;
- if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
- (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
+ if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
+ ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
return codecvt_base::error;
++frm_nxt;
uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
@@ -1944,9 +1944,9 @@ utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nx
return codecvt_base::error;
if (to_end-to_nxt < 2)
return codecvt_base::partial;
- if (((((unsigned long)c1 & 7) << 18) +
- (((unsigned long)c2 & 0x3F) << 12) +
- (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
+ if ((((c1 & 7UL) << 18) +
+ ((c2 & 0x3FUL) << 12) +
+ ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint16_t>(
0xD800
@@ -2065,9 +2065,9 @@ utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nx
return codecvt_base::error;
if (to_end-to_nxt < 2)
return codecvt_base::partial;
- if (((((unsigned long)c1 & 7) << 18) +
- (((unsigned long)c2 & 0x3F) << 12) +
- (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
+ if ((((c1 & 7UL) << 18) +
+ ((c2 & 0x3FUL) << 12) +
+ ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint32_t>(
0xD800
@@ -2174,9 +2174,9 @@ utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
break;
- if (((((unsigned long)c1 & 7) << 18) +
- (((unsigned long)c2 & 0x3F) << 12) +
- (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
+ if ((((c1 & 7UL) << 18) +
+ ((c2 & 0x3FUL) << 12) +
+ ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
break;
++nchar16_t;
frm_nxt += 4;
diff --git a/contrib/libc++/src/memory.cpp b/contrib/libc++/src/memory.cpp
index 98bcc86..8a4eb34 100644
--- a/contrib/libc++/src/memory.cpp
+++ b/contrib/libc++/src/memory.cpp
@@ -9,8 +9,10 @@
#define _LIBCPP_BUILDING_MEMORY
#include "memory"
+#ifndef _LIBCPP_HAS_NO_THREADS
#include "mutex"
#include "thread"
+#endif
_LIBCPP_BEGIN_NAMESPACE_STD
@@ -109,7 +111,7 @@ __shared_weak_count::lock() _NOEXCEPT
return 0;
}
-#ifndef _LIBCPP_NO_RTTI
+#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
const void*
__shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
@@ -119,7 +121,7 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
#endif // _LIBCPP_NO_RTTI
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
static const std::size_t __sp_mut_count = 16;
static pthread_mutex_t mut_back_imp[__sp_mut_count] =
@@ -172,7 +174,7 @@ __get_sp_mut(const void* p)
return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
}
-#endif // __has_feature(cxx_atomic)
+#endif // __has_feature(cxx_atomic) && !_LIBCPP_HAS_NO_THREADS
void
declare_reachable(void*)
@@ -208,7 +210,7 @@ align(size_t alignment, size_t size, void*& ptr, size_t& space)
if (size <= space)
{
char* p1 = static_cast<char*>(ptr);
- char* p2 = (char*)((size_t)(p1 + (alignment - 1)) & -alignment);
+ char* p2 = reinterpret_cast<char*>(reinterpret_cast<size_t>(p1 + (alignment - 1)) & -alignment);
size_t d = static_cast<size_t>(p2 - p1);
if (d <= space - size)
{
diff --git a/contrib/libc++/src/mutex.cpp b/contrib/libc++/src/mutex.cpp
index 0767897..e56271d 100644
--- a/contrib/libc++/src/mutex.cpp
+++ b/contrib/libc++/src/mutex.cpp
@@ -14,6 +14,7 @@
#include "cassert"
_LIBCPP_BEGIN_NAMESPACE_STD
+#ifndef _LIBCPP_HAS_NO_THREADS
const defer_lock_t defer_lock = {};
const try_to_lock_t try_to_lock = {};
@@ -206,18 +207,42 @@ recursive_timed_mutex::unlock() _NOEXCEPT
}
}
+#endif // !_LIBCPP_HAS_NO_THREADS
+
// If dispatch_once_f ever handles C++ exceptions, and if one can get to it
// without illegal macros (unexpected macros not beginning with _UpperCase or
// __lowercase), and if it stops spinning waiting threads, then call_once should
// call into dispatch_once_f instead of here. Relevant radar this code needs to
// keep in sync with: 7741191.
+#ifndef _LIBCPP_HAS_NO_THREADS
static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cv = PTHREAD_COND_INITIALIZER;
+#endif
void
__call_once(volatile unsigned long& flag, void* arg, void(*func)(void*))
{
+#if defined(_LIBCPP_HAS_NO_THREADS)
+ if (flag == 0)
+ {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ try
+ {
+#endif // _LIBCPP_NO_EXCEPTIONS
+ flag = 1;
+ func(arg);
+ flag = ~0ul;
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ flag = 0ul;
+ throw;
+ }
+#endif // _LIBCPP_NO_EXCEPTIONS
+ }
+#else // !_LIBCPP_HAS_NO_THREADS
pthread_mutex_lock(&mut);
while (flag == 1)
pthread_cond_wait(&cv, &mut);
@@ -248,6 +273,8 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*))
}
else
pthread_mutex_unlock(&mut);
+#endif // !_LIBCPP_HAS_NO_THREADS
+
}
_LIBCPP_END_NAMESPACE_STD
diff --git a/contrib/libc++/src/new.cpp b/contrib/libc++/src/new.cpp
index f4998cf..a88d4cc 100644
--- a/contrib/libc++/src/new.cpp
+++ b/contrib/libc++/src/new.cpp
@@ -17,7 +17,7 @@
#define __has_include(inc) 0
#endif
-#ifdef __APPLE__
+#if defined(__APPLE__) && !defined(LIBCXXRT)
#include <cxxabi.h>
#ifndef _LIBCPPABI_VERSION
@@ -167,7 +167,7 @@ set_new_handler(new_handler handler) _NOEXCEPT
new_handler
get_new_handler() _NOEXCEPT
{
- return __sync_fetch_and_add(&__new_handler, (new_handler)0);
+ return __sync_fetch_and_add(&__new_handler, nullptr);
}
#endif // !__GLIBCXX__
@@ -192,8 +192,6 @@ bad_alloc::what() const _NOEXCEPT
#endif // !__GLIBCXX__
-#endif //LIBCXXRT
-
bad_array_new_length::bad_array_new_length() _NOEXCEPT
{
}
@@ -203,6 +201,14 @@ bad_array_new_length::~bad_array_new_length() _NOEXCEPT
}
const char*
+bad_array_new_length::what() const _NOEXCEPT
+{
+ return "bad_array_new_length";
+}
+
+#endif //LIBCXXRT
+
+const char*
bad_array_length::what() const _NOEXCEPT
{
return "bad_array_length";
@@ -216,12 +222,6 @@ bad_array_length::~bad_array_length() _NOEXCEPT
{
}
-const char*
-bad_array_new_length::what() const _NOEXCEPT
-{
- return "bad_array_new_length";
-}
-
#endif // _LIBCPPABI_VERSION
#ifndef LIBSTDCXX
diff --git a/contrib/libc++/src/optional.cpp b/contrib/libc++/src/optional.cpp
index b614d81..8c5dd76 100644
--- a/contrib/libc++/src/optional.cpp
+++ b/contrib/libc++/src/optional.cpp
@@ -9,8 +9,7 @@
#include "experimental/optional"
-namespace std // purposefully not using versioning namespace
-{ namespace experimental {
+_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -22,4 +21,4 @@ bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
#endif
-}} // std::experimental
+_LIBCPP_END_NAMESPACE_EXPERIMENTAL
diff --git a/contrib/libc++/src/random.cpp b/contrib/libc++/src/random.cpp
index bd24f2e..15ed65b 100644
--- a/contrib/libc++/src/random.cpp
+++ b/contrib/libc++/src/random.cpp
@@ -11,23 +11,27 @@
// Must be defined before including stdlib.h to enable rand_s().
#define _CRT_RAND_S
#include <stdio.h>
-#endif
+#endif // defined(_WIN32)
#include "random"
#include "system_error"
-#ifdef __sun__
+#if defined(__sun__)
#define rename solaris_headers_are_broken
-#endif
+#endif // defined(__sun__)
#if !defined(_WIN32)
#include <fcntl.h>
#include <unistd.h>
-#endif // defined(_WIN32)
+#endif // !defined(_WIN32)
#include <errno.h>
+#if defined(_LIBCPP_USING_NACL_RANDOM)
+#include <nacl/nacl_random.h>
+#endif // defined(_LIBCPP_USING_NACL_RANDOM)
_LIBCPP_BEGIN_NAMESPACE_STD
#if defined(_WIN32)
+
random_device::random_device(const string&)
{
}
@@ -45,11 +49,43 @@ random_device::operator()()
__throw_system_error(err, "random_device rand_s failed.");
return r;
}
-#else
+
+#elif defined(_LIBCPP_USING_NACL_RANDOM)
+
+random_device::random_device(const string& __token)
+{
+ if (__token != "/dev/urandom")
+ __throw_system_error(ENOENT, ("random device not supported " + __token).c_str());
+ int error = nacl_secure_random_init();
+ if (error)
+ __throw_system_error(error, ("random device failed to open " + __token).c_str());
+}
+
+random_device::~random_device()
+{
+}
+
+unsigned
+random_device::operator()()
+{
+ unsigned r;
+ size_t n = sizeof(r);
+ char* p = reinterpret_cast<char*>(&r);
+ size_t bytes_written;
+ int error = nacl_secure_random(&r, n, &bytes_written);
+ if (error != 0)
+ __throw_system_error(error, "random_device failed getting bytes");
+ else if (bytes_written != n)
+ __throw_runtime_error("random_device failed to obtain enough bytes");
+ return r;
+}
+
+#else // !defined(_WIN32) && !defined(_LIBCPP_USING_NACL_RANDOM)
+
random_device::random_device(const string& __token)
: __f_(open(__token.c_str(), O_RDONLY))
{
- if (__f_ <= 0)
+ if (__f_ < 0)
__throw_system_error(errno, ("random_device failed to open " + __token).c_str());
}
@@ -62,10 +98,26 @@ unsigned
random_device::operator()()
{
unsigned r;
- read(__f_, &r, sizeof(r));
+ size_t n = sizeof(r);
+ char* p = reinterpret_cast<char*>(&r);
+ while (n > 0)
+ {
+ ssize_t s = read(__f_, p, n);
+ if (s == 0)
+ __throw_system_error(ENODATA, "random_device got EOF");
+ if (s == -1)
+ {
+ if (errno != EINTR)
+ __throw_system_error(errno, "random_device got an unexpected error");
+ continue;
+ }
+ n -= static_cast<size_t>(s);
+ p += static_cast<size_t>(s);
+ }
return r;
}
-#endif // defined(_WIN32)
+
+#endif // defined(_WIN32) || defined(_LIBCPP_USING_NACL_RANDOM)
double
random_device::entropy() const _NOEXCEPT
diff --git a/contrib/libc++/src/regex.cpp b/contrib/libc++/src/regex.cpp
index e3ec281..17dd6ea 100644
--- a/contrib/libc++/src/regex.cpp
+++ b/contrib/libc++/src/regex.cpp
@@ -69,8 +69,10 @@ regex_error::~regex_error() throw() {}
namespace {
+#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
+#endif
struct collationnames
{
@@ -78,7 +80,9 @@ struct collationnames
char char_;
};
+#if defined(__clang__)
#pragma clang diagnostic pop
+#endif
const collationnames collatenames[] =
{
@@ -195,16 +199,20 @@ const collationnames collatenames[] =
{"zero", 0x30}
};
+#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
+#endif
struct classnames
{
const char* elem_;
- ctype_base::mask mask_;
+ regex_traits<char>::char_class_type mask_;
};
+#if defined(__clang__)
#pragma clang diagnostic pop
+#endif
const classnames ClassNames[] =
{
@@ -246,12 +254,12 @@ __get_collation_name(const char* s)
return r;
}
-ctype_base::mask
+regex_traits<char>::char_class_type
__get_classname(const char* s, bool __icase)
{
const classnames* i =
_VSTD::lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp());
- ctype_base::mask r = 0;
+ regex_traits<char>::char_class_type r = 0;
if (i != end(ClassNames) && strcmp(s, i->elem_) == 0)
{
r = i->mask_;
diff --git a/contrib/libc++/src/shared_mutex.cpp b/contrib/libc++/src/shared_mutex.cpp
index 5fb22e4..2b78c1f 100644
--- a/contrib/libc++/src/shared_mutex.cpp
+++ b/contrib/libc++/src/shared_mutex.cpp
@@ -7,12 +7,15 @@
//
//===----------------------------------------------------------------------===//
+#include "__config"
+#ifndef _LIBCPP_HAS_NO_THREADS
+
#define _LIBCPP_BUILDING_SHARED_MUTEX
#include "shared_mutex"
_LIBCPP_BEGIN_NAMESPACE_STD
-shared_mutex::shared_mutex()
+shared_timed_mutex::shared_timed_mutex()
: __state_(0)
{
}
@@ -20,7 +23,7 @@ shared_mutex::shared_mutex()
// Exclusive ownership
void
-shared_mutex::lock()
+shared_timed_mutex::lock()
{
unique_lock<mutex> lk(__mut_);
while (__state_ & __write_entered_)
@@ -31,7 +34,7 @@ shared_mutex::lock()
}
bool
-shared_mutex::try_lock()
+shared_timed_mutex::try_lock()
{
unique_lock<mutex> lk(__mut_);
if (__state_ == 0)
@@ -43,7 +46,7 @@ shared_mutex::try_lock()
}
void
-shared_mutex::unlock()
+shared_timed_mutex::unlock()
{
lock_guard<mutex> _(__mut_);
__state_ = 0;
@@ -53,7 +56,7 @@ shared_mutex::unlock()
// Shared ownership
void
-shared_mutex::lock_shared()
+shared_timed_mutex::lock_shared()
{
unique_lock<mutex> lk(__mut_);
while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
@@ -64,7 +67,7 @@ shared_mutex::lock_shared()
}
bool
-shared_mutex::try_lock_shared()
+shared_timed_mutex::try_lock_shared()
{
unique_lock<mutex> lk(__mut_);
unsigned num_readers = __state_ & __n_readers_;
@@ -79,7 +82,7 @@ shared_mutex::try_lock_shared()
}
void
-shared_mutex::unlock_shared()
+shared_timed_mutex::unlock_shared()
{
lock_guard<mutex> _(__mut_);
unsigned num_readers = (__state_ & __n_readers_) - 1;
@@ -99,3 +102,5 @@ shared_mutex::unlock_shared()
_LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/libc++/src/stdexcept.cpp b/contrib/libc++/src/stdexcept.cpp
index a4207d6..aff4b18 100644
--- a/contrib/libc++/src/stdexcept.cpp
+++ b/contrib/libc++/src/stdexcept.cpp
@@ -7,123 +7,42 @@
//
//===----------------------------------------------------------------------===//
+#include "__refstring"
#include "stdexcept"
#include "new"
#include "string"
-#include <cstdlib>
-#include <cstring>
-#include <cstdint>
-#include <cstddef>
#include "system_error"
#ifndef __has_include
#define __has_include(inc) 0
#endif
-#ifdef __APPLE__
+/* For _LIBCPPABI_VERSION */
+#if __has_include(<cxxabi.h>) || defined(__APPLE_) || defined(LIBCXXRT)
#include <cxxabi.h>
-#elif defined(LIBCXXRT) || __has_include(<cxxabi.h>)
-#include <cxxabi.h>
-#endif
-
-// Note: optimize for size
-
-#if ! defined(_LIBCPP_MSVC)
-#pragma GCC visibility push(hidden)
#endif
-namespace
-{
-
-class __libcpp_nmstr
-{
-private:
- const char* str_;
-
- typedef std::size_t unused_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));
-
- count_t& count() const _NOEXCEPT {return (count_t&)(*(str_ - sizeof(count_t)));}
-public:
- explicit __libcpp_nmstr(const char* msg);
- __libcpp_nmstr(const __libcpp_nmstr& s) _NOEXCEPT;
- __libcpp_nmstr& operator=(const __libcpp_nmstr& s) _NOEXCEPT;
- ~__libcpp_nmstr();
- const char* c_str() const _NOEXCEPT {return str_;}
-};
-
-__libcpp_nmstr::__libcpp_nmstr(const char* msg)
-{
- std::size_t len = strlen(msg);
- str_ = new char[len + 1 + offset];
- unused_t* c = (unused_t*)str_;
- c[0] = c[1] = len;
- str_ += offset;
- count() = 0;
- std::memcpy(const_cast<char*>(c_str()), msg, len + 1);
-}
-
-inline
-__libcpp_nmstr::__libcpp_nmstr(const __libcpp_nmstr& s) _NOEXCEPT
- : str_(s.str_)
-{
- __sync_add_and_fetch(&count(), 1);
-}
-
-__libcpp_nmstr&
-__libcpp_nmstr::operator=(const __libcpp_nmstr& s) _NOEXCEPT
-{
- const char* p = str_;
- str_ = s.str_;
- __sync_add_and_fetch(&count(), 1);
- if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), count_t(-1)) < 0)
- delete [] (p-offset);
- return *this;
-}
-
-inline
-__libcpp_nmstr::~__libcpp_nmstr()
-{
- if (__sync_add_and_fetch(&count(), count_t(-1)) < 0)
- delete [] (str_ - offset);
-}
-
-}
-
-#if ! defined(_LIBCPP_MSVC)
-#pragma GCC visibility pop
-#endif
+static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char *), "");
namespace std // purposefully not using versioning namespace
{
-logic_error::logic_error(const string& msg)
+logic_error::logic_error(const string& msg) : __imp_(msg.c_str())
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- ::new(&s) __libcpp_nmstr(msg.c_str());
}
-logic_error::logic_error(const char* msg)
+logic_error::logic_error(const char* msg) : __imp_(msg)
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- ::new(&s) __libcpp_nmstr(msg);
}
-logic_error::logic_error(const logic_error& le) _NOEXCEPT
+logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_)
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- ::new(&s) __libcpp_nmstr((const __libcpp_nmstr&)le.__imp_);
}
logic_error&
logic_error::operator=(const logic_error& le) _NOEXCEPT
{
- __libcpp_nmstr& s1 = (__libcpp_nmstr&)__imp_;
- const __libcpp_nmstr& s2 = (const __libcpp_nmstr&)le.__imp_;
- s1 = s2;
+ __imp_ = le.__imp_;
return *this;
}
@@ -131,43 +50,33 @@ logic_error::operator=(const logic_error& le) _NOEXCEPT
logic_error::~logic_error() _NOEXCEPT
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- s.~__libcpp_nmstr();
}
const char*
logic_error::what() const _NOEXCEPT
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- return s.c_str();
+ return __imp_.c_str();
}
#endif
-runtime_error::runtime_error(const string& msg)
+runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str())
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- ::new(&s) __libcpp_nmstr(msg.c_str());
}
-runtime_error::runtime_error(const char* msg)
+runtime_error::runtime_error(const char* msg) : __imp_(msg)
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- ::new(&s) __libcpp_nmstr(msg);
}
runtime_error::runtime_error(const runtime_error& le) _NOEXCEPT
+ : __imp_(le.__imp_)
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- ::new(&s) __libcpp_nmstr((const __libcpp_nmstr&)le.__imp_);
}
runtime_error&
runtime_error::operator=(const runtime_error& le) _NOEXCEPT
{
- __libcpp_nmstr& s1 = (__libcpp_nmstr&)__imp_;
- const __libcpp_nmstr& s2 = (const __libcpp_nmstr&)le.__imp_;
- s1 = s2;
+ __imp_ = le.__imp_;
return *this;
}
@@ -175,15 +84,12 @@ runtime_error::operator=(const runtime_error& le) _NOEXCEPT
runtime_error::~runtime_error() _NOEXCEPT
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- s.~__libcpp_nmstr();
}
const char*
runtime_error::what() const _NOEXCEPT
{
- __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
- return s.c_str();
+ return __imp_.c_str();
}
domain_error::~domain_error() _NOEXCEPT {}
diff --git a/contrib/libc++/src/string.cpp b/contrib/libc++/src/string.cpp
index fde5212..febc532 100644
--- a/contrib/libc++/src/string.cpp
+++ b/contrib/libc++/src/string.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
#include "string"
#include "cstdlib"
#include "cwchar"
@@ -65,7 +63,7 @@ inline
V
as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
{
- typename S::value_type* ptr;
+ typename S::value_type* ptr = nullptr;
const typename S::value_type* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
@@ -182,7 +180,7 @@ inline
V
as_float_helper(const string& func, const S& str, size_t* idx, F f )
{
- typename S::value_type* ptr;
+ typename S::value_type* ptr = nullptr;
const typename S::value_type* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
diff --git a/contrib/libc++/src/strstream.cpp b/contrib/libc++/src/strstream.cpp
index c1965ea..ea72813 100644
--- a/contrib/libc++/src/strstream.cpp
+++ b/contrib/libc++/src/strstream.cpp
@@ -61,7 +61,7 @@ strstreambuf::strstreambuf(const char* __gnext, streamsize __n)
__palloc_(nullptr),
__pfree_(nullptr)
{
- __init((char*)__gnext, __n, nullptr);
+ __init(const_cast<char *>(__gnext), __n, nullptr);
}
strstreambuf::strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg)
@@ -70,7 +70,7 @@ strstreambuf::strstreambuf(signed char* __gnext, streamsize __n, signed char* __
__palloc_(nullptr),
__pfree_(nullptr)
{
- __init((char*)__gnext, __n, (char*)__pbeg);
+ __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
}
strstreambuf::strstreambuf(const signed char* __gnext, streamsize __n)
@@ -79,7 +79,7 @@ strstreambuf::strstreambuf(const signed char* __gnext, streamsize __n)
__palloc_(nullptr),
__pfree_(nullptr)
{
- __init((char*)__gnext, __n, nullptr);
+ __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
}
strstreambuf::strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg)
@@ -88,7 +88,7 @@ strstreambuf::strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char
__palloc_(nullptr),
__pfree_(nullptr)
{
- __init((char*)__gnext, __n, (char*)__pbeg);
+ __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
}
strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
@@ -97,7 +97,7 @@ strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
__palloc_(nullptr),
__pfree_(nullptr)
{
- __init((char*)__gnext, __n, nullptr);
+ __init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
}
strstreambuf::~strstreambuf()
@@ -186,7 +186,7 @@ strstreambuf::overflow(int_type __c)
}
*pptr() = static_cast<char>(__c);
pbump(1);
- return int_type((unsigned char)__c);
+ return int_type(static_cast<unsigned char>(__c));
}
strstreambuf::int_type
@@ -222,7 +222,7 @@ strstreambuf::underflow()
return EOF;
setg(eback(), gptr(), pptr());
}
- return int_type((unsigned char)*gptr());
+ return int_type(static_cast<unsigned char>(*gptr()));
}
strstreambuf::pos_type
diff --git a/contrib/libc++/src/system_error.cpp b/contrib/libc++/src/system_error.cpp
index b40409f..9c8adc4 100644
--- a/contrib/libc++/src/system_error.cpp
+++ b/contrib/libc++/src/system_error.cpp
@@ -7,7 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#define _LIBCPP_BUILDING_SYSTEM_ERROR
+#define _LIBCPP_BUILDING_SYSTEM_ERROR
+#include "__config"
#include "system_error"
#include "string"
#include "cstring"
@@ -65,10 +66,10 @@ __generic_error_category::name() const _NOEXCEPT
string
__generic_error_category::message(int ev) const
{
-#ifdef ELAST
- if (ev > ELAST)
+#ifdef _LIBCPP_ELAST
+ if (ev > _LIBCPP_ELAST)
return string("unspecified generic_category error");
-#endif // ELAST
+#endif // _LIBCPP_ELAST
return __do_message::message(ev);
}
@@ -97,20 +98,20 @@ __system_error_category::name() const _NOEXCEPT
string
__system_error_category::message(int ev) const
{
-#ifdef ELAST
- if (ev > ELAST)
+#ifdef _LIBCPP_ELAST
+ if (ev > _LIBCPP_ELAST)
return string("unspecified system_category error");
-#endif // ELAST
+#endif // _LIBCPP_ELAST
return __do_message::message(ev);
}
error_condition
__system_error_category::default_error_condition(int ev) const _NOEXCEPT
{
-#ifdef ELAST
- if (ev > ELAST)
+#ifdef _LIBCPP_ELAST
+ if (ev > _LIBCPP_ELAST)
return error_condition(ev, system_category());
-#endif // ELAST
+#endif // _LIBCPP_ELAST
return error_condition(ev, generic_category());
}
diff --git a/contrib/libc++/src/thread.cpp b/contrib/libc++/src/thread.cpp
index 338a8a2..6aad558 100644
--- a/contrib/libc++/src/thread.cpp
+++ b/contrib/libc++/src/thread.cpp
@@ -7,6 +7,9 @@
//
//===----------------------------------------------------------------------===//
+#include "__config"
+#ifndef _LIBCPP_HAS_NO_THREADS
+
#include "thread"
#include "exception"
#include "vector"
@@ -14,10 +17,10 @@
#include "limits"
#include <sys/types.h>
#if !defined(_WIN32)
-#if !defined(__sun__) && !defined(__linux__) && !defined(_AIX)
-#include <sys/sysctl.h>
-#endif // !__sun__ && !__linux__ && !_AIX
-#include <unistd.h>
+# if !defined(__sun__) && !defined(__linux__) && !defined(_AIX) && !defined(__native_client__)
+# include <sys/sysctl.h>
+# endif // !defined(__sun__) && !defined(__linux__) && !defined(_AIX) && !defined(__native_client__)
+# include <unistd.h>
#endif // !_WIN32
#if defined(__NetBSD__)
@@ -121,7 +124,9 @@ sleep_for(const chrono::nanoseconds& ns)
ts.tv_sec = ts_sec_max;
ts.tv_nsec = giga::num - 1;
}
- nanosleep(&ts, 0);
+
+ while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
+ ;
}
}
@@ -144,7 +149,7 @@ public:
T* allocate(size_t __n)
{return static_cast<T*>(::operator new(__n * sizeof(T)));}
- void deallocate(T* __p, size_t) {::operator delete((void*)__p);}
+ void deallocate(T* __p, size_t) {::operator delete(static_cast<void*>(__p));}
size_t max_size() const {return size_t(~0) / sizeof(T);}
};
@@ -223,3 +228,5 @@ __thread_struct::__make_ready_at_thread_exit(__assoc_sub_state* __s)
}
_LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_HAS_NO_THREADS
diff --git a/contrib/libc++/src/valarray.cpp b/contrib/libc++/src/valarray.cpp
index e4c9ed0..2d8db52 100644
--- a/contrib/libc++/src/valarray.cpp
+++ b/contrib/libc++/src/valarray.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
-
#include "valarray"
_LIBCPP_BEGIN_NAMESPACE_STD
OpenPOWER on IntegriCloud