| 52 | namespace Rcpp { |
| 53 | |
| 54 | inline SEXP unwindProtect(SEXP (*callback)(void* data), void* data) { |
| 55 | internal::UnwindData unwind_data; |
| 56 | Shield<SEXP> token(::R_MakeUnwindCont()); |
| 57 | |
| 58 | if (setjmp(unwind_data.jmpbuf)) { |
| 59 | // Keep the token protected while unwinding because R code might run |
| 60 | // in C++ destructors. Can't use PROTECT() for this because |
| 61 | // UNPROTECT() might be called in a destructor, for instance if a |
| 62 | // Shield<SEXP> is on the stack. |
| 63 | ::R_PreserveObject(token); |
| 64 | |
| 65 | throw LongjumpException(token); |
| 66 | } |
| 67 | |
| 68 | return ::R_UnwindProtect(callback, data, |
| 69 | internal::maybeJump, &unwind_data, |
| 70 | token); |
| 71 | } |
| 72 | |
| 73 | inline SEXP unwindProtect(std::function<SEXP(void)> callback) { |
| 74 | return unwindProtect(&internal::unwindProtectUnwrap, &callback); |
no test coverage detected