@@ -70,8 +70,6 @@ inline Rboolean& get_should_unwind_protect() {
70
70
return should_unwind_protect[0 ];
71
71
}
72
72
73
- static Rboolean& should_unwind_protect = get_should_unwind_protect();
74
-
75
73
} // namespace detail
76
74
77
75
#ifdef HAS_UNWIND_PROTECT
@@ -82,11 +80,12 @@ static Rboolean& should_unwind_protect = get_should_unwind_protect();
82
80
template <typename Fun, typename = typename std::enable_if<std::is_same<
83
81
decltype (std::declval<Fun&&>()()), SEXP>::value>::type>
84
82
SEXP unwind_protect(Fun&& code) {
85
- if (detail::should_unwind_protect == FALSE ) {
83
+ static auto should_unwind_protect = detail::get_should_unwind_protect ();
84
+ if (should_unwind_protect == FALSE ) {
86
85
return std::forward<Fun>(code)();
87
86
}
88
87
89
- detail:: should_unwind_protect = FALSE ;
88
+ should_unwind_protect = FALSE ;
90
89
91
90
static SEXP token = [] {
92
91
SEXP res = R_MakeUnwindCont ();
@@ -96,7 +95,7 @@ SEXP unwind_protect(Fun&& code) {
96
95
97
96
std::jmp_buf jmpbuf;
98
97
if (setjmp (jmpbuf)) {
99
- detail:: should_unwind_protect = TRUE ;
98
+ should_unwind_protect = TRUE ;
100
99
throw unwind_exception (token);
101
100
}
102
101
@@ -121,7 +120,7 @@ SEXP unwind_protect(Fun&& code) {
121
120
// unset it here before returning the value ourselves.
122
121
SETCAR (token, R_NilValue);
123
122
124
- detail:: should_unwind_protect = TRUE ;
123
+ should_unwind_protect = TRUE ;
125
124
126
125
return res;
127
126
}
0 commit comments