@@ -54,22 +54,6 @@ inline void set_option(SEXP name, SEXP value) {
54
54
SETCAR (opt, value);
55
55
}
56
56
57
- inline Rboolean& get_should_unwind_protect () {
58
- SEXP should_unwind_protect_sym = Rf_install (" cpp11_should_unwind_protect" );
59
- SEXP should_unwind_protect_sexp = Rf_GetOption1 (should_unwind_protect_sym);
60
- if (should_unwind_protect_sexp == R_NilValue) {
61
- should_unwind_protect_sexp = PROTECT (Rf_allocVector (LGLSXP, 1 ));
62
- detail::set_option (should_unwind_protect_sym, should_unwind_protect_sexp);
63
- UNPROTECT (1 );
64
- }
65
-
66
- Rboolean* should_unwind_protect =
67
- reinterpret_cast <Rboolean*>(LOGICAL (should_unwind_protect_sexp));
68
- should_unwind_protect[0 ] = TRUE ;
69
-
70
- return should_unwind_protect[0 ];
71
- }
72
-
73
57
} // namespace detail
74
58
75
59
#ifdef HAS_UNWIND_PROTECT
@@ -80,13 +64,6 @@ inline Rboolean& get_should_unwind_protect() {
80
64
template <typename Fun, typename = typename std::enable_if<std::is_same<
81
65
decltype (std::declval<Fun&&>()()), SEXP>::value>::type>
82
66
SEXP unwind_protect(Fun&& code) {
83
- static auto should_unwind_protect = detail::get_should_unwind_protect ();
84
- if (should_unwind_protect == FALSE ) {
85
- return std::forward<Fun>(code)();
86
- }
87
-
88
- should_unwind_protect = FALSE ;
89
-
90
67
static SEXP token = [] {
91
68
SEXP res = R_MakeUnwindCont ();
92
69
R_PreserveObject (res);
@@ -95,7 +72,6 @@ SEXP unwind_protect(Fun&& code) {
95
72
96
73
std::jmp_buf jmpbuf;
97
74
if (setjmp (jmpbuf)) {
98
- should_unwind_protect = TRUE ;
99
75
throw unwind_exception (token);
100
76
}
101
77
@@ -120,8 +96,6 @@ SEXP unwind_protect(Fun&& code) {
120
96
// unset it here before returning the value ourselves.
121
97
SETCAR (token, R_NilValue);
122
98
123
- should_unwind_protect = TRUE ;
124
-
125
99
return res;
126
100
}
127
101
0 commit comments