• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
23__ExceptionPtrCopyException(void*, const void*, const void*);
24
25namespace std {
26
27exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); }
28exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); }
29
30exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT {
31  __ExceptionPtrCopy(this, &__other);
32}
33exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _NOEXCEPT {
34  __ExceptionPtrAssign(this, &__other);
35  return *this;
36}
37
38exception_ptr& exception_ptr::operator=(nullptr_t) _NOEXCEPT {
39  exception_ptr dummy;
40  __ExceptionPtrAssign(this, &dummy);
41  return *this;
42}
43
44exception_ptr::~exception_ptr() _NOEXCEPT { __ExceptionPtrDestroy(this); }
45
46exception_ptr::operator bool() const _NOEXCEPT {
47  return __ExceptionPtrToBool(this);
48}
49
50bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
51  return __ExceptionPtrCompare(&__x, &__y);
52}
53
54
55void swap(exception_ptr& lhs, exception_ptr& rhs) _NOEXCEPT {
56  __ExceptionPtrSwap(&rhs, &lhs);
57}
58
59exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) {
60  exception_ptr __ret = nullptr;
61  if (__ptr)
62    __ExceptionPtrCopyException(&__ret, __except, __ptr);
63  return __ret;
64}
65
66exception_ptr current_exception() _NOEXCEPT {
67  exception_ptr __ret;
68  __ExceptionPtrCurrentException(&__ret);
69  return __ret;
70}
71
72_LIBCPP_NORETURN
73void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
74
75nested_exception::nested_exception() _NOEXCEPT : __ptr_(current_exception()) {}
76
77nested_exception::~nested_exception() _NOEXCEPT {}
78
79_LIBCPP_NORETURN
80void nested_exception::rethrow_nested() const {
81  if (__ptr_ == nullptr)
82    terminate();
83  rethrow_exception(__ptr_);
84}
85
86} // namespace std
87