MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / unwindProtect

Function unwindProtect

inst/include/Rcpp/unwindProtect.h:54–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52namespace Rcpp {
53
54inline 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
73inline SEXP unwindProtect(std::function<SEXP(void)> callback) {
74 return unwindProtect(&internal::unwindProtectUnwrap, &callback);

Callers 4

testUnwindProtectFunction · 0.85
testUnwindProtectLambdaFunction · 0.85
Rcpp_fast_evalFunction · 0.85

Calls 1

LongjumpExceptionClass · 0.85

Tested by

no test coverage detected