@@ -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() {
8064template <typename Fun, typename = typename std::enable_if<std::is_same<
8165 decltype (std::declval<Fun&&>()()), SEXP>::value>::type>
8266SEXP 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