Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,91 @@
//===----------------------- algorithm.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 "algorithm"
#include "random"
#include "mutex"
_LIBCPP_BEGIN_NAMESPACE_STD
template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&);
template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&);
template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&);
template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&);
template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
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
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
#endif
unsigned __rs_default::__c_ = 0;
__rs_default::__rs_default()
{
#ifndef _LIBCPP_HAS_NO_THREADS
__libcpp_mutex_lock(&__rs_mut);
#endif
__c_ = 1;
}
__rs_default::__rs_default(const __rs_default&)
{
++__c_;
}
__rs_default::~__rs_default()
{
#ifndef _LIBCPP_HAS_NO_THREADS
if (--__c_ == 0)
__libcpp_mutex_unlock(&__rs_mut);
#else
--__c_;
#endif
}
__rs_default::result_type
__rs_default::operator()()
{
static mt19937 __rs_g;
return __rs_g();
}
__rs_default
__rs_get()
{
return __rs_default();
}
_LIBCPP_END_NAMESPACE_STD

View File

@ -0,0 +1,23 @@
//===---------------------------- any.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 "any"
#include "experimental/any"
namespace std {
const char* bad_any_cast::what() const _NOEXCEPT {
return "bad any cast";
}
}
_LIBCPP_BEGIN_NAMESPACE_LFTS
const char* bad_any_cast::what() const _NOEXCEPT {
return "bad any cast";
}
_LIBCPP_END_NAMESPACE_LFTS

View File

@ -0,0 +1,31 @@
//===-------------------------- bind.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.
//
//===----------------------------------------------------------------------===//
#define _LIBCPP_BUILDING_BIND
#include "functional"
_LIBCPP_BEGIN_NAMESPACE_STD
namespace placeholders
{
const __ph<1> _1{};
const __ph<2> _2{};
const __ph<3> _3{};
const __ph<4> _4{};
const __ph<5> _5{};
const __ph<6> _6{};
const __ph<7> _7{};
const __ph<8> _8{};
const __ph<9> _9{};
const __ph<10> _10{};
} // placeholders
_LIBCPP_END_NAMESPACE_STD

View File

@ -0,0 +1,237 @@
//===------------------------- chrono.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 "chrono"
#include "cerrno" // errno
#include "system_error" // __throw_system_error
#include <time.h> // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME
#if (__APPLE__)
#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200
#define _LIBCXX_USE_CLOCK_GETTIME
#endif
#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 100000
#define _LIBCXX_USE_CLOCK_GETTIME
#endif
#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__)
#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 100000
#define _LIBCXX_USE_CLOCK_GETTIME
#endif
#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__)
#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 30000
#define _LIBCXX_USE_CLOCK_GETTIME
#endif
#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__
#else
#define _LIBCXX_USE_CLOCK_GETTIME
#endif // __APPLE__
#if defined(_LIBCPP_WIN32API)
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRA_LEAN
#include <windows.h>
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
#include <winapifamily.h>
#endif
#else
#if !defined(CLOCK_REALTIME) || !defined(_LIBCXX_USE_CLOCK_GETTIME)
#include <sys/time.h> // for gettimeofday and timeval
#endif // !defined(CLOCK_REALTIME)
#endif // defined(_LIBCPP_WIN32API)
#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
#if __APPLE__
#include <mach/mach_time.h> // mach_absolute_time, mach_timebase_info_data_t
#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC)
#error "Monotonic clock not implemented"
#endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
// system_clock
const bool system_clock::is_steady;
system_clock::time_point
system_clock::now() _NOEXCEPT
{
#if defined(_LIBCPP_WIN32API)
// FILETIME is in 100ns units
using filetime_duration =
_VSTD::chrono::duration<__int64,
_VSTD::ratio_multiply<_VSTD::ratio<100, 1>,
nanoseconds::period>>;
// The Windows epoch is Jan 1 1601, the Unix epoch Jan 1 1970.
static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600};
FILETIME ft;
#if _WIN32_WINNT >= _WIN32_WINNT_WIN8
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
GetSystemTimePreciseAsFileTime(&ft);
#else
GetSystemTimeAsFileTime(&ft);
#endif
#else
GetSystemTimeAsFileTime(&ft);
#endif
filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) |
static_cast<__int64>(ft.dwLowDateTime)};
return time_point(duration_cast<duration>(d - nt_to_unix_epoch));
#else
#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
struct timespec tp;
if (0 != clock_gettime(CLOCK_REALTIME, &tp))
__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
#else
timeval tv;
gettimeofday(&tv, 0);
return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
#endif // _LIBCXX_USE_CLOCK_GETTIME && CLOCK_REALTIME
#endif
}
time_t
system_clock::to_time_t(const time_point& t) _NOEXCEPT
{
return time_t(duration_cast<seconds>(t.time_since_epoch()).count());
}
system_clock::time_point
system_clock::from_time_t(time_t t) _NOEXCEPT
{
return system_clock::time_point(seconds(t));
}
#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
// steady_clock
//
// 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
// instead.
const bool steady_clock::is_steady;
#if defined(__APPLE__)
// Darwin libc versions >= 1133 provide ns precision via CLOCK_UPTIME_RAW
#if defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
struct timespec tp;
if (0 != clock_gettime(CLOCK_UPTIME_RAW, &tp))
__throw_system_error(errno, "clock_gettime(CLOCK_UPTIME_RAW) failed");
return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
}
#else
// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
// nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom
// are run time constants supplied by the OS. This clock has no relationship
// to the Gregorian calendar. It's main use is as a high resolution timer.
// MachInfo.numer / MachInfo.denom is often 1 on the latest equipment. Specialize
// for that case as an optimization.
static
steady_clock::rep
steady_simplified()
{
return static_cast<steady_clock::rep>(mach_absolute_time());
}
static
double
compute_steady_factor()
{
mach_timebase_info_data_t MachInfo;
mach_timebase_info(&MachInfo);
return static_cast<double>(MachInfo.numer) / MachInfo.denom;
}
static
steady_clock::rep
steady_full()
{
static const double factor = compute_steady_factor();
return static_cast<steady_clock::rep>(mach_absolute_time() * factor);
}
typedef steady_clock::rep (*FP)();
static
FP
init_steady_clock()
{
mach_timebase_info_data_t MachInfo;
mach_timebase_info(&MachInfo);
if (MachInfo.numer == MachInfo.denom)
return &steady_simplified;
return &steady_full;
}
steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
static FP fp = init_steady_clock();
return time_point(duration(fp()));
}
#endif // defined(_LIBCXX_USE_CLOCK_GETTIME) && defined(CLOCK_UPTIME_RAW)
#elif defined(_LIBCPP_WIN32API)
steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
static LARGE_INTEGER freq;
static BOOL initialized = FALSE;
if (!initialized)
initialized = QueryPerformanceFrequency(&freq); // always succceeds
LARGE_INTEGER counter;
QueryPerformanceCounter(&counter);
return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart));
}
#elif defined(CLOCK_MONOTONIC)
// On Apple platforms only CLOCK_UPTIME_RAW or mach_absolute_time are able to
// time functions in the nanosecond range. Thus, they are the only acceptable
// implementations of steady_clock.
#ifdef __APPLE__
#error "Never use CLOCK_MONOTONIC for steady_clock::now on Apple platforms"
#endif
steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
struct timespec tp;
if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
}
#else
#error "Monotonic clock not implemented"
#endif
#endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK
}
_LIBCPP_END_NAMESPACE_STD

View File

@ -0,0 +1,93 @@
//===-------------------- condition_variable.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 "__config"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "condition_variable"
#include "thread"
#include "system_error"
#include "__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
condition_variable::~condition_variable()
{
__libcpp_condvar_destroy(&__cv_);
}
void
condition_variable::notify_one() _NOEXCEPT
{
__libcpp_condvar_signal(&__cv_);
}
void
condition_variable::notify_all() _NOEXCEPT
{
__libcpp_condvar_broadcast(&__cv_);
}
void
condition_variable::wait(unique_lock<mutex>& lk) _NOEXCEPT
{
if (!lk.owns_lock())
__throw_system_error(EPERM,
"condition_variable::wait: mutex not locked");
int ec = __libcpp_condvar_wait(&__cv_, lk.mutex()->native_handle());
if (ec)
__throw_system_error(ec, "condition_variable wait failed");
}
void
condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) _NOEXCEPT
{
using namespace chrono;
if (!lk.owns_lock())
__throw_system_error(EPERM,
"condition_variable::timed wait: mutex not locked");
nanoseconds d = tp.time_since_epoch();
if (d > nanoseconds(0x59682F000000E941))
d = nanoseconds(0x59682F000000E941);
timespec ts;
seconds s = duration_cast<seconds>(d);
typedef decltype(ts.tv_sec) ts_sec;
_LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
if (s.count() < ts_sec_max)
{
ts.tv_sec = static_cast<ts_sec>(s.count());
ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
}
else
{
ts.tv_sec = ts_sec_max;
ts.tv_nsec = giga::num - 1;
}
int ec = __libcpp_condvar_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
if (ec != 0 && ec != ETIMEDOUT)
__throw_system_error(ec, "condition_variable timed_wait failed");
}
void
notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
{
auto& tl_ptr = __thread_local_data();
// If this thread was not created using std::thread then it will not have
// previously allocated.
if (tl_ptr.get() == nullptr) {
tl_ptr.set_pointer(new __thread_struct);
}
__thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
}
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
//===------------------------ exception.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 "exception"
#include "new"
#include "typeinfo"
#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
#endif
#if defined(_LIBCPP_ABI_MICROSOFT)
#include "support/runtime/exception_msvc.ipp"
#include "support/runtime/exception_pointer_msvc.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__)
#include "support/runtime/exception_glibcxx.ipp"
#include "support/runtime/exception_pointer_glibcxx.ipp"
#else
#include "include/atomic_support.h"
#include "support/runtime/exception_fallback.ipp"
#include "support/runtime/exception_pointer_unimplemented.ipp"
#endif

View File

@ -0,0 +1,342 @@
//===------------------ 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()};
}
#endif
template <class ...Args>
inline bool set_or_throw(std::error_code& my_ec,
std::error_code* user_ec,
const char* msg, Args&&... args)
{
if (user_ec) {
*user_ec = my_ec;
return true;
}
__throw_filesystem_error(msg, std::forward<Args>(args)..., my_ec);
return false;
}
#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) {
if (errno)
ec = capture_errno();
return {};
} else {
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;
__dir_stream& operator=(const __dir_stream&) = delete;
__dir_stream(__dir_stream&& other) noexcept
: __stream_(other.__stream_), __root_(std::move(other.__root_)),
__entry_(std::move(other.__entry_))
{
other.__stream_ = nullptr;
}
__dir_stream(const path& root, directory_options opts, error_code& ec)
: __stream_(nullptr),
__root_(root)
{
if ((__stream_ = ::opendir(root.c_str())) == nullptr) {
ec = detail::capture_errno();
const bool allow_eacess =
bool(opts & directory_options::skip_permission_denied);
if (allow_eacess && ec.value() == EACCES)
ec.clear();
return;
}
advance(ec);
}
~__dir_stream() noexcept
{ if (__stream_) close(); }
bool good() const noexcept { return __stream_ != nullptr; }
bool advance(error_code &ec) {
while (true) {
auto str = detail::posix_readdir(__stream_, ec);
if (str == "." || str == "..") {
continue;
} else if (ec || str.empty()) {
close();
return false;
} else {
__entry_.assign(__root_ / str);
return true;
}
}
}
private:
std::error_code close() noexcept {
std::error_code m_ec;
if (::closedir(__stream_) == -1)
m_ec = detail::capture_errno();
__stream_ = nullptr;
return m_ec;
}
DIR * __stream_{nullptr};
public:
path __root_;
directory_entry __entry_;
};
#endif
// directory_iterator
directory_iterator::directory_iterator(const path& p, error_code *ec,
directory_options opts)
{
std::error_code m_ec;
__imp_ = make_shared<__dir_stream>(p, opts, m_ec);
if (ec) *ec = m_ec;
if (!__imp_->good()) {
__imp_.reset();
if (m_ec)
set_or_throw(m_ec, ec,
"directory_iterator::directory_iterator(...)", p);
}
}
directory_iterator& directory_iterator::__increment(error_code *ec)
{
_LIBCPP_ASSERT(__imp_, "Attempting to increment an invalid iterator");
std::error_code m_ec;
if (!__imp_->advance(m_ec)) {
__imp_.reset();
if (m_ec)
set_or_throw(m_ec, ec, "directory_iterator::operator++()");
} else {
if (ec) ec->clear();
}
return *this;
}
directory_entry const& directory_iterator::__dereference() const {
_LIBCPP_ASSERT(__imp_, "Attempting to dereference an invalid iterator");
return __imp_->__entry_;
}
// recursive_directory_iterator
struct recursive_directory_iterator::__shared_imp {
stack<__dir_stream> __stack_;
directory_options __options_;
};
recursive_directory_iterator::recursive_directory_iterator(const path& p,
directory_options opt, error_code *ec)
: __imp_(nullptr), __rec_(true)
{
if (ec) ec->clear();
std::error_code m_ec;
__dir_stream new_s(p, opt, m_ec);
if (m_ec) set_or_throw(m_ec, ec, "recursive_directory_iterator", p);
if (m_ec || !new_s.good()) return;
__imp_ = _VSTD::make_shared<__shared_imp>();
__imp_->__options_ = opt;
__imp_->__stack_.push(_VSTD::move(new_s));
}
void recursive_directory_iterator::__pop(error_code* ec)
{
_LIBCPP_ASSERT(__imp_, "Popping the end iterator");
if (ec) ec->clear();
__imp_->__stack_.pop();
if (__imp_->__stack_.size() == 0)
__imp_.reset();
else
__advance(ec);
}
directory_options recursive_directory_iterator::options() const {
return __imp_->__options_;
}
int recursive_directory_iterator::depth() const {
return __imp_->__stack_.size() - 1;
}
const directory_entry& recursive_directory_iterator::__dereference() const {
return __imp_->__stack_.top().__entry_;
}
recursive_directory_iterator&
recursive_directory_iterator::__increment(error_code *ec)
{
if (ec) ec->clear();
if (recursion_pending()) {
if (__try_recursion(ec) || (ec && *ec))
return *this;
}
__rec_ = true;
__advance(ec);
return *this;
}
void recursive_directory_iterator::__advance(error_code* ec) {
// REQUIRES: ec must be cleared before calling this function.
const directory_iterator end_it;
auto& stack = __imp_->__stack_;
std::error_code m_ec;
while (stack.size() > 0) {
if (stack.top().advance(m_ec))
return;
if (m_ec) break;
stack.pop();
}
__imp_.reset();
if (m_ec)
set_or_throw(m_ec, ec, "recursive_directory_iterator::operator++()");
}
bool recursive_directory_iterator::__try_recursion(error_code *ec) {
bool rec_sym =
bool(options() & directory_options::follow_directory_symlink);
auto& curr_it = __imp_->__stack_.top();
bool skip_rec = false;
std::error_code m_ec;
if (!rec_sym) {
file_status st = curr_it.__entry_.symlink_status(m_ec);
if (m_ec && status_known(st))
m_ec.clear();
if (m_ec || is_symlink(st) || !is_directory(st))
skip_rec = true;
} else {
file_status st = curr_it.__entry_.status(m_ec);
if (m_ec && status_known(st))
m_ec.clear();
if (m_ec || !is_directory(st))
skip_rec = true;
}
if (!skip_rec) {
__dir_stream new_it(curr_it.__entry_.path(), __imp_->__options_, m_ec);
if (new_it.good()) {
__imp_->__stack_.push(_VSTD::move(new_it));
return true;
}
}
if (m_ec) {
const bool allow_eacess = bool(__imp_->__options_
& directory_options::skip_permission_denied);
if (m_ec.value() == EACCES && allow_eacess) {
if (ec) ec->clear();
} else {
__imp_.reset();
set_or_throw(m_ec, ec,
"recursive_directory_iterator::operator++()");
}
}
return false;
}
_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM

View File

@ -0,0 +1,173 @@
//===----------------------------------------------------------------------===////
//
// 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 FILESYSTEM_TIME_HELPER_H
#define FILESYSTEM_TIME_HELPER_H
#include "experimental/__config"
#include "chrono"
#include "cstdlib"
#include "climits"
#include <unistd.h>
#include <sys/stat.h>
#if !defined(UTIME_OMIT)
#include <sys/time.h> // for ::utimes as used in __last_write_time
#endif
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
namespace time_detail { namespace {
using namespace chrono;
template <class FileTimeT,
bool IsFloat = is_floating_point<typename FileTimeT::rep>::value>
struct fs_time_util_base {
static constexpr auto max_seconds =
duration_cast<seconds>(FileTimeT::duration::max()).count();
static constexpr auto max_nsec =
duration_cast<nanoseconds>(FileTimeT::duration::max() -
seconds(max_seconds))
.count();
static constexpr auto min_seconds =
duration_cast<seconds>(FileTimeT::duration::min()).count();
static constexpr auto min_nsec_timespec =
duration_cast<nanoseconds>(
(FileTimeT::duration::min() - seconds(min_seconds)) + seconds(1))
.count();
// Static assert that these values properly round trip.
static_assert((seconds(min_seconds) +
duration_cast<microseconds>(nanoseconds(min_nsec_timespec))) -
duration_cast<microseconds>(seconds(1)) ==
FileTimeT::duration::min(),
"");
};
template <class FileTimeT>
struct fs_time_util_base<FileTimeT, true> {
static const long long max_seconds;
static const long long max_nsec;
static const long long min_seconds;
static const long long min_nsec_timespec;
};
template <class FileTimeT>
const long long fs_time_util_base<FileTimeT, true>::max_seconds =
duration_cast<seconds>(FileTimeT::duration::max()).count();
template <class FileTimeT>
const long long fs_time_util_base<FileTimeT, true>::max_nsec =
duration_cast<nanoseconds>(FileTimeT::duration::max() -
seconds(max_seconds))
.count();
template <class FileTimeT>
const long long fs_time_util_base<FileTimeT, true>::min_seconds =
duration_cast<seconds>(FileTimeT::duration::min()).count();
template <class FileTimeT>
const long long fs_time_util_base<FileTimeT, true>::min_nsec_timespec =
duration_cast<nanoseconds>((FileTimeT::duration::min() -
seconds(min_seconds)) +
seconds(1))
.count();
template <class FileTimeT, class TimeT, class TimeSpecT>
struct fs_time_util : fs_time_util_base<FileTimeT> {
using Base = fs_time_util_base<FileTimeT>;
using Base::max_nsec;
using Base::max_seconds;
using Base::min_nsec_timespec;
using Base::min_seconds;
public:
template <class CType, class ChronoType>
static bool checked_set(CType* out, ChronoType time) {
using Lim = numeric_limits<CType>;
if (time > Lim::max() || time < Lim::min())
return false;
*out = static_cast<CType>(time);
return true;
}
static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool is_representable(TimeSpecT tm) {
if (tm.tv_sec >= 0) {
return (tm.tv_sec < max_seconds) ||
(tm.tv_sec == max_seconds && tm.tv_nsec <= max_nsec);
} else if (tm.tv_sec == (min_seconds - 1)) {
return tm.tv_nsec >= min_nsec_timespec;
} else {
return (tm.tv_sec >= min_seconds);
}
}
static _LIBCPP_CONSTEXPR_AFTER_CXX11 bool is_representable(FileTimeT tm) {
auto secs = duration_cast<seconds>(tm.time_since_epoch());
auto nsecs = duration_cast<nanoseconds>(tm.time_since_epoch() - secs);
if (nsecs.count() < 0) {
secs = secs + seconds(1);
nsecs = nsecs + seconds(1);
}
using TLim = numeric_limits<TimeT>;
if (secs.count() >= 0)
return secs.count() <= TLim::max();
return secs.count() >= TLim::min();
}
static _LIBCPP_CONSTEXPR_AFTER_CXX11 FileTimeT
convert_timespec(TimeSpecT tm) {
auto adj_msec = duration_cast<microseconds>(nanoseconds(tm.tv_nsec));
if (tm.tv_sec >= 0) {
auto Dur = seconds(tm.tv_sec) + microseconds(adj_msec);
return FileTimeT(Dur);
} else if (duration_cast<microseconds>(nanoseconds(tm.tv_nsec)).count() ==
0) {
return FileTimeT(seconds(tm.tv_sec));
} else { // tm.tv_sec < 0
auto adj_subsec =
duration_cast<microseconds>(seconds(1) - nanoseconds(tm.tv_nsec));
auto Dur = seconds(tm.tv_sec + 1) - adj_subsec;
return FileTimeT(Dur);
}
}
template <class SubSecDurT, class SubSecT>
static bool set_times_checked(TimeT* sec_out, SubSecT* subsec_out,
FileTimeT tp) {
using namespace chrono;
auto dur = tp.time_since_epoch();
auto sec_dur = duration_cast<seconds>(dur);
auto subsec_dur = duration_cast<SubSecDurT>(dur - sec_dur);
// The tv_nsec and tv_usec fields must not be negative so adjust accordingly
if (subsec_dur.count() < 0) {
if (sec_dur.count() > min_seconds) {
sec_dur -= seconds(1);
subsec_dur += seconds(1);
} else {
subsec_dur = SubSecDurT::zero();
}
}
return checked_set(sec_out, sec_dur.count()) &&
checked_set(subsec_out, subsec_dur.count());
}
};
} // end namespace
} // end namespace time_detail
using time_detail::fs_time_util;
_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM
#endif // FILESYSTEM_TIME_HELPER_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,448 @@
//===--------------------- filesystem/path.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 "string_view"
#include "utility"
namespace { namespace parser
{
using namespace std;
using namespace std::experimental::filesystem;
using string_view_t = path::__string_view;
using string_view_pair = pair<string_view_t, string_view_t>;
using PosPtr = path::value_type const*;
struct PathParser {
enum ParserState : unsigned char {
// Zero is a special sentinel value used by default constructed iterators.
PS_BeforeBegin = 1,
PS_InRootName,
PS_InRootDir,
PS_InFilenames,
PS_InTrailingSep,
PS_AtEnd
};
const string_view_t Path;
string_view_t RawEntry;
ParserState State;
private:
PathParser(string_view_t P, ParserState State) noexcept
: Path(P), State(State) {}
public:
PathParser(string_view_t P, string_view_t E, unsigned char S)
: Path(P), RawEntry(E), State(static_cast<ParserState>(S)) {
// S cannot be '0' or PS_BeforeBegin.
}
static PathParser CreateBegin(string_view_t P) noexcept {
PathParser PP(P, PS_BeforeBegin);
PP.increment();
return PP;
}
static PathParser CreateEnd(string_view_t P) noexcept {
PathParser PP(P, PS_AtEnd);
return PP;
}
PosPtr peek() const noexcept {
auto TkEnd = getNextTokenStartPos();
auto End = getAfterBack();
return TkEnd == End ? nullptr : TkEnd;
}
void increment() noexcept {
const PosPtr End = getAfterBack();
const PosPtr Start = getNextTokenStartPos();
if (Start == End)
return makeState(PS_AtEnd);
switch (State) {
case PS_BeforeBegin: {
PosPtr TkEnd = consumeSeparator(Start, End);
// If we consumed exactly two separators we have a root name.
if (TkEnd && TkEnd == Start + 2) {
// FIXME Do we need to consume a name or is '//' a root name on its own?
// what about '//.', '//..', '//...'?
auto NameEnd = consumeName(TkEnd, End);
if (NameEnd)
TkEnd = NameEnd;
return makeState(PS_InRootName, Start, TkEnd);
}
else if (TkEnd)
return makeState(PS_InRootDir, Start, TkEnd);
else
return makeState(PS_InFilenames, Start, consumeName(Start, End));
}
case PS_InRootName:
return makeState(PS_InRootDir, Start, consumeSeparator(Start, End));
case PS_InRootDir:
return makeState(PS_InFilenames, Start, consumeName(Start, End));
case PS_InFilenames: {
PosPtr SepEnd = consumeSeparator(Start, End);
if (SepEnd != End) {
PosPtr TkEnd = consumeName(SepEnd, End);
if (TkEnd)
return makeState(PS_InFilenames, SepEnd, TkEnd);
}
return makeState(PS_InTrailingSep, Start, SepEnd);
}
case PS_InTrailingSep:
return makeState(PS_AtEnd);
case PS_AtEnd:
_LIBCPP_UNREACHABLE();
}
}
void decrement() noexcept {
const PosPtr REnd = getBeforeFront();
const PosPtr RStart = getCurrentTokenStartPos() - 1;
switch (State) {
case PS_AtEnd: {
// Try to consume a trailing separator or root directory first.
if (PosPtr SepEnd = consumeSeparator(RStart, REnd)) {
if (SepEnd == REnd)
return makeState((RStart == REnd + 2) ? PS_InRootName : PS_InRootDir,
Path.data(), RStart + 1);
// Check if we're seeing the root directory separator
auto PP = CreateBegin(Path);
bool InRootDir = PP.State == PS_InRootName &&
&PP.RawEntry.back() == SepEnd;
return makeState(InRootDir ? PS_InRootDir : PS_InTrailingSep,
SepEnd + 1, RStart + 1);
} else {
PosPtr TkStart = consumeName(RStart, REnd);
if (TkStart == REnd + 2 && consumeSeparator(TkStart, REnd) == REnd)
return makeState(PS_InRootName, Path.data(), RStart + 1);
else
return makeState(PS_InFilenames, TkStart + 1, RStart + 1);
}
}
case PS_InTrailingSep:
return makeState(PS_InFilenames, consumeName(RStart, REnd) + 1, RStart + 1);
case PS_InFilenames: {
PosPtr SepEnd = consumeSeparator(RStart, REnd);
if (SepEnd == REnd)
return makeState((RStart == REnd + 2) ? PS_InRootName : PS_InRootDir,
Path.data(), RStart + 1);
PosPtr TkEnd = consumeName(SepEnd, REnd);
if (TkEnd == REnd + 2 && consumeSeparator(TkEnd, REnd) == REnd)
return makeState(PS_InRootDir, SepEnd + 1, RStart + 1);
return makeState(PS_InFilenames, TkEnd + 1, SepEnd + 1);
}
case PS_InRootDir:
return makeState(PS_InRootName, Path.data(), RStart + 1);
case PS_InRootName:
case PS_BeforeBegin:
_LIBCPP_UNREACHABLE();
}
}
/// \brief Return a view with the "preferred representation" of the current
/// element. For example trailing separators are represented as a '.'
string_view_t operator*() const noexcept {
switch (State) {
case PS_BeforeBegin:
case PS_AtEnd:
return "";
case PS_InRootDir:
return "/";
case PS_InTrailingSep:
return ".";
case PS_InRootName:
case PS_InFilenames:
return RawEntry;
}
_LIBCPP_UNREACHABLE();
}
explicit operator bool() const noexcept {
return State != PS_BeforeBegin && State != PS_AtEnd;
}
PathParser& operator++() noexcept {
increment();
return *this;
}
PathParser& operator--() noexcept {
decrement();
return *this;
}
private:
void makeState(ParserState NewState, PosPtr Start, PosPtr End) noexcept {
State = NewState;
RawEntry = string_view_t(Start, End - Start);
}
void makeState(ParserState NewState) noexcept {
State = NewState;
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.data();
case PS_InRootName:
case PS_InRootDir:
case PS_InFilenames:
return &RawEntry.back() + 1;
case PS_InTrailingSep:
case PS_AtEnd:
return getAfterBack();
}
_LIBCPP_UNREACHABLE();
}
/// \brief Return a pointer to the first character in the currently lexed
/// element.
PosPtr getCurrentTokenStartPos() const noexcept {
switch (State) {
case PS_BeforeBegin:
case PS_InRootName:
return &Path.front();
case PS_InRootDir:
case PS_InFilenames:
case PS_InTrailingSep:
return &RawEntry.front();
case PS_AtEnd:
return &Path.back() + 1;
}
_LIBCPP_UNREACHABLE();
}
PosPtr consumeSeparator(PosPtr P, PosPtr End) const noexcept {
if (P == End || *P != '/')
return nullptr;
const int Inc = P < End ? 1 : -1;
P += Inc;
while (P != End && *P == '/')
P += Inc;
return P;
}
PosPtr consumeName(PosPtr P, PosPtr End) const noexcept {
if (P == End || *P == '/')
return nullptr;
const int Inc = P < End ? 1 : -1;
P += Inc;
while (P != End && *P != '/')
P += Inc;
return P;
}
};
string_view_pair separate_filename(string_view_t const & s) {
if (s == "." || s == ".." || s.empty()) return string_view_pair{s, ""};
auto pos = s.find_last_of('.');
if (pos == string_view_t::npos)
return string_view_pair{s, string_view_t{}};
return string_view_pair{s.substr(0, pos), s.substr(pos)};
}
string_view_t createView(PosPtr S, PosPtr E) noexcept {
return {S, static_cast<size_t>(E - S) + 1};
}
}} // namespace parser
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
using parser::string_view_t;
using parser::string_view_pair;
using parser::PathParser;
using parser::createView;
///////////////////////////////////////////////////////////////////////////////
// path definitions
///////////////////////////////////////////////////////////////////////////////
constexpr path::value_type path::preferred_separator;
path & path::replace_extension(path const & replacement)
{
path p = extension();
if (not p.empty()) {
__pn_.erase(__pn_.size() - p.native().size());
}
if (!replacement.empty()) {
if (replacement.native()[0] != '.') {
__pn_ += ".";
}
__pn_.append(replacement.__pn_);
}
return *this;
}
///////////////////////////////////////////////////////////////////////////////
// path.decompose
string_view_t path::__root_name() const
{
auto PP = PathParser::CreateBegin(__pn_);
if (PP.State == PathParser::PS_InRootName)
return *PP;
return {};
}
string_view_t path::__root_directory() const
{
auto PP = PathParser::CreateBegin(__pn_);
if (PP.State == PathParser::PS_InRootName)
++PP;
if (PP.State == PathParser::PS_InRootDir)
return *PP;
return {};
}
string_view_t path::__root_path_raw() const
{
auto PP = PathParser::CreateBegin(__pn_);
if (PP.State == PathParser::PS_InRootName) {
auto NextCh = PP.peek();
if (NextCh && *NextCh == '/') {
++PP;
return createView(__pn_.data(), &PP.RawEntry.back());
}
return PP.RawEntry;
}
if (PP.State == PathParser::PS_InRootDir)
return *PP;
return {};
}
string_view_t path::__relative_path() const
{
auto PP = PathParser::CreateBegin(__pn_);
while (PP.State <= PathParser::PS_InRootDir)
++PP;
if (PP.State == PathParser::PS_AtEnd)
return {};
return createView(PP.RawEntry.data(), &__pn_.back());
}
string_view_t path::__parent_path() const
{
if (empty())
return {};
auto PP = PathParser::CreateEnd(__pn_);
--PP;
if (PP.RawEntry.data() == __pn_.data())
return {};
--PP;
return createView(__pn_.data(), &PP.RawEntry.back());
}
string_view_t path::__filename() const
{
if (empty()) return {};
return *(--PathParser::CreateEnd(__pn_));
}
string_view_t path::__stem() const
{
return parser::separate_filename(__filename()).first;
}
string_view_t path::__extension() const
{
return parser::separate_filename(__filename()).second;
}
////////////////////////////////////////////////////////////////////////////
// path.comparisons
int path::__compare(string_view_t __s) const {
auto PP = PathParser::CreateBegin(__pn_);
auto PP2 = PathParser::CreateBegin(__s);
while (PP && PP2) {
int res = (*PP).compare(*PP2);
if (res != 0) return res;
++PP; ++PP2;
}
if (PP.State == PP2.State && PP.State == PathParser::PS_AtEnd)
return 0;
if (PP.State == PathParser::PS_AtEnd)
return -1;
return 1;
}
////////////////////////////////////////////////////////////////////////////
// path.nonmembers
size_t hash_value(const path& __p) noexcept {
auto PP = PathParser::CreateBegin(__p.native());
size_t hash_value = 0;
std::hash<string_view_t> hasher;
while (PP) {
hash_value = __hash_combine(hash_value, hasher(*PP));
++PP;
}
return hash_value;
}
////////////////////////////////////////////////////////////////////////////
// path.itr
path::iterator path::begin() const
{
auto PP = PathParser::CreateBegin(__pn_);
iterator it;
it.__path_ptr_ = this;
it.__state_ = PP.State;
it.__entry_ = PP.RawEntry;
it.__stashed_elem_.__assign_view(*PP);
return it;
}
path::iterator path::end() const
{
iterator it{};
it.__state_ = PathParser::PS_AtEnd;
it.__path_ptr_ = this;
return it;
}
path::iterator& path::iterator::__increment() {
static_assert(__at_end == PathParser::PS_AtEnd, "");
PathParser PP(__path_ptr_->native(), __entry_, __state_);
++PP;
__state_ = PP.State;
__entry_ = PP.RawEntry;
__stashed_elem_.__assign_view(*PP);
return *this;
}
path::iterator& path::iterator::__decrement() {
PathParser PP(__path_ptr_->native(), __entry_, __state_);
--PP;
__state_ = PP.State;
__entry_ = PP.RawEntry;
__stashed_elem_.__assign_view(*PP);
return *this;
}
_LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM

View File

@ -0,0 +1,143 @@
//===------------------------ memory_resource.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/memory_resource"
#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
#include "atomic"
#elif !defined(_LIBCPP_HAS_NO_THREADS)
#include "mutex"
#endif
_LIBCPP_BEGIN_NAMESPACE_LFTS_PMR
// memory_resource
//memory_resource::~memory_resource() {}
// new_delete_resource()
class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp
: public memory_resource
{
public:
~__new_delete_memory_resource_imp() = default;
protected:
virtual void* do_allocate(size_t __size, size_t __align)
{ return __allocate(__size); }
virtual void do_deallocate(void * __p, size_t, size_t)
{ _VSTD::__libcpp_deallocate(__p); }
virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
{ return &__other == this; }
};
// null_memory_resource()
class _LIBCPP_TYPE_VIS __null_memory_resource_imp
: public memory_resource
{
public:
~__null_memory_resource_imp() = default;
protected:
virtual void* do_allocate(size_t, size_t) {
__throw_bad_alloc();
}
virtual void do_deallocate(void *, size_t, size_t) {}
virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT
{ return &__other == this; }
};
namespace {
union ResourceInitHelper {
struct {
__new_delete_memory_resource_imp new_delete_res;
__null_memory_resource_imp null_res;
} resources;
char dummy;
_LIBCPP_CONSTEXPR_AFTER_CXX11 ResourceInitHelper() : resources() {}
~ResourceInitHelper() {}
};
// When compiled in C++14 this initialization should be a constant expression.
// Only in C++11 is "init_priority" needed to ensure initialization order.
#if _LIBCPP_STD_VER > 11
_LIBCPP_SAFE_STATIC
#endif
ResourceInitHelper res_init __attribute__((init_priority (101)));
} // end namespace
memory_resource * new_delete_resource() _NOEXCEPT {
return &res_init.resources.new_delete_res;
}
memory_resource * null_memory_resource() _NOEXCEPT {
return &res_init.resources.null_res;
}
// default_memory_resource()
static memory_resource *
__default_memory_resource(bool set = false, memory_resource * new_res = nullptr) _NOEXCEPT
{
#ifndef _LIBCPP_HAS_NO_ATOMIC_HEADER
_LIBCPP_SAFE_STATIC static atomic<memory_resource*> __res =
ATOMIC_VAR_INIT(&res_init.resources.new_delete_res);
if (set) {
new_res = new_res ? new_res : new_delete_resource();
// TODO: Can a weaker ordering be used?
return _VSTD::atomic_exchange_explicit(
&__res, new_res, memory_order::memory_order_acq_rel);
}
else {
return _VSTD::atomic_load_explicit(
&__res, memory_order::memory_order_acquire);
}
#elif !defined(_LIBCPP_HAS_NO_THREADS)
_LIBCPP_SAFE_STATIC static memory_resource * res = &res_init.resources.new_delete_res;
static mutex res_lock;
if (set) {
new_res = new_res ? new_res : new_delete_resource();
lock_guard<mutex> guard(res_lock);
memory_resource * old_res = res;
res = new_res;
return old_res;
} else {
lock_guard<mutex> guard(res_lock);
return res;
}
#else
_LIBCPP_SAFE_STATIC static memory_resource* res = &res_init.resources.new_delete_res;
if (set) {
new_res = new_res ? new_res : new_delete_resource();
memory_resource * old_res = res;
res = new_res;
return old_res;
} else {
return res;
}
#endif
}
memory_resource * get_default_resource() _NOEXCEPT
{
return __default_memory_resource();
}
memory_resource * set_default_resource(memory_resource * __new_res) _NOEXCEPT
{
return __default_memory_resource(true, __new_res);
}
_LIBCPP_END_NAMESPACE_LFTS_PMR

View File

@ -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

View File

@ -0,0 +1,303 @@
//===------------------------- future.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 "__config"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "future"
#include "string"
_LIBCPP_BEGIN_NAMESPACE_STD
class _LIBCPP_HIDDEN __future_error_category
: public __do_message
{
public:
virtual const char* name() const _NOEXCEPT;
virtual string message(int ev) const;
};
const char*
__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
{
switch (static_cast<future_errc>(ev))
{
case future_errc(0): // For backwards compatibility with C++11 (LWG 2056)
case future_errc::broken_promise:
return string("The associated promise has been destructed prior "
"to the associated state becoming ready.");
case future_errc::future_already_retrieved:
return string("The future has already been retrieved from "
"the promise or packaged_task.");
case future_errc::promise_already_satisfied:
return string("The state of the promise has already been set.");
case future_errc::no_state:
return string("Operation not permitted on an object without "
"an associated state.");
}
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
{
static __future_error_category __f;
return __f;
}
future_error::future_error(error_code __ec)
: logic_error(__ec.message()),
__ec_(__ec)
{
}
future_error::~future_error() _NOEXCEPT
{
}
void
__assoc_sub_state::__on_zero_shared() _NOEXCEPT
{
delete this;
}
void
__assoc_sub_state::set_value()
{
unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__state_ |= __constructed | ready;
__cv_.notify_all();
}
void
__assoc_sub_state::set_value_at_thread_exit()
{
unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__state_ |= __constructed;
__thread_local_data()->__make_ready_at_thread_exit(this);
}
void
__assoc_sub_state::set_exception(exception_ptr __p)
{
unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__exception_ = __p;
__state_ |= ready;
__cv_.notify_all();
}
void
__assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p)
{
unique_lock<mutex> __lk(__mut_);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__has_value())
throw future_error(make_error_code(future_errc::promise_already_satisfied));
#endif
__exception_ = __p;
__thread_local_data()->__make_ready_at_thread_exit(this);
}
void
__assoc_sub_state::__make_ready()
{
unique_lock<mutex> __lk(__mut_);
__state_ |= ready;
__cv_.notify_all();
}
void
__assoc_sub_state::copy()
{
unique_lock<mutex> __lk(__mut_);
__sub_wait(__lk);
if (__exception_ != nullptr)
rethrow_exception(__exception_);
}
void
__assoc_sub_state::wait()
{
unique_lock<mutex> __lk(__mut_);
__sub_wait(__lk);
}
void
__assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk)
{
if (!__is_ready())
{
if (__state_ & static_cast<unsigned>(deferred))
{
__state_ &= ~static_cast<unsigned>(deferred);
__lk.unlock();
__execute();
}
else
while (!__is_ready())
__cv_.wait(__lk);
}
}
void
__assoc_sub_state::__execute()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw future_error(make_error_code(future_errc::no_state));
#endif
}
future<void>::future(__assoc_sub_state* __state)
: __state_(__state)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_->__has_future_attached())
throw future_error(make_error_code(future_errc::future_already_retrieved));
#endif
__state_->__add_shared();
__state_->__set_future_attached();
}
future<void>::~future()
{
if (__state_)
__state_->__release_shared();
}
void
future<void>::get()
{
unique_ptr<__shared_count, __release_shared_count> __(__state_);
__assoc_sub_state* __s = __state_;
__state_ = nullptr;
__s->copy();
}
promise<void>::promise()
: __state_(new __assoc_sub_state)
{
}
promise<void>::~promise()
{
if (__state_)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!__state_->__has_value() && __state_->use_count() > 1)
__state_->set_exception(make_exception_ptr(
future_error(make_error_code(future_errc::broken_promise))
));
#endif // _LIBCPP_NO_EXCEPTIONS
__state_->__release_shared();
}
}
future<void>
promise<void>::get_future()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state));
#endif
return future<void>(__state_);
}
void
promise<void>::set_value()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value();
}
void
promise<void>::set_exception(exception_ptr __p)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception(__p);
}
void
promise<void>::set_value_at_thread_exit()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_value_at_thread_exit();
}
void
promise<void>::set_exception_at_thread_exit(exception_ptr __p)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__state_ == nullptr)
throw future_error(make_error_code(future_errc::no_state));
#endif
__state_->set_exception_at_thread_exit(__p);
}
shared_future<void>::~shared_future()
{
if (__state_)
__state_->__release_shared();
}
shared_future<void>&
shared_future<void>::operator=(const shared_future& __rhs)
{
if (__rhs.__state_)
__rhs.__state_->__add_shared();
if (__state_)
__state_->__release_shared();
__state_ = __rhs.__state_;
return *this;
}
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,177 @@
//===----------------------------------------------------------------------===////
//
// 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 ATOMIC_SUPPORT_H
#define ATOMIC_SUPPORT_H
#include "__config"
#include "memory" // for __libcpp_relaxed_load
#if defined(__clang__) && __has_builtin(__atomic_load_n) \
&& __has_builtin(__atomic_store_n) \
&& __has_builtin(__atomic_add_fetch) \
&& __has_builtin(__atomic_exchange_n) \
&& __has_builtin(__atomic_compare_exchange_n) \
&& defined(__ATOMIC_RELAXED) \
&& defined(__ATOMIC_CONSUME) \
&& defined(__ATOMIC_ACQUIRE) \
&& defined(__ATOMIC_RELEASE) \
&& defined(__ATOMIC_ACQ_REL) \
&& defined(__ATOMIC_SEQ_CST)
# define _LIBCPP_HAS_ATOMIC_BUILTINS
#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
# define _LIBCPP_HAS_ATOMIC_BUILTINS
#endif
#if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
# if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
# else
# warning Building libc++ without __atomic builtins is unsupported
# endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
namespace {
#if defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
enum __libcpp_atomic_order {
_AO_Relaxed = __ATOMIC_RELAXED,
_AO_Consume = __ATOMIC_CONSUME,
_AO_Acquire = __ATOMIC_ACQUIRE,
_AO_Release = __ATOMIC_RELEASE,
_AO_Acq_Rel = __ATOMIC_ACQ_REL,
_AO_Seq = __ATOMIC_SEQ_CST
};
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
int __order = _AO_Seq)
{
__atomic_store_n(__dest, __val, __order);
}
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
{
__atomic_store_n(__dest, __val, _AO_Relaxed);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_load(_ValueType const* __val,
int __order = _AO_Seq)
{
return __atomic_load_n(__val, __order);
}
template <class _ValueType, class _AddType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
int __order = _AO_Seq)
{
return __atomic_add_fetch(__val, __a, __order);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_exchange(_ValueType* __target,
_ValueType __value, int __order = _AO_Seq)
{
return __atomic_exchange_n(__target, __value, __order);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
bool __libcpp_atomic_compare_exchange(_ValueType* __val,
_ValueType* __expected, _ValueType __after,
int __success_order = _AO_Seq,
int __fail_order = _AO_Seq)
{
return __atomic_compare_exchange_n(__val, __expected, __after, true,
__success_order, __fail_order);
}
#else // _LIBCPP_HAS_NO_THREADS
enum __libcpp_atomic_order {
_AO_Relaxed,
_AO_Consume,
_AO_Acquire,
_AO_Release,
_AO_Acq_Rel,
_AO_Seq
};
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
int = 0)
{
*__dest = __val;
}
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
{
*__dest = __val;
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_load(_ValueType const* __val,
int = 0)
{
return *__val;
}
template <class _ValueType, class _AddType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
int = 0)
{
return *__val += __a;
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_exchange(_ValueType* __target,
_ValueType __value, int __order = _AO_Seq)
{
_ValueType old = *__target;
*__target = __value;
return old;
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
bool __libcpp_atomic_compare_exchange(_ValueType* __val,
_ValueType* __expected, _ValueType __after,
int = 0, int = 0)
{
if (*__val == *__expected) {
*__val = __after;
return true;
}
*__expected = *__val;
return false;
}
#endif // _LIBCPP_HAS_NO_THREADS
} // end namespace
_LIBCPP_END_NAMESPACE_STD
#endif // ATOMIC_SUPPORT_H

View File

@ -0,0 +1,40 @@
//===----------------------- config_elast.h -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_CONFIG_ELAST
#define _LIBCPP_CONFIG_ELAST
#include <__config>
#if defined(_LIBCPP_MSVCRT)
#include <stdlib.h>
#else
#include <errno.h>
#endif
#if defined(ELAST)
#define _LIBCPP_ELAST ELAST
#elif defined(_NEWLIB_VERSION)
#define _LIBCPP_ELAST __ELASTERROR
#elif defined(__Fuchsia__)
// No _LIBCPP_ELAST needed on Fuchsia
#elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC)
#define _LIBCPP_ELAST 4095
#elif defined(__APPLE__)
// No _LIBCPP_ELAST needed on Apple
#elif defined(__sun__)
#define _LIBCPP_ELAST ESTALE
#elif defined(_LIBCPP_MSVCRT)
#define _LIBCPP_ELAST (_sys_nerr - 1)
#else
// Warn here so that the person doing the libcxx port has an easier time:
#warning ELAST for this platform not yet implemented
#endif
#endif // _LIBCPP_CONFIG_ELAST

View File

@ -0,0 +1,128 @@
//===------------------------ __refstring ---------------------------------===//
//
// 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_REFSTRING_H
#define _LIBCPP_REFSTRING_H
#include <__config>
#include <stdexcept>
#include <cstddef>
#include <cstring>
#ifdef __APPLE__
#include <dlfcn.h>
#include <mach-o/dyld.h>
#endif
#include "atomic_support.h"
_LIBCPP_BEGIN_NAMESPACE_STD
namespace __refstring_imp { namespace {
typedef int count_t;
struct _Rep_base {
std::size_t len;
std::size_t cap;
count_t count;
};
inline _Rep_base* rep_from_data(const char *data_) noexcept {
char *data = const_cast<char *>(data_);
return reinterpret_cast<_Rep_base *>(data - sizeof(_Rep_base));
}
inline char * data_from_rep(_Rep_base *rep) noexcept {
char *data = reinterpret_cast<char *>(rep);
return data + sizeof(*rep);
}
#if defined(__APPLE__)
inline
const char* compute_gcc_empty_string_storage() _NOEXCEPT
{
void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD);
if (handle == nullptr)
return nullptr;
void* sym = dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE");
if (sym == nullptr)
return nullptr;
return data_from_rep(reinterpret_cast<_Rep_base *>(sym));
}
inline
const char*
get_gcc_empty_string_storage() _NOEXCEPT
{
static const char* p = compute_gcc_empty_string_storage();
return p;
}
#endif
}} // namespace __refstring_imp
using namespace __refstring_imp;
inline
__libcpp_refstring::__libcpp_refstring(const char* msg) {
std::size_t len = strlen(msg);
_Rep_base* rep = static_cast<_Rep_base *>(::operator new(sizeof(*rep) + len + 1));
rep->len = len;
rep->cap = len;
rep->count = 0;
char *data = data_from_rep(rep);
std::memcpy(data, msg, len + 1);
__imp_ = data;
}
inline
__libcpp_refstring::__libcpp_refstring(const __libcpp_refstring &s) _NOEXCEPT
: __imp_(s.__imp_)
{
if (__uses_refcount())
__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
}
inline
__libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) _NOEXCEPT {
bool adjust_old_count = __uses_refcount();
struct _Rep_base *old_rep = rep_from_data(__imp_);
__imp_ = s.__imp_;
if (__uses_refcount())
__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
if (adjust_old_count)
{
if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0)
{
::operator delete(old_rep);
}
}
return *this;
}
inline
__libcpp_refstring::~__libcpp_refstring() {
if (__uses_refcount()) {
_Rep_base* rep = rep_from_data(__imp_);
if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) {
::operator delete(rep);
}
}
}
inline
bool __libcpp_refstring::__uses_refcount() const {
#ifdef __APPLE__
return __imp_ != get_gcc_empty_string_storage();
#else
return true;
#endif
}
_LIBCPP_END_NAMESPACE_STD
#endif //_LIBCPP_REFSTRING_H

467
external/llvm-project/libcxx/src/ios.cpp vendored Normal file
View File

@ -0,0 +1,467 @@
//===-------------------------- ios.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 "__config"
#include "ios"
#include <stdlib.h>
#include "__locale"
#include "algorithm"
#include "include/config_elast.h"
#include "istream"
#include "limits"
#include "memory"
#include "new"
#include "streambuf"
#include "string"
#include "__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_iostream<char>;
class _LIBCPP_HIDDEN __iostream_category
: public __do_message
{
public:
virtual const char* name() const _NOEXCEPT;
virtual string message(int ev) const;
};
const char*
__iostream_category::name() const _NOEXCEPT
{
return "iostream";
}
string
__iostream_category::message(int ev) const
{
if (ev != static_cast<int>(io_errc::stream)
#ifdef _LIBCPP_ELAST
&& ev <= _LIBCPP_ELAST
#endif // _LIBCPP_ELAST
)
return __do_message::message(ev);
return string("unspecified iostream_category error");
}
const error_category&
iostream_category() _NOEXCEPT
{
static __iostream_category s;
return s;
}
// ios_base::failure
ios_base::failure::failure(const string& msg, const error_code& ec)
: system_error(ec, msg)
{
}
ios_base::failure::failure(const char* msg, const error_code& ec)
: system_error(ec, msg)
{
}
ios_base::failure::~failure() throw()
{
}
// ios_base locale
const ios_base::fmtflags ios_base::boolalpha;
const ios_base::fmtflags ios_base::dec;
const ios_base::fmtflags ios_base::fixed;
const ios_base::fmtflags ios_base::hex;
const ios_base::fmtflags ios_base::internal;
const ios_base::fmtflags ios_base::left;
const ios_base::fmtflags ios_base::oct;
const ios_base::fmtflags ios_base::right;
const ios_base::fmtflags ios_base::scientific;
const ios_base::fmtflags ios_base::showbase;
const ios_base::fmtflags ios_base::showpoint;
const ios_base::fmtflags ios_base::showpos;
const ios_base::fmtflags ios_base::skipws;
const ios_base::fmtflags ios_base::unitbuf;
const ios_base::fmtflags ios_base::uppercase;
const ios_base::fmtflags ios_base::adjustfield;
const ios_base::fmtflags ios_base::basefield;
const ios_base::fmtflags ios_base::floatfield;
const ios_base::iostate ios_base::badbit;
const ios_base::iostate ios_base::eofbit;
const ios_base::iostate ios_base::failbit;
const ios_base::iostate ios_base::goodbit;
const ios_base::openmode ios_base::app;
const ios_base::openmode ios_base::ate;
const ios_base::openmode ios_base::binary;
const ios_base::openmode ios_base::in;
const ios_base::openmode ios_base::out;
const ios_base::openmode ios_base::trunc;
void
ios_base::__call_callbacks(event ev)
{
for (size_t i = __event_size_; i;)
{
--i;
__fn_[i](ev, *this, __index_[i]);
}
}
// locale
locale
ios_base::imbue(const locale& newloc)
{
static_assert(sizeof(locale) == sizeof(__loc_), "");
locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
locale oldloc = loc_storage;
loc_storage = newloc;
__call_callbacks(imbue_event);
return oldloc;
}
locale
ios_base::getloc() const
{
const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
return loc_storage;
}
// xalloc
#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !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()
{
return __xindex_++;
}
long&
ios_base::iword(int index)
{
size_t req_size = static_cast<size_t>(index)+1;
if (req_size > __iarray_cap_)
{
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);
static long error;
error = 0;
return error;
}
__iarray_ = iarray;
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];
}
void*&
ios_base::pword(int index)
{
size_t req_size = static_cast<size_t>(index)+1;
if (req_size > __parray_cap_)
{
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);
static void* error;
error = 0;
return error;
}
__parray_ = parray;
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];
}
// register_callback
void
ios_base::register_callback(event_callback fn, int index)
{
size_t req_size = __event_size_ + 1;
if (req_size > __event_cap_)
{
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 = 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;
++__event_size_;
}
ios_base::~ios_base()
{
__call_callbacks(erase_event);
locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
loc_storage.~locale();
free(__fn_);
free(__index_);
free(__iarray_);
free(__parray_);
}
// iostate
void
ios_base::clear(iostate state)
{
if (__rdbuf_)
__rdstate_ = state;
else
__rdstate_ = state | badbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
throw failure("ios_base::clear");
#endif // _LIBCPP_NO_EXCEPTIONS
}
// init
void
ios_base::init(void* sb)
{
__rdbuf_ = sb;
__rdstate_ = __rdbuf_ ? goodbit : badbit;
__exceptions_ = goodbit;
__fmtflags_ = skipws | dec;
__width_ = 0;
__precision_ = 6;
__fn_ = 0;
__index_ = 0;
__event_size_ = 0;
__event_cap_ = 0;
__iarray_ = 0;
__iarray_size_ = 0;
__iarray_cap_ = 0;
__parray_ = 0;
__parray_size_ = 0;
__parray_cap_ = 0;
::new(&__loc_) locale;
}
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 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_)
{
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
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();
#endif // _LIBCPP_NO_EXCEPTIONS
}
if (__iarray_cap_ < 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();
#endif // _LIBCPP_NO_EXCEPTIONS
}
if (__parray_cap_ < 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();
#endif // _LIBCPP_NO_EXCEPTIONS
}
// Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_
__fmtflags_ = rhs.__fmtflags_;
__precision_ = rhs.__precision_;
__width_ = rhs.__width_;
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_)
{
free(__fn_);
__fn_ = new_callbacks.release();
free(__index_);
__index_ = new_ints.release();
__event_cap_ = rhs.__event_size_;
}
for (__event_size_ = 0; __event_size_ < rhs.__event_size_; ++__event_size_)
{
__fn_[__event_size_] = rhs.__fn_[__event_size_];
__index_[__event_size_] = rhs.__index_[__event_size_];
}
if (__iarray_cap_ < rhs.__iarray_size_)
{
free(__iarray_);
__iarray_ = new_longs.release();
__iarray_cap_ = rhs.__iarray_size_;
}
for (__iarray_size_ = 0; __iarray_size_ < rhs.__iarray_size_; ++__iarray_size_)
__iarray_[__iarray_size_] = rhs.__iarray_[__iarray_size_];
if (__parray_cap_ < rhs.__parray_size_)
{
free(__parray_);
__parray_ = new_pointers.release();
__parray_cap_ = rhs.__parray_size_;
}
for (__parray_size_ = 0; __parray_size_ < rhs.__parray_size_; ++__parray_size_)
__parray_[__parray_size_] = rhs.__parray_[__parray_size_];
}
void
ios_base::move(ios_base& rhs)
{
// *this is uninitialized
__fmtflags_ = rhs.__fmtflags_;
__precision_ = rhs.__precision_;
__width_ = rhs.__width_;
__rdstate_ = rhs.__rdstate_;
__exceptions_ = rhs.__exceptions_;
__rdbuf_ = 0;
locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
::new(&__loc_) locale(rhs_loc);
__fn_ = rhs.__fn_;
rhs.__fn_ = 0;
__index_ = rhs.__index_;
rhs.__index_ = 0;
__event_size_ = rhs.__event_size_;
rhs.__event_size_ = 0;
__event_cap_ = rhs.__event_cap_;
rhs.__event_cap_ = 0;
__iarray_ = rhs.__iarray_;
rhs.__iarray_ = 0;
__iarray_size_ = rhs.__iarray_size_;
rhs.__iarray_size_ = 0;
__iarray_cap_ = rhs.__iarray_cap_;
rhs.__iarray_cap_ = 0;
__parray_ = rhs.__parray_;
rhs.__parray_ = 0;
__parray_size_ = rhs.__parray_size_;
rhs.__parray_size_ = 0;
__parray_cap_ = rhs.__parray_cap_;
rhs.__parray_cap_ = 0;
}
void
ios_base::swap(ios_base& rhs) _NOEXCEPT
{
_VSTD::swap(__fmtflags_, rhs.__fmtflags_);
_VSTD::swap(__precision_, rhs.__precision_);
_VSTD::swap(__width_, rhs.__width_);
_VSTD::swap(__rdstate_, rhs.__rdstate_);
_VSTD::swap(__exceptions_, rhs.__exceptions_);
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_);
_VSTD::swap(__event_size_, rhs.__event_size_);
_VSTD::swap(__event_cap_, rhs.__event_cap_);
_VSTD::swap(__iarray_, rhs.__iarray_);
_VSTD::swap(__iarray_size_, rhs.__iarray_size_);
_VSTD::swap(__iarray_cap_, rhs.__iarray_cap_);
_VSTD::swap(__parray_, rhs.__parray_);
_VSTD::swap(__parray_size_, rhs.__parray_size_);
_VSTD::swap(__parray_cap_, rhs.__parray_cap_);
}
void
ios_base::__set_badbit_and_consider_rethrow()
{
__rdstate_ |= badbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__exceptions_ & badbit)
throw;
#endif // _LIBCPP_NO_EXCEPTIONS
}
void
ios_base::__set_failbit_and_consider_rethrow()
{
__rdstate_ |= failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__exceptions_ & failbit)
throw;
#endif // _LIBCPP_NO_EXCEPTIONS
}
bool
ios_base::sync_with_stdio(bool sync)
{
static bool previous_state = true;
bool r = previous_state;
previous_state = sync;
return r;
}
_LIBCPP_END_NAMESPACE_STD

View File

@ -0,0 +1,124 @@
//===------------------------ iostream.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 "__std_stream"
#include "string"
#include "new"
#define _str(s) #s
#define str(s) _str(s)
#define _LIBCPP_NAMESPACE_STR str(_LIBCPP_NAMESPACE)
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_STDIN
_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?cin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
static mbstate_t mb_cin;
_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wcin@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
static mbstate_t mb_wcin;
#endif
#ifndef _LIBCPP_HAS_NO_STDOUT
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?cout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
static mbstate_t mb_cout;
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wcout@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
static mbstate_t mb_wcout;
#endif
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?cerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
static mbstate_t mb_cerr;
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wcerr@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
static mbstate_t mb_wcerr;
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?clog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wclog@" _LIBCPP_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_NAMESPACE_STR "@std@@@12@A")
#endif
;
ios_base::Init __start_std_streams;
ios_base::Init::Init()
{
#ifndef _LIBCPP_HAS_NO_STDIN
istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin));
wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin));
#endif
#ifndef _LIBCPP_HAS_NO_STDOUT
ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout));
wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
#endif
ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
::new(clog) ostream(cerr_ptr->rdbuf());
wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
::new(wclog) wostream(wcerr_ptr->rdbuf());
#if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
cin_ptr->tie(cout_ptr);
wcin_ptr->tie(wcout_ptr);
#endif
_VSTD::unitbuf(*cerr_ptr);
_VSTD::unitbuf(*wcerr_ptr);
#ifndef _LIBCPP_HAS_NO_STDOUT
cerr_ptr->tie(cout_ptr);
wcerr_ptr->tie(wcout_ptr);
#endif
}
ios_base::Init::~Init()
{
#ifndef _LIBCPP_HAS_NO_STDOUT
ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
cout_ptr->flush();
wcout_ptr->flush();
#endif
ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
clog_ptr->flush();
wclog_ptr->flush();
}
_LIBCPP_END_NAMESPACE_STD

Some files were not shown because too many files have changed in this diff Show More