Skip to content

Commit 3a3e90d

Browse files
committed
Deduplicate ref-counted implementations
1 parent 8a8d2ff commit 3a3e90d

File tree

5 files changed

+40
-61
lines changed

5 files changed

+40
-61
lines changed

libcxx/src/exception.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ using namespace __cxxabiv1;
2424
# include "support/runtime/exception_pointer_msvc.ipp"
2525
#elif defined(_LIBCPPABI_VERSION)
2626
# include "support/runtime/exception_libcxxabi.ipp"
27+
# include "support/runtime/exception_pointer_refcounted.ipp"
2728
# include "support/runtime/exception_pointer_cxxabi.ipp"
2829
#elif defined(LIBCXXRT)
2930
# include "support/runtime/exception_libcxxrt.ipp"
31+
# include "support/runtime/exception_pointer_refcounted.ipp"
3032
# include "support/runtime/exception_pointer_cxxabi.ipp"
3133
#elif defined(__GLIBCXX__)
3234
# include "support/runtime/exception_glibcxx.ipp"
35+
# include "support/runtime/exception_pointer_refcounted.ipp"
3336
# include "support/runtime/exception_pointer_glibcxx.ipp"
3437
#else
3538
# include "include/atomic_support.h"

libcxx/src/support/runtime/exception_pointer_cxxabi.ipp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,6 @@ void exception_ptr::__decrement_refcount([[__gnu__::__nonnull__]] _LIBCPP_NOESCA
2121
__cxa_decrement_exception_refcount(__ptr);
2222
}
2323

24-
exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {
25-
exception_ptr ptr;
26-
ptr.__ptr_ = __e;
27-
__cxa_increment_exception_refcount(ptr.__ptr_);
28-
29-
return ptr;
30-
}
31-
32-
exception_ptr::~exception_ptr() noexcept { __decrement_refcount(__ptr_); }
33-
34-
exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
35-
__increment_refcount(__ptr_);
36-
}
37-
38-
exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
39-
if (__ptr_ != other.__ptr_) {
40-
__increment_refcount(other.__ptr_);
41-
__decrement_refcount(__ptr_);
42-
__ptr_ = other.__ptr_;
43-
}
44-
return *this;
45-
}
46-
4724
nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
4825

4926
nested_exception::~nested_exception() noexcept {}

libcxx/src/support/runtime/exception_pointer_glibcxx.ipp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,6 @@ void exception_ptr::__decrement_refcount([[__gnu__::__nonnull__]] _LIBCPP_NOESCA
3838
reinterpret_cast<__exception_ptr::exception_ptr*>(this)->_M_release();
3939
}
4040

41-
exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {
42-
exception_ptr ptr{};
43-
new (reinterpret_cast<void*>(&ptr)) __exception_ptr::exception_ptr(__e);
44-
45-
return ptr;
46-
}
47-
48-
exception_ptr::~exception_ptr() noexcept { __decrement_refcount(__ptr_); }
49-
50-
exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
51-
__increment_refcount(__ptr_);
52-
}
53-
54-
exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
55-
if (__ptr_ != other.__ptr_) {
56-
__increment_refcount(other.__ptr_);
57-
__decrement_refcount(__ptr_);
58-
__ptr_ = other.__ptr_;
59-
}
60-
return *this;
61-
}
62-
6341
nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
6442

6543
[[noreturn]] void nested_exception::rethrow_nested() const {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
// Provides the common functionality shared between cxxabi and glibcxx.
11+
12+
namespace std {
13+
14+
exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept {
15+
exception_ptr ptr;
16+
ptr.__ptr_ = __e;
17+
__increment_refcount(ptr.__ptr_);
18+
19+
return ptr;
20+
}
21+
22+
exception_ptr::~exception_ptr() noexcept { __decrement_refcount(__ptr_); }
23+
24+
exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
25+
__increment_refcount(__ptr_);
26+
}
27+
28+
exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
29+
if (__ptr_ != other.__ptr_) {
30+
__increment_refcount(other.__ptr_);
31+
__decrement_refcount(__ptr_);
32+
__ptr_ = other.__ptr_;
33+
}
34+
return *this;
35+
}
36+
37+
} // namespace std

libcxx/src/support/runtime/exception_pointer_unimplemented.ipp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ void exception_ptr::__decrement_refcount([[__gnu__::__nonnull__]] _LIBCPP_NOESCA
2121
__libcpp_verbose_abort("exception_ptr not yet implemented\n");
2222
}
2323

24-
exception_ptr exception_ptr::__from_native_exception_pointer(void *__e) noexcept {
25-
__libcpp_verbose_abort("exception_ptr not yet implemented\n");
26-
}
27-
28-
exception_ptr::~exception_ptr() noexcept {
29-
__libcpp_verbose_abort("exception_ptr not yet implemented\n");
30-
}
31-
32-
exception_ptr::exception_ptr(const exception_ptr& other) noexcept : __ptr_(other.__ptr_) {
33-
__libcpp_verbose_abort("exception_ptr not yet implemented\n");
34-
}
35-
36-
exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept {
37-
__libcpp_verbose_abort("exception_ptr not yet implemented\n");
38-
}
39-
4024
nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
4125

4226
#if !defined(__GLIBCXX__)

0 commit comments

Comments
 (0)