| 1 |
// -*- C++ -*- |
| 2 |
//===----------------------------------------------------------------------===// |
| 3 |
// |
| 4 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 |
// See https://llvm.org/LICENSE.txt for license information. |
| 6 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 |
// |
| 8 |
//===----------------------------------------------------------------------===// |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
|
| 13 |
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*); |
| 14 |
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*); |
| 15 |
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*); |
| 16 |
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*); |
| 17 |
_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*); |
| 18 |
_LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*); |
| 19 |
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*); |
| 20 |
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*); |
| 21 |
[[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*); |
| 22 |
_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopyException(void*, const void*, const void*); |
| 23 |
|
| 24 |
namespace std { |
| 25 |
|
| 26 |
exception_ptr::exception_ptr() noexcept { __ExceptionPtrCreate(this); } |
| 27 |
exception_ptr::exception_ptr(nullptr_t) noexcept { __ExceptionPtrCreate(this); } |
| 28 |
|
| 29 |
exception_ptr::exception_ptr(const exception_ptr& __other) noexcept { __ExceptionPtrCopy(this, &__other); } |
| 30 |
exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept { |
| 31 |
__ExceptionPtrAssign(this, &__other); |
| 32 |
return *this; |
| 33 |
} |
| 34 |
|
| 35 |
exception_ptr& exception_ptr::operator=(nullptr_t) noexcept { |
| 36 |
exception_ptr dummy; |
| 37 |
__ExceptionPtrAssign(this, &dummy); |
| 38 |
return *this; |
| 39 |
} |
| 40 |
|
| 41 |
exception_ptr::~exception_ptr() noexcept { __ExceptionPtrDestroy(this); } |
| 42 |
|
| 43 |
exception_ptr::operator bool() const noexcept { return __ExceptionPtrToBool(this); } |
| 44 |
|
| 45 |
bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept { |
| 46 |
return __ExceptionPtrCompare(&__x, &__y); |
| 47 |
} |
| 48 |
|
| 49 |
void swap(exception_ptr& lhs, exception_ptr& rhs) noexcept { __ExceptionPtrSwap(&rhs, &lhs); } |
| 50 |
|
| 51 |
exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) { |
| 52 |
exception_ptr __ret = nullptr; |
| 53 |
if (__ptr) |
| 54 |
__ExceptionPtrCopyException(&__ret, __except, __ptr); |
| 55 |
return __ret; |
| 56 |
} |
| 57 |
|
| 58 |
exception_ptr current_exception() noexcept { |
| 59 |
exception_ptr __ret; |
| 60 |
__ExceptionPtrCurrentException(&__ret); |
| 61 |
return __ret; |
| 62 |
} |
| 63 |
|
| 64 |
_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); } |
| 65 |
|
| 66 |
nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} |
| 67 |
|
| 68 |
nested_exception::~nested_exception() noexcept {} |
| 69 |
|
| 70 |
_LIBCPP_NORETURN void nested_exception::rethrow_nested() const { |
| 71 |
if (__ptr_ == nullptr) |
| 72 |
terminate(); |
| 73 |
rethrow_exception(__ptr_); |
| 74 |
} |
| 75 |
|
| 76 |
} // namespace std |