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 | #ifndef HAVE_DEPENDENT_EH_ABI |
11 | # error this header may only be used with libc++abi or libcxxrt |
12 | #endif |
13 | |
14 | namespace std { |
15 | |
16 | exception_ptr::~exception_ptr() noexcept { __cxa_decrement_exception_refcount(__ptr_); } |
17 | |
18 | exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) { |
19 | __cxa_increment_exception_refcount(__ptr_); |
20 | } |
21 | |
22 | exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept { |
23 | if (__ptr_ != other.__ptr_) { |
24 | __cxa_increment_exception_refcount(other.__ptr_); |
25 | __cxa_decrement_exception_refcount(__ptr_); |
26 | __ptr_ = other.__ptr_; |
27 | } |
28 | return *this; |
29 | } |
30 | |
31 | exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept { |
32 | exception_ptr ptr; |
33 | ptr.__ptr_ = __e; |
34 | __cxa_increment_exception_refcount(ptr.__ptr_); |
35 | |
36 | return ptr; |
37 | } |
38 | |
39 | nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {} |
40 | |
41 | nested_exception::~nested_exception() noexcept {} |
42 | |
43 | _LIBCPP_NORETURN void nested_exception::rethrow_nested() const { |
44 | if (__ptr_ == nullptr) |
45 | terminate(); |
46 | rethrow_exception(__ptr_); |
47 | } |
48 | |
49 | exception_ptr current_exception() noexcept { |
50 | // be nicer if there was a constructor that took a ptr, then |
51 | // this whole function would be just: |
52 | // return exception_ptr(__cxa_current_primary_exception()); |
53 | exception_ptr ptr; |
54 | ptr.__ptr_ = __cxa_current_primary_exception(); |
55 | return ptr; |
56 | } |
57 | |
58 | _LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { |
59 | __cxa_rethrow_primary_exception(p.__ptr_); |
60 | // if p.__ptr_ is NULL, above returns so we terminate |
61 | terminate(); |
62 | } |
63 | |
64 | } // namespace std |
65 | |