Skip to content

Commit 293acca

Browse files
committed
Remove unwind protect global variable altogether
1 parent 04b08a3 commit 293acca

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# cpp11 (development version)
22

3+
* TODO (something about both the performance optimization being removed, and
4+
the danger of using nested unwind_protect() calls from within the same .Call
5+
entry point)
6+
37
# cpp11 0.4.5
48

59
* On 2023-07-20, cpp11 was temporarily rolled back to 0.4.3 manually by CRAN due

inst/include/cpp11/protect.hpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ inline void set_option(SEXP name, SEXP value) {
5454
SETCAR(opt, value);
5555
}
5656

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-
7357
} // namespace detail
7458

7559
#ifdef HAS_UNWIND_PROTECT
@@ -80,13 +64,6 @@ inline Rboolean& get_should_unwind_protect() {
8064
template <typename Fun, typename = typename std::enable_if<std::is_same<
8165
decltype(std::declval<Fun&&>()()), SEXP>::value>::type>
8266
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-
9067
static SEXP token = [] {
9168
SEXP res = R_MakeUnwindCont();
9269
R_PreserveObject(res);
@@ -95,7 +72,6 @@ SEXP unwind_protect(Fun&& code) {
9572

9673
std::jmp_buf jmpbuf;
9774
if (setjmp(jmpbuf)) {
98-
should_unwind_protect = TRUE;
9975
throw unwind_exception(token);
10076
}
10177

@@ -120,8 +96,6 @@ SEXP unwind_protect(Fun&& code) {
12096
// unset it here before returning the value ourselves.
12197
SETCAR(token, R_NilValue);
12298

123-
should_unwind_protect = TRUE;
124-
12599
return res;
126100
}
127101

0 commit comments

Comments
 (0)