diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:03:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:03:23 +0000 |
commit | 0dc0969cd0a732760f0aa79942a04e0eaef297c4 (patch) | |
tree | 051bdb57b1ac6ee143f61ddbb47bd0da619f6f0c /src | |
parent | 868847c6900e575417c03bced6e562b3af891318 (diff) |
Notes
Diffstat (limited to 'src')
24 files changed, 878 insertions, 634 deletions
diff --git a/src/condition_variable.cpp b/src/condition_variable.cpp index 25e66038eec0b..3f607271b9ebf 100644 --- a/src/condition_variable.cpp +++ b/src/condition_variable.cpp @@ -14,7 +14,6 @@ #include "condition_variable" #include "thread" #include "system_error" -#include "cassert" _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/src/exception.cpp b/src/exception.cpp index f25041d834276..0b502cd134c07 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -6,328 +6,31 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include <stdlib.h> -#include <stdio.h> #include "exception" #include "new" +#include "typeinfo" -#if defined(_LIBCPP_ABI_MICROSOFT) -#include <eh.h> -#include <corecrt_terminate.h> -#elif defined(__APPLE__) && !defined(LIBCXXRT) && \ - !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) +#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) || \ + (defined(__APPLE__) && !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)) #include <cxxabi.h> - using namespace __cxxabiv1; #define HAVE_DEPENDENT_EH_ABI 1 - #ifndef _LIBCPPABI_VERSION - using namespace __cxxabiapple; - // On Darwin, there are two STL shared libraries and a lower level ABI - // shared library. The globals holding the current terminate handler and - // current unexpected handler are in the ABI library. - #define __terminate_handler __cxxabiapple::__cxa_terminate_handler - #define __unexpected_handler __cxxabiapple::__cxa_unexpected_handler - #endif // _LIBCPPABI_VERSION -#elif defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) - #include <cxxabi.h> - using namespace __cxxabiv1; - #if defined(LIBCXXRT) || defined(_LIBCPPABI_VERSION) - #define HAVE_DEPENDENT_EH_ABI 1 - #endif -#elif !defined(__GLIBCXX__) // defined(LIBCXX_BUILDING_LIBCXXABI) - _LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler; - _LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler; -#endif // defined(LIBCXX_BUILDING_LIBCXXABI) - -namespace std -{ - -#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) - -// libcxxrt provides implementations of these functions itself. -unexpected_handler -set_unexpected(unexpected_handler func) _NOEXCEPT -{ -#if defined(_LIBCPP_ABI_MICROSOFT) - return ::set_unexpected(func); -#else - return __sync_lock_test_and_set(&__unexpected_handler, func); -#endif -} - -unexpected_handler -get_unexpected() _NOEXCEPT -{ -#if defined(_LIBCPP_ABI_MICROSOFT) - return ::_get_unexpected(); -#else - return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); -#endif -} - -_LIBCPP_NORETURN -void -unexpected() -{ - (*get_unexpected())(); - // unexpected handler should not return - terminate(); -} - -terminate_handler -set_terminate(terminate_handler func) _NOEXCEPT -{ -#if defined(_LIBCPP_ABI_MICROSOFT) - return ::set_terminate(func); -#else - return __sync_lock_test_and_set(&__terminate_handler, func); #endif -} -terminate_handler -get_terminate() _NOEXCEPT -{ #if defined(_LIBCPP_ABI_MICROSOFT) - return ::_get_terminate(); -#else - return __sync_fetch_and_add(&__terminate_handler, (terminate_handler)0); -#endif -} - -#ifndef __EMSCRIPTEN__ // We provide this in JS -_LIBCPP_NORETURN -void -terminate() _NOEXCEPT -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - (*get_terminate())(); - // handler should not return - fprintf(stderr, "terminate_handler unexpectedly returned\n"); - ::abort(); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - // handler should not throw exception - fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); - ::abort(); - } -#endif // _LIBCPP_NO_EXCEPTIONS -} -#endif // !__EMSCRIPTEN__ -#endif // !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) - -#if !defined(LIBCXXRT) && !defined(__GLIBCXX__) && !defined(__EMSCRIPTEN__) - -bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } - -int uncaught_exceptions() _NOEXCEPT -{ -#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ - (defined(__APPLE__) || defined(_LIBCPPABI_VERSION)) - // on Darwin, there is a helper function so __cxa_get_globals is private -# if _LIBCPPABI_VERSION > 1101 - return __cxa_uncaught_exceptions(); -# else - return __cxa_uncaught_exception() ? 1 : 0; -# endif -#elif defined(_LIBCPP_ABI_MICROSOFT) - return __uncaught_exceptions(); -#else -# if defined(_MSC_VER) && ! defined(__clang__) - _LIBCPP_WARNING("uncaught_exceptions not yet implemented") -# else -# warning uncaught_exception not yet implemented -# endif - fprintf(stderr, "uncaught_exceptions not yet implemented\n"); - ::abort(); -#endif // __APPLE__ -} - - -#ifndef _LIBCPPABI_VERSION - -exception::~exception() _NOEXCEPT -{ -} - -const char* exception::what() const _NOEXCEPT -{ - return "std::exception"; -} - -#endif // _LIBCPPABI_VERSION -#endif //LIBCXXRT -#if !defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__) - -bad_exception::~bad_exception() _NOEXCEPT -{ -} - -const char* bad_exception::what() const _NOEXCEPT -{ - return "std::bad_exception"; -} - -#endif - -#if defined(__GLIBCXX__) - -// libsupc++ does not implement the dependent EH ABI and the functionality -// it uses to implement std::exception_ptr (which it declares as an alias of -// std::__exception_ptr::exception_ptr) is not directly exported to clients. So -// we have little choice but to hijack std::__exception_ptr::exception_ptr's -// (which fortunately has the same layout as our std::exception_ptr) copy -// constructor, assignment operator and destructor (which are part of its -// stable ABI), and its rethrow_exception(std::__exception_ptr::exception_ptr) -// function. - -namespace __exception_ptr -{ - -struct exception_ptr -{ - void* __ptr_; - - exception_ptr(const exception_ptr&) _NOEXCEPT; - exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; - ~exception_ptr() _NOEXCEPT; -}; - -} - -_LIBCPP_NORETURN void rethrow_exception(__exception_ptr::exception_ptr); - -#endif - -exception_ptr::~exception_ptr() _NOEXCEPT -{ -#if HAVE_DEPENDENT_EH_ABI - __cxa_decrement_exception_refcount(__ptr_); -#elif defined(__GLIBCXX__) - reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); -#else -# if defined(_MSC_VER) && ! defined(__clang__) - _LIBCPP_WARNING("exception_ptr not yet implemented") -# else -# warning exception_ptr not yet implemented -# endif - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); -#endif -} - -exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT - : __ptr_(other.__ptr_) -{ -#if HAVE_DEPENDENT_EH_ABI - __cxa_increment_exception_refcount(__ptr_); -#elif defined(__GLIBCXX__) - new (reinterpret_cast<void*>(this)) __exception_ptr::exception_ptr( - reinterpret_cast<const __exception_ptr::exception_ptr&>(other)); -#else -# if defined(_MSC_VER) && ! defined(__clang__) - _LIBCPP_WARNING("exception_ptr not yet implemented") -# else -# warning exception_ptr not yet implemented -# endif - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); -#endif -} - -exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT -{ -#if HAVE_DEPENDENT_EH_ABI - if (__ptr_ != other.__ptr_) - { - __cxa_increment_exception_refcount(other.__ptr_); - __cxa_decrement_exception_refcount(__ptr_); - __ptr_ = other.__ptr_; - } - return *this; -#elif defined(__GLIBCXX__) - *reinterpret_cast<__exception_ptr::exception_ptr*>(this) = - reinterpret_cast<const __exception_ptr::exception_ptr&>(other); - return *this; -#else -# if defined(_MSC_VER) && ! defined(__clang__) - _LIBCPP_WARNING("exception_ptr not yet implemented") -# else -# warning exception_ptr not yet implemented -# endif - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); -#endif -} - -nested_exception::nested_exception() _NOEXCEPT - : __ptr_(current_exception()) -{ -} - -#if !defined(__GLIBCXX__) - -nested_exception::~nested_exception() _NOEXCEPT -{ -} - -#endif - -_LIBCPP_NORETURN -void -nested_exception::rethrow_nested() const -{ - if (__ptr_ == nullptr) - terminate(); - rethrow_exception(__ptr_); -} - -#if !defined(__GLIBCXX__) - -exception_ptr current_exception() _NOEXCEPT -{ -#if HAVE_DEPENDENT_EH_ABI - // be nicer if there was a constructor that took a ptr, then - // this whole function would be just: - // return exception_ptr(__cxa_current_primary_exception()); - exception_ptr ptr; - ptr.__ptr_ = __cxa_current_primary_exception(); - return ptr; -#else -# if defined(_MSC_VER) && ! defined(__clang__) - _LIBCPP_WARNING( "exception_ptr not yet implemented" ) -# else -# warning exception_ptr not yet implemented -# endif - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); -#endif -} - -#endif // !__GLIBCXX__ - -_LIBCPP_NORETURN -void rethrow_exception(exception_ptr p) -{ -#if HAVE_DEPENDENT_EH_ABI - __cxa_rethrow_primary_exception(p.__ptr_); - // if p.__ptr_ is NULL, above returns so we terminate - terminate(); +#include "support/runtime/exception_msvc.ipp" +#include "support/runtime/exception_pointer_unimplemented.ipp" +#elif defined(_LIBCPPABI_VERSION) +#include "support/runtime/exception_libcxxabi.ipp" +#include "support/runtime/exception_pointer_cxxabi.ipp" +#elif defined(LIBCXXRT) +#include "support/runtime/exception_libcxxrt.ipp" +#include "support/runtime/exception_pointer_cxxabi.ipp" #elif defined(__GLIBCXX__) - rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p)); +#include "support/runtime/exception_glibcxx.ipp" +#include "support/runtime/exception_pointer_glibcxx.ipp" #else -# if defined(_MSC_VER) && ! defined(__clang__) - _LIBCPP_WARNING("exception_ptr not yet implemented") -# else -# warning exception_ptr not yet implemented -# endif - fprintf(stderr, "exception_ptr not yet implemented\n"); - ::abort(); +#include "support/runtime/exception_fallback.ipp" +#include "support/runtime/exception_pointer_unimplemented.ipp" #endif -} -} // std diff --git a/src/experimental/filesystem/directory_iterator.cpp b/src/experimental/filesystem/directory_iterator.cpp index a888dcfa1190e..25135857d40cb 100644 --- a/src/experimental/filesystem/directory_iterator.cpp +++ b/src/experimental/filesystem/directory_iterator.cpp @@ -1,28 +1,32 @@ +//===------------------ directory_iterator.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 "experimental/filesystem" +#include "__config" +#if defined(_LIBCPP_WIN32API) +#define WIN32_LEAN_AND_MEAN +#include <Windows.h> +#else #include <dirent.h> +#endif #include <errno.h> _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM namespace { namespace detail { +#if !defined(_LIBCPP_WIN32API) inline error_code capture_errno() { _LIBCPP_ASSERT(errno, "Expected errno to be non-zero"); return error_code{errno, std::generic_category()}; } - -template <class ...Args> -inline bool capture_error_or_throw(std::error_code* user_ec, - const char* msg, Args&&... args) -{ - std::error_code my_ec = capture_errno(); - if (user_ec) { - *user_ec = my_ec; - return true; - } - __throw_filesystem_error(msg, std::forward<Args>(args)..., my_ec); - return false; -} +#endif template <class ...Args> inline bool set_or_throw(std::error_code& my_ec, @@ -37,25 +41,87 @@ inline bool set_or_throw(std::error_code& my_ec, return false; } -typedef path::string_type string_type; - - -inline string_type posix_readdir(DIR *dir_stream, error_code& ec) { +#if !defined(_LIBCPP_WIN32API) +inline path::string_type posix_readdir(DIR *dir_stream, error_code& ec) { struct dirent* dir_entry_ptr = nullptr; errno = 0; // zero errno in order to detect errors + ec.clear(); if ((dir_entry_ptr = ::readdir(dir_stream)) == nullptr) { - ec = capture_errno(); + if (errno) + ec = capture_errno(); return {}; } else { - ec.clear(); return dir_entry_ptr->d_name; } } +#endif }} // namespace detail using detail::set_or_throw; +#if defined(_LIBCPP_WIN32API) +class __dir_stream { +public: + __dir_stream() = delete; + __dir_stream& operator=(const __dir_stream&) = delete; + + __dir_stream(__dir_stream&& __ds) noexcept + : __stream_(__ds.__stream_), __root_(std::move(__ds.__root_)), + __entry_(std::move(__ds.__entry_)) { + __ds.__stream_ = INVALID_HANDLE_VALUE; + } + + __dir_stream(const path& root, directory_options opts, error_code& ec) + : __stream_(INVALID_HANDLE_VALUE), __root_(root) { + __stream_ = ::FindFirstFile(root.c_str(), &__data_); + if (__stream_ == INVALID_HANDLE_VALUE) { + ec = error_code(::GetLastError(), std::generic_category()); + const bool ignore_permission_denied = + bool(opts & directory_options::skip_permission_denied); + if (ignore_permission_denied && ec.value() == ERROR_ACCESS_DENIED) + ec.clear(); + return; + } + } + + ~__dir_stream() noexcept { + if (__stream_ == INVALID_HANDLE_VALUE) + return; + close(); + } + + bool good() const noexcept { return __stream_ != INVALID_HANDLE_VALUE; } + + bool advance(error_code& ec) { + while (::FindNextFile(__stream_, &__data_)) { + if (!strcmp(__data_.cFileName, ".") || strcmp(__data_.cFileName, "..")) + continue; + __entry_.assign(__root_ / __data_.cFileName); + return true; + } + ec = error_code(::GetLastError(), std::generic_category()); + close(); + return false; + } + +private: + std::error_code close() noexcept { + std::error_code ec; + if (!::FindClose(__stream_)) + ec = error_code(::GetLastError(), std::generic_category()); + __stream_ = INVALID_HANDLE_VALUE; + return ec; + } + + HANDLE __stream_{INVALID_HANDLE_VALUE}; + WIN32_FIND_DATA __data_; + +public: + path __root_; + directory_entry __entry_; +}; +#else class __dir_stream { public: __dir_stream() = delete; @@ -117,6 +183,7 @@ public: path __root_; directory_entry __entry_; }; +#endif // directory_iterator @@ -149,7 +216,7 @@ directory_iterator& directory_iterator::__increment(error_code *ec) } -directory_entry const& directory_iterator::__deref() const { +directory_entry const& directory_iterator::__dereference() const { _LIBCPP_ASSERT(__imp_, "Attempting to dereference an invalid iterator"); return __imp_->__entry_; } @@ -195,7 +262,7 @@ int recursive_directory_iterator::depth() const { return __imp_->__stack_.size() - 1; } -const directory_entry& recursive_directory_iterator::__deref() const { +const directory_entry& recursive_directory_iterator::__dereference() const { return __imp_->__stack_.top().__entry_; } diff --git a/src/experimental/filesystem/operations.cpp b/src/experimental/filesystem/operations.cpp index 6c7e4cf24888b..bd7685819ecae 100644 --- a/src/experimental/filesystem/operations.cpp +++ b/src/experimental/filesystem/operations.cpp @@ -35,12 +35,9 @@ namespace detail { namespace { using value_type = path::value_type; using string_type = path::string_type; - - inline std::error_code capture_errno() { - _LIBCPP_ASSERT(errno, "Expected errno to be non-zero"); - std::error_code m_ec(errno, std::generic_category()); - return m_ec; + _LIBCPP_ASSERT(errno, "Expected errno to be non-zero"); + return std::error_code(errno, std::generic_category()); } void set_or_throw(std::error_code const& m_ec, std::error_code* ec, @@ -886,23 +883,28 @@ path __system_complete(const path& p, std::error_code *ec) { return absolute(p, current_path()); } -path __temp_directory_path(std::error_code *ec) { - const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"}; - const char* ret = nullptr; - for (auto & ep : env_paths) { - if ((ret = std::getenv(ep))) - break; - } - path p(ret ? ret : "/tmp"); - std::error_code m_ec; - if (is_directory(p, m_ec)) { - if (ec) ec->clear(); - return p; - } +path __temp_directory_path(std::error_code* ec) { + const char* env_paths[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"}; + const char* ret = nullptr; + + for (auto& ep : env_paths) + if ((ret = std::getenv(ep))) + break; + if (ret == nullptr) + ret = "/tmp"; + + path p(ret); + std::error_code m_ec; + if (!exists(p, m_ec) || !is_directory(p, m_ec)) { if (!m_ec || m_ec == make_error_code(errc::no_such_file_or_directory)) - m_ec = make_error_code(errc::not_a_directory); + m_ec = make_error_code(errc::not_a_directory); set_or_throw(m_ec, ec, "temp_directory_path"); return {}; + } + + if (ec) + ec->clear(); + return p; } // An absolute path is composed according to the table in [fs.op.absolute]. diff --git a/src/experimental/filesystem/path.cpp b/src/experimental/filesystem/path.cpp index 96b81f7b0a70e..f49d4cd2d418f 100644 --- a/src/experimental/filesystem/path.cpp +++ b/src/experimental/filesystem/path.cpp @@ -6,11 +6,9 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#undef NDEBUG #include "experimental/filesystem" #include "string_view" #include "utility" -#include "cassert" namespace { namespace parser { @@ -58,13 +56,13 @@ public: } PosPtr peek() const noexcept { - auto End = &Path.back() + 1; auto TkEnd = getNextTokenStartPos(); + auto End = getAfterBack(); return TkEnd == End ? nullptr : TkEnd; } void increment() noexcept { - const PosPtr End = &Path.back() + 1; + const PosPtr End = getAfterBack(); const PosPtr Start = getNextTokenStartPos(); if (Start == End) return makeState(PS_AtEnd); @@ -111,9 +109,8 @@ public: } void decrement() noexcept { - const PosPtr REnd = &Path.front() - 1; + const PosPtr REnd = getBeforeFront(); const PosPtr RStart = getCurrentTokenStartPos() - 1; - assert(RStart != REnd); switch (State) { case PS_AtEnd: { @@ -198,19 +195,27 @@ private: RawEntry = {}; } + PosPtr getAfterBack() const noexcept { + return Path.data() + Path.size(); + } + + PosPtr getBeforeFront() const noexcept { + return Path.data() - 1; + } + /// \brief Return a pointer to the first character after the currently /// lexed element. PosPtr getNextTokenStartPos() const noexcept { switch (State) { case PS_BeforeBegin: - return &Path.front(); + return Path.data(); case PS_InRootName: case PS_InRootDir: case PS_InFilenames: return &RawEntry.back() + 1; case PS_InTrailingSep: case PS_AtEnd: - return &Path.back() + 1; + return getAfterBack(); } _LIBCPP_UNREACHABLE(); } @@ -322,7 +327,6 @@ string_view_t path::__root_path_raw() const auto NextCh = PP.peek(); if (NextCh && *NextCh == '/') { ++PP; - assert(PP.State == PathParser::PS_InRootDir); return createView(__pn_.data(), &PP.RawEntry.back()); } return PP.RawEntry; diff --git a/src/functional.cpp b/src/functional.cpp new file mode 100644 index 0000000000000..5c2646f01b2e5 --- /dev/null +++ b/src/functional.cpp @@ -0,0 +1,26 @@ +//===----------------------- functional.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 "functional" + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +bad_function_call::~bad_function_call() _NOEXCEPT +{ +} + +const char* +bad_function_call::what() const _NOEXCEPT +{ + return "std::bad_function_call"; +} +#endif + +_LIBCPP_END_NAMESPACE_STD diff --git a/src/include/atomic_support.h b/src/include/atomic_support.h index af0f5f505ea54..378541b232562 100644 --- a/src/include/atomic_support.h +++ b/src/include/atomic_support.h @@ -29,7 +29,7 @@ #endif #if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS) -# if defined(_MSC_VER) && !defined(__clang__) +# if defined(_LIBCPP_MSVC) _LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported") # else # warning Building libc++ without __atomic builtins is unsupported diff --git a/src/locale.cpp b/src/locale.cpp index 338ffde3f5b7f..1460f9662e354 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -579,10 +579,8 @@ locale::global(const locale& loc) locale& g = __global(); locale r = g; g = loc; -#ifndef __CloudABI__ if (g.name() != "*") setlocale(LC_ALL, g.name().c_str()); -#endif return r; } @@ -1111,13 +1109,7 @@ ctype<char>::classic_table() _NOEXCEPT #elif __sun__ return __ctype_mask; #elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) -#if _VC_CRT_MAJOR_VERSION < 14 - // This is assumed to be safe, which is a nonsense assumption because we're - // going to end up dereferencing it later... - return _ctype+1; // internal ctype mask table defined in msvcrt.dll -#else return __pctype_func(); -#endif #elif defined(__EMSCRIPTEN__) return *__ctype_b_loc(); #elif defined(_NEWLIB_VERSION) diff --git a/src/memory.cpp b/src/memory.cpp index 8569fafb337c7..f6f6fe8da6281 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -17,28 +17,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD -namespace -{ - -// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively) -// should be sufficient for thread safety. -// See https://llvm.org/bugs/show_bug.cgi?id=22803 -template <class T> -inline T -increment(T& t) _NOEXCEPT -{ - return __libcpp_atomic_add(&t, 1, _AO_Relaxed); -} - -template <class T> -inline T -decrement(T& t) _NOEXCEPT -{ - return __libcpp_atomic_add(&t, -1, _AO_Acq_Rel); -} - -} // namespace - const allocator_arg_t allocator_arg = allocator_arg_t(); bad_weak_ptr::~bad_weak_ptr() _NOEXCEPT {} @@ -53,16 +31,21 @@ __shared_count::~__shared_count() { } +__shared_weak_count::~__shared_weak_count() +{ +} + +#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) void __shared_count::__add_shared() _NOEXCEPT { - increment(__shared_owners_); + __libcpp_atomic_refcount_increment(__shared_owners_); } bool __shared_count::__release_shared() _NOEXCEPT { - if (decrement(__shared_owners_) == -1) + if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) { __on_zero_shared(); return true; @@ -70,10 +53,6 @@ __shared_count::__release_shared() _NOEXCEPT return false; } -__shared_weak_count::~__shared_weak_count() -{ -} - void __shared_weak_count::__add_shared() _NOEXCEPT { @@ -83,7 +62,7 @@ __shared_weak_count::__add_shared() _NOEXCEPT void __shared_weak_count::__add_weak() _NOEXCEPT { - increment(__shared_weak_owners_); + __libcpp_atomic_refcount_increment(__shared_weak_owners_); } void @@ -93,6 +72,8 @@ __shared_weak_count::__release_shared() _NOEXCEPT __release_weak(); } +#endif // _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS + void __shared_weak_count::__release_weak() _NOEXCEPT { @@ -124,7 +105,7 @@ __shared_weak_count::__release_weak() _NOEXCEPT //__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release); __on_zero_shared_weak(); } - else if (decrement(__shared_weak_owners_) == -1) + else if (__libcpp_atomic_refcount_decrement(__shared_weak_owners_) == -1) __on_zero_shared_weak(); } diff --git a/src/mutex.cpp b/src/mutex.cpp index 9397ae73ca4f3..b858e8877ae5c 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -11,7 +11,6 @@ #include "mutex" #include "limits" #include "system_error" -#include "cassert" #include "include/atomic_support.h" _LIBCPP_BEGIN_NAMESPACE_STD @@ -37,7 +36,7 @@ mutex::lock() bool mutex::try_lock() _NOEXCEPT { - return __libcpp_mutex_trylock(&__m_) == 0; + return __libcpp_mutex_trylock(&__m_); } void @@ -45,7 +44,7 @@ mutex::unlock() _NOEXCEPT { int ec = __libcpp_mutex_unlock(&__m_); (void)ec; - assert(ec == 0); + _LIBCPP_ASSERT(ec == 0, "call to mutex::unlock failed"); } // recursive_mutex @@ -61,7 +60,7 @@ recursive_mutex::~recursive_mutex() { int e = __libcpp_recursive_mutex_destroy(&__m_); (void)e; - assert(e == 0); + _LIBCPP_ASSERT(e == 0, "call to ~recursive_mutex() failed"); } void @@ -77,13 +76,13 @@ recursive_mutex::unlock() _NOEXCEPT { int e = __libcpp_recursive_mutex_unlock(&__m_); (void)e; - assert(e == 0); + _LIBCPP_ASSERT(e == 0, "call to recursive_mutex::unlock() failed"); } bool recursive_mutex::try_lock() _NOEXCEPT { - return __libcpp_recursive_mutex_trylock(&__m_) == 0; + return __libcpp_recursive_mutex_trylock(&__m_); } // timed_mutex diff --git a/src/new.cpp b/src/new.cpp index b1e8ee324d84e..21b30740196b0 100644 --- a/src/new.cpp +++ b/src/new.cpp @@ -13,27 +13,48 @@ #include "new" -#if defined(__APPLE__) && !defined(LIBCXXRT) && \ - !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) - #include <cxxabi.h> - - #ifndef _LIBCPPABI_VERSION - // On Darwin, there are two STL shared libraries and a lower level ABI - // shared library. The global holding the current new handler is - // in the ABI library and named __cxa_new_handler. - #define __new_handler __cxxabiapple::__cxa_new_handler - #endif -#else // __APPLE__ - #if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) - #include <cxxabi.h> - #endif // defined(LIBCXX_BUILDING_LIBCXXABI) - #if defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) || \ - (!defined(_LIBCPPABI_VERSION) && !defined(__GLIBCXX__)) - static std::new_handler __new_handler; - #endif // _LIBCPPABI_VERSION +#if defined(_LIBCPP_ABI_MICROSOFT) +// nothing todo +#elif defined(LIBCXX_BUILDING_LIBCXXABI) +#include <cxxabi.h> +#elif defined(LIBCXXRT) +#include <cxxabi.h> +#include "support/runtime/new_handler_fallback.ipp" +#elif defined(__GLIBCXX__) +// nothing todo +#else +# if defined(__APPLE__) && !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) +# include <cxxabi.h> // FIXME: remove this once buildit is gone. +# else +# include "support/runtime/new_handler_fallback.ipp" +# endif #endif +namespace std +{ + #ifndef __GLIBCXX__ +const nothrow_t nothrow = {}; +#endif + +#ifndef LIBSTDCXX + +void +__throw_bad_alloc() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_alloc(); +#else + _VSTD::abort(); +#endif +} + +#endif // !LIBSTDCXX + +} // std + +#if !defined(__GLIBCXX__) && !defined(_LIBCPP_ABI_MICROSOFT) && \ + !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) // Implement all new and delete operators as weak definitions // in this shared library, so that they can be overridden by programs @@ -277,107 +298,5 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT ::operator delete[](ptr, alignment); } -#endif // !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) - -#endif // !__GLIBCXX__ - -namespace std -{ - -#ifndef __GLIBCXX__ -const nothrow_t nothrow = {}; -#endif - -#ifndef _LIBCPPABI_VERSION - -#ifndef __GLIBCXX__ - -new_handler -set_new_handler(new_handler handler) _NOEXCEPT -{ - return __sync_lock_test_and_set(&__new_handler, handler); -} - -new_handler -get_new_handler() _NOEXCEPT -{ - return __sync_fetch_and_add(&__new_handler, nullptr); -} - -#endif // !__GLIBCXX__ - -#ifndef LIBCXXRT - -bad_alloc::bad_alloc() _NOEXCEPT -{ -} - -#ifndef __GLIBCXX__ - -bad_alloc::~bad_alloc() _NOEXCEPT -{ -} - -const char* -bad_alloc::what() const _NOEXCEPT -{ - return "std::bad_alloc"; -} - -#endif // !__GLIBCXX__ - -bad_array_new_length::bad_array_new_length() _NOEXCEPT -{ -} - -#ifndef __GLIBCXX__ - -bad_array_new_length::~bad_array_new_length() _NOEXCEPT -{ -} - -const char* -bad_array_new_length::what() const _NOEXCEPT -{ - return "bad_array_new_length"; -} - -#endif // !__GLIBCXX__ - -#endif //LIBCXXRT - -bad_array_length::bad_array_length() _NOEXCEPT -{ -} - -#ifndef __GLIBCXX__ - -bad_array_length::~bad_array_length() _NOEXCEPT -{ -} - -const char* -bad_array_length::what() const _NOEXCEPT -{ - return "bad_array_length"; -} - -#endif // !__GLIBCXX__ - -#endif // _LIBCPPABI_VERSION - -#ifndef LIBSTDCXX - -void -__throw_bad_alloc() -{ -#ifndef _LIBCPP_NO_EXCEPTIONS - throw bad_alloc(); -#else - _VSTD::abort(); -#endif -} - -#endif // !LIBSTDCXX - -} // std +#endif // !_LIBCPP_HAS_NO_ALIGNED_ALLOCATION +#endif // !__GLIBCXX__ && !_LIBCPP_ABI_MICROSOFT && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS diff --git a/src/support/runtime/exception_fallback.ipp b/src/support/runtime/exception_fallback.ipp new file mode 100644 index 0000000000000..69c06a9ce3a8a --- /dev/null +++ b/src/support/runtime/exception_fallback.ipp @@ -0,0 +1,182 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <cstdio> + +namespace std { + +_LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler; +_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler; + + +// libcxxrt provides implementations of these functions itself. +unexpected_handler +set_unexpected(unexpected_handler func) _NOEXCEPT +{ + return __sync_lock_test_and_set(&__unexpected_handler, func); +} + +unexpected_handler +get_unexpected() _NOEXCEPT +{ + return __sync_fetch_and_add(&__unexpected_handler, (unexpected_handler)0); + +} + +_LIBCPP_NORETURN +void unexpected() +{ + (*get_unexpected())(); + // unexpected handler should not return + terminate(); +} + +terminate_handler +set_terminate(terminate_handler func) _NOEXCEPT +{ + return __sync_lock_test_and_set(&__terminate_handler, func); +} + +terminate_handler +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 +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + (*get_terminate())(); + // handler should not return + fprintf(stderr, "terminate_handler unexpectedly returned\n"); + ::abort(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + // handler should not throw exception + fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); + ::abort(); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} +#endif // !__EMSCRIPTEN__ + +#if !defined(__EMSCRIPTEN__) +bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } + +int uncaught_exceptions() _NOEXCEPT +{ +#warning uncaught_exception not yet implemented + fprintf(stderr, "uncaught_exceptions not yet implemented\n"); + ::abort(); +} +#endif // !__EMSCRIPTEN__ + + +exception::~exception() _NOEXCEPT +{ +} + +const char* exception::what() const _NOEXCEPT +{ + return "std::exception"; +} + +bad_exception::~bad_exception() _NOEXCEPT +{ +} + +const char* bad_exception::what() const _NOEXCEPT +{ + return "std::bad_exception"; +} + + +bad_alloc::bad_alloc() _NOEXCEPT +{ +} + +bad_alloc::~bad_alloc() _NOEXCEPT +{ +} + +const char* +bad_alloc::what() const _NOEXCEPT +{ + return "std::bad_alloc"; +} + +bad_array_new_length::bad_array_new_length() _NOEXCEPT +{ +} + +bad_array_new_length::~bad_array_new_length() _NOEXCEPT +{ +} + +const char* +bad_array_new_length::what() const _NOEXCEPT +{ + return "bad_array_new_length"; +} + + +bad_array_length::bad_array_length() _NOEXCEPT +{ +} + +bad_array_length::~bad_array_length() _NOEXCEPT +{ +} + +const char* +bad_array_length::what() const _NOEXCEPT +{ + return "bad_array_length"; +} + + +bad_cast::bad_cast() _NOEXCEPT +{ +} + +bad_typeid::bad_typeid() _NOEXCEPT +{ +} + +bad_cast::~bad_cast() _NOEXCEPT +{ +} + +const char* +bad_cast::what() const _NOEXCEPT +{ + return "std::bad_cast"; +} + +bad_typeid::~bad_typeid() _NOEXCEPT +{ +} + +const char* +bad_typeid::what() const _NOEXCEPT +{ + return "std::bad_typeid"; +} + +} // namespace std diff --git a/src/support/runtime/exception_glibcxx.ipp b/src/support/runtime/exception_glibcxx.ipp new file mode 100644 index 0000000000000..0f78932f6f981 --- /dev/null +++ b/src/support/runtime/exception_glibcxx.ipp @@ -0,0 +1,38 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef __GLIBCXX__ +#error header can only be used when targeting libstdc++ or libsupc++ +#endif + +namespace std { + +bad_alloc::bad_alloc() _NOEXCEPT +{ +} + +bad_array_new_length::bad_array_new_length() _NOEXCEPT +{ +} + +bad_array_length::bad_array_length() _NOEXCEPT +{ +} + + +bad_cast::bad_cast() _NOEXCEPT +{ +} + +bad_typeid::bad_typeid() _NOEXCEPT +{ +} + +} // namespace std diff --git a/src/support/runtime/exception_libcxxabi.ipp b/src/support/runtime/exception_libcxxabi.ipp new file mode 100644 index 0000000000000..c3dcf1ec591a9 --- /dev/null +++ b/src/support/runtime/exception_libcxxabi.ipp @@ -0,0 +1,28 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPPABI_VERSION +#error this header can only be used with libc++abi +#endif + +namespace std { + +bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } + +int uncaught_exceptions() _NOEXCEPT +{ +# if _LIBCPPABI_VERSION > 1101 + return __cxa_uncaught_exceptions(); +# else + return __cxa_uncaught_exception() ? 1 : 0; +# endif +} + +} // namespace std diff --git a/src/support/runtime/exception_libcxxrt.ipp b/src/support/runtime/exception_libcxxrt.ipp new file mode 100644 index 0000000000000..6d9e0cff58dc6 --- /dev/null +++ b/src/support/runtime/exception_libcxxrt.ipp @@ -0,0 +1,41 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef LIBCXXRT +#error this header may only be used when targeting libcxxrt +#endif + +namespace std { + +bad_exception::~bad_exception() _NOEXCEPT +{ +} + +const char* bad_exception::what() const _NOEXCEPT +{ + return "std::bad_exception"; +} + + +bad_array_length::bad_array_length() _NOEXCEPT +{ +} + +bad_array_length::~bad_array_length() _NOEXCEPT +{ +} + +const char* +bad_array_length::what() const _NOEXCEPT +{ + return "bad_array_length"; +} + +} // namespace std diff --git a/src/support/runtime/exception_msvc.ipp b/src/support/runtime/exception_msvc.ipp new file mode 100644 index 0000000000000..950ec0cebfe7a --- /dev/null +++ b/src/support/runtime/exception_msvc.ipp @@ -0,0 +1,89 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ABI_MICROSOFT +#error this header can only be used when targeting the MSVC ABI +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <eh.h> +#include <corecrt_terminate.h> + +namespace std { + +// libcxxrt provides implementations of these functions itself. +unexpected_handler +set_unexpected(unexpected_handler func) _NOEXCEPT { + return ::set_unexpected(func); +} + +unexpected_handler get_unexpected() _NOEXCEPT { + return ::_get_unexpected(); +} + +_LIBCPP_NORETURN +void unexpected() { + (*get_unexpected())(); + // unexpected handler should not return + terminate(); +} + +terminate_handler set_terminate(terminate_handler func) _NOEXCEPT { + return ::set_terminate(func); +} + +terminate_handler get_terminate() _NOEXCEPT { + return ::_get_terminate(); +} + +_LIBCPP_NORETURN +void terminate() _NOEXCEPT +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + (*get_terminate())(); + // handler should not return + fprintf(stderr, "terminate_handler unexpectedly returned\n"); + ::abort(); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + // handler should not throw exception + fprintf(stderr, "terminate_handler unexpectedly threw an exception\n"); + ::abort(); + } +#endif // _LIBCPP_NO_EXCEPTIONS +} + +bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; } + +int uncaught_exceptions() _NOEXCEPT { + return __uncaught_exceptions(); +} + +bad_array_length::bad_array_length() _NOEXCEPT +{ +} + +bad_array_length::~bad_array_length() _NOEXCEPT +{ +} + +const char* +bad_array_length::what() const _NOEXCEPT +{ + return "bad_array_length"; +} + +} // namespace std diff --git a/src/support/runtime/exception_pointer_cxxabi.ipp b/src/support/runtime/exception_pointer_cxxabi.ipp new file mode 100644 index 0000000000000..dfac8648c498e --- /dev/null +++ b/src/support/runtime/exception_pointer_cxxabi.ipp @@ -0,0 +1,74 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef HAVE_DEPENDENT_EH_ABI +#error this header may only be used with libc++abi or libcxxrt +#endif + +namespace std { + +exception_ptr::~exception_ptr() _NOEXCEPT { + __cxa_decrement_exception_refcount(__ptr_); +} + +exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT + : __ptr_(other.__ptr_) +{ + __cxa_increment_exception_refcount(__ptr_); +} + +exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT +{ + if (__ptr_ != other.__ptr_) + { + __cxa_increment_exception_refcount(other.__ptr_); + __cxa_decrement_exception_refcount(__ptr_); + __ptr_ = other.__ptr_; + } + return *this; +} + +nested_exception::nested_exception() _NOEXCEPT + : __ptr_(current_exception()) +{ +} + +nested_exception::~nested_exception() _NOEXCEPT +{ +} + +_LIBCPP_NORETURN +void +nested_exception::rethrow_nested() const +{ + if (__ptr_ == nullptr) + terminate(); + rethrow_exception(__ptr_); +} + +exception_ptr current_exception() _NOEXCEPT +{ + // be nicer if there was a constructor that took a ptr, then + // this whole function would be just: + // return exception_ptr(__cxa_current_primary_exception()); + exception_ptr ptr; + ptr.__ptr_ = __cxa_current_primary_exception(); + return ptr; +} + +_LIBCPP_NORETURN +void rethrow_exception(exception_ptr p) +{ + __cxa_rethrow_primary_exception(p.__ptr_); + // if p.__ptr_ is NULL, above returns so we terminate + terminate(); +} + +} // namespace std diff --git a/src/support/runtime/exception_pointer_glibcxx.ipp b/src/support/runtime/exception_pointer_glibcxx.ipp new file mode 100644 index 0000000000000..9d20dfe486227 --- /dev/null +++ b/src/support/runtime/exception_pointer_glibcxx.ipp @@ -0,0 +1,78 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// libsupc++ does not implement the dependent EH ABI and the functionality +// it uses to implement std::exception_ptr (which it declares as an alias of +// std::__exception_ptr::exception_ptr) is not directly exported to clients. So +// we have little choice but to hijack std::__exception_ptr::exception_ptr's +// (which fortunately has the same layout as our std::exception_ptr) copy +// constructor, assignment operator and destructor (which are part of its +// stable ABI), and its rethrow_exception(std::__exception_ptr::exception_ptr) +// function. + +namespace std { + +namespace __exception_ptr +{ + +struct exception_ptr +{ + void* __ptr_; + + exception_ptr(const exception_ptr&) _NOEXCEPT; + exception_ptr& operator=(const exception_ptr&) _NOEXCEPT; + ~exception_ptr() _NOEXCEPT; +}; + +} + +_LIBCPP_NORETURN void rethrow_exception(__exception_ptr::exception_ptr); + +exception_ptr::~exception_ptr() _NOEXCEPT +{ + reinterpret_cast<__exception_ptr::exception_ptr*>(this)->~exception_ptr(); +} + +exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT + : __ptr_(other.__ptr_) +{ + new (reinterpret_cast<void*>(this)) __exception_ptr::exception_ptr( + reinterpret_cast<const __exception_ptr::exception_ptr&>(other)); +} + +exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT +{ + *reinterpret_cast<__exception_ptr::exception_ptr*>(this) = + reinterpret_cast<const __exception_ptr::exception_ptr&>(other); + return *this; +} + +nested_exception::nested_exception() _NOEXCEPT + : __ptr_(current_exception()) +{ +} + + +_LIBCPP_NORETURN +void +nested_exception::rethrow_nested() const +{ + if (__ptr_ == nullptr) + terminate(); + rethrow_exception(__ptr_); +} + +_LIBCPP_NORETURN +void rethrow_exception(exception_ptr p) +{ + rethrow_exception(reinterpret_cast<__exception_ptr::exception_ptr&>(p)); +} + +} // namespace std diff --git a/src/support/runtime/exception_pointer_unimplemented.ipp b/src/support/runtime/exception_pointer_unimplemented.ipp new file mode 100644 index 0000000000000..21c182c85974b --- /dev/null +++ b/src/support/runtime/exception_pointer_unimplemented.ipp @@ -0,0 +1,80 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 <stdio.h> +#include <stdlib.h> + +namespace std { + +exception_ptr::~exception_ptr() _NOEXCEPT +{ +# warning exception_ptr not yet implemented + fprintf(stderr, "exception_ptr not yet implemented\n"); + ::abort(); +} + +exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT + : __ptr_(other.__ptr_) +{ +# warning exception_ptr not yet implemented + fprintf(stderr, "exception_ptr not yet implemented\n"); + ::abort(); +} + +exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT +{ +# warning exception_ptr not yet implemented + fprintf(stderr, "exception_ptr not yet implemented\n"); + ::abort(); +} + +nested_exception::nested_exception() _NOEXCEPT + : __ptr_(current_exception()) +{ +} + +#if !defined(__GLIBCXX__) + +nested_exception::~nested_exception() _NOEXCEPT +{ +} + +#endif + +_LIBCPP_NORETURN +void +nested_exception::rethrow_nested() const +{ +# warning exception_ptr not yet implemented + fprintf(stderr, "exception_ptr not yet implemented\n"); + ::abort(); +#if 0 + if (__ptr_ == nullptr) + terminate(); + rethrow_exception(__ptr_); +#endif // FIXME +} + +exception_ptr current_exception() _NOEXCEPT +{ +# warning exception_ptr not yet implemented + fprintf(stderr, "exception_ptr not yet implemented\n"); + ::abort(); +} + +_LIBCPP_NORETURN +void rethrow_exception(exception_ptr p) +{ +# warning exception_ptr not yet implemented + fprintf(stderr, "exception_ptr not yet implemented\n"); + ::abort(); +} + +} // namespace std diff --git a/src/support/runtime/new_handler_fallback.ipp b/src/support/runtime/new_handler_fallback.ipp new file mode 100644 index 0000000000000..b7092d542d972 --- /dev/null +++ b/src/support/runtime/new_handler_fallback.ipp @@ -0,0 +1,27 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +namespace std { + +_LIBCPP_SAFE_STATIC static std::new_handler __new_handler; + +new_handler +set_new_handler(new_handler handler) _NOEXCEPT +{ + return __sync_lock_test_and_set(&__new_handler, handler); +} + +new_handler +get_new_handler() _NOEXCEPT +{ + return __sync_fetch_and_add(&__new_handler, nullptr); +} + +} // namespace std diff --git a/src/support/win32/locale_win32.cpp b/src/support/win32/locale_win32.cpp index ee13811171551..acbf79ac197c0 100644 --- a/src/support/win32/locale_win32.cpp +++ b/src/support/win32/locale_win32.cpp @@ -13,8 +13,6 @@ #include <memory> #include <type_traits> -#include <crtversion.h> - typedef _VSTD::remove_pointer<locale_t>::type __locale_struct; typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii; @@ -31,9 +29,8 @@ locale_t uselocale( locale_t newloc ) // uselocale sets the thread's locale by definition, so unconditionally use thread-local locale _configthreadlocale( _ENABLE_PER_THREAD_LOCALE ); // uselocale sets all categories -#if _VC_CRT_MAJOR_VERSION < 14 - setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale ); -#endif + // disable setting locale on Windows temporarily because the structure is opaque (PR31516) + //setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale ); // uselocale returns the old locale_t return old_locale; } diff --git a/src/system_error.cpp b/src/system_error.cpp index c547124768282..cbbbb5dcd15c4 100644 --- a/src/system_error.cpp +++ b/src/system_error.cpp @@ -17,9 +17,9 @@ #include "cstring" #include "cstdio" #include "cstdlib" -#include "cassert" #include "string" #include "string.h" +#include "__debug" #if defined(__ANDROID__) #include <android/api-level.h> @@ -29,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD // class error_category -#if defined(_LIBCPP_DEPRECATED_ABI_EXTERNAL_ERROR_CATEGORY_CONSTRUCTOR) +#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS) error_category::error_category() _NOEXCEPT { } @@ -96,7 +96,7 @@ string do_strerror_r(int ev) { std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev); return string(buffer); } else { - assert(new_errno == ERANGE); + _LIBCPP_ASSERT(new_errno == ERANGE, "unexpected error from ::strerr_r"); // FIXME maybe? 'strerror_buff_size' is likely to exceed the // maximum error size so ERANGE shouldn't be returned. std::abort(); diff --git a/src/thread.cpp b/src/thread.cpp index 5ccf829fb8644..3f283c385b76b 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -24,9 +24,9 @@ # endif // defined(BSD) #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) # include <unistd.h> -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) #if defined(__NetBSD__) #pragma weak pthread_create // Do not create libpthread dependency @@ -40,7 +40,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD thread::~thread() { - if (__t_ != 0) + if (!__libcpp_thread_isnull(&__t_)) terminate(); } @@ -48,11 +48,11 @@ void thread::join() { int ec = EINVAL; - if (__t_ != 0) + if (!__libcpp_thread_isnull(&__t_)) { ec = __libcpp_thread_join(&__t_); if (ec == 0) - __t_ = 0; + __t_ = _LIBCPP_NULL_THREAD; } if (ec) @@ -63,11 +63,11 @@ void thread::detach() { int ec = EINVAL; - if (__t_ != 0) + if (!__libcpp_thread_isnull(&__t_)) { ec = __libcpp_thread_detach(&__t_); if (ec == 0) - __t_ = 0; + __t_ = _LIBCPP_NULL_THREAD; } if (ec) @@ -99,7 +99,7 @@ thread::hardware_concurrency() _NOEXCEPT #else // defined(CTL_HW) && defined(HW_NCPU) // TODO: grovel through /proc or check cpuid on x86 and similar // instructions on other architectures. -# if defined(_MSC_VER) && ! defined(__clang__) +# if defined(_LIBCPP_MSVC) _LIBCPP_WARNING("hardware_concurrency not yet implemented") # else # warning hardware_concurrency not yet implemented @@ -114,33 +114,9 @@ namespace this_thread void sleep_for(const chrono::nanoseconds& ns) { - using namespace chrono; - if (ns > nanoseconds::zero()) + if (ns > chrono::nanoseconds::zero()) { -#if defined(_LIBCPP_WIN32API) - milliseconds ms = duration_cast<milliseconds>(ns); - if (ms.count() == 0 || ns > duration_cast<nanoseconds>(ms)) - ++ms; - Sleep(ms.count()); -#else - seconds s = duration_cast<seconds>(ns); - timespec ts; - 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; - } - - while (nanosleep(&ts, &ts) == -1 && errno == EINTR) - ; -#endif + __libcpp_thread_sleep_for(ns); } } diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp index d0a7dae380254..02778f3687047 100644 --- a/src/typeinfo.cpp +++ b/src/typeinfo.cpp @@ -6,73 +6,15 @@ // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -#include <stdlib.h> - -#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ - (defined(__APPLE__) || defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI)) -#include <cxxabi.h> -#endif #include "typeinfo" -#if defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) +// FIXME: Remove __APPLE__ default here once buildit is gone. +#if (!defined(_LIBCPP_ABI_MICROSOFT) && !defined(LIBCXX_BUILDING_LIBCXXABI) && \ + !defined(LIBCXXRT) && !defined(__GLIBCXX__) && \ + !defined(__APPLE__)) || \ + defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) // FIXME: remove this configuration. std::type_info::~type_info() { } #endif - -#if !defined(LIBCXXRT) && !defined(_LIBCPPABI_VERSION) - -std::bad_cast::bad_cast() _NOEXCEPT -{ -} - -std::bad_typeid::bad_typeid() _NOEXCEPT -{ -} - -#ifndef __GLIBCXX__ - -std::bad_cast::~bad_cast() _NOEXCEPT -{ -} - -const char* -std::bad_cast::what() const _NOEXCEPT -{ - return "std::bad_cast"; -} - -std::bad_typeid::~bad_typeid() _NOEXCEPT -{ -} - -const char* -std::bad_typeid::what() const _NOEXCEPT -{ - return "std::bad_typeid"; -} - -#if defined(__APPLE__) && !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) - // 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() - { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw std::bad_typeid(); -#else - _VSTD::abort(); -#endif - } - void __cxxabiv1::__cxa_bad_cast() - { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw std::bad_cast(); -#else - _VSTD::abort(); -#endif - } -#endif - -#endif // !__GLIBCXX__ -#endif // !LIBCXXRT && !_LIBCPPABI_VERSION |