| 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 <exception> |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | |
| 14 | _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*); |
| 15 | _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*); |
| 16 | _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*); |
| 17 | _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*); |
| 18 | _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*); |
| 19 | _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*); |
| 20 | _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*); |
| 21 | _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*); |
| 22 | [[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*); |
| 23 | _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopyException(void*, const void*, const void*); |
| 24 | |
| 25 | namespace std { |
| 26 | |
| 27 | exception_ptr::exception_ptr() noexcept { __ExceptionPtrCreate(this); } |
| 28 | exception_ptr::exception_ptr(nullptr_t) noexcept { __ExceptionPtrCreate(this); } |
| 29 | |
| 30 | exception_ptr::exception_ptr(const exception_ptr& __other) noexcept { __ExceptionPtrCopy(this, &__other); } |
| 31 | exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept { |
| 32 | __ExceptionPtrAssign(this, &__other); |
| 33 | return *this; |
| 34 | } |
| 35 | |
| 36 | exception_ptr& exception_ptr::operator=(nullptr_t) noexcept { |
| 37 | exception_ptr dummy; |
| 38 | __ExceptionPtrAssign(this, &dummy); |
| 39 | return *this; |
| 40 | } |
| 41 | |
| 42 | exception_ptr::~exception_ptr() noexcept { __ExceptionPtrDestroy(this); } |
| 43 | |
| 44 | exception_ptr::operator bool() const noexcept { return __ExceptionPtrToBool(this); } |
| 45 | |
| 46 | bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept { |
| 47 | return __ExceptionPtrCompare(&__x, &__y); |
| 48 | } |
| 49 | |
| 50 | void swap(exception_ptr& lhs, exception_ptr& rhs) noexcept { __ExceptionPtrSwap(&rhs, &lhs); } |
| 51 | |
| 52 | exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) { |
| 53 | exception_ptr __ret = nullptr; |
| 54 | if (__ptr) |
| 55 | __ExceptionPtrCopyException(&__ret, __except, __ptr); |
| 56 | return __ret; |
| 57 | } |
| 58 | |
| 59 | exception_ptr current_exception() noexcept { |
| 60 | exception_ptr __ret; |
| 61 | __ExceptionPtrCurrentException(&__ret); |
| 62 | return __ret; |
| 63 | } |
| 64 | |
| 65 | [[noreturn]] void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); } |
| 66 | |
| 67 | nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} |
| 68 | |
| 69 | nested_exception::~nested_exception() noexcept {} |
| 70 | |
| 71 | [[noreturn]] void nested_exception::rethrow_nested() const { |
| 72 | if (__ptr_ == nullptr) |
| 73 | terminate(); |
| 74 | rethrow_exception(__ptr_); |
| 75 | } |
| 76 | |
| 77 | } // namespace std |