@@ -24,64 +24,76 @@ if (.runThisTest) {
2424
2525 .setUp <- Rcpp ::: unitTestSetup(" stack.cpp" )
2626
27- test.stackUnwinds <- function () {
28- # On old versions of R, Rcpp_fast_eval() falls back to Rcpp_eval() and
29- # leaks on longjumps
30- hasUnwind <- getRversion() > = " 3.5.0"
31- checkUnwound <- if (hasUnwind ) checkTrue else function (x ) checkTrue(! x )
32- testEvalUnwind <- function (expr , indicator ) {
33- testFastEval(expr , parent.frame(), indicator )
34- }
27+ # On old versions of R, Rcpp_fast_eval() falls back to Rcpp_eval() and
28+ # leaks on longjumps
29+ hasUnwind <- getRversion() > = " 3.5.0"
30+ checkUnwound <- if (hasUnwind ) checkTrue else function (x ) checkTrue(! x )
31+ EvalUnwind <- function (expr , indicator ) {
32+ testFastEval(expr , parent.frame(), indicator )
33+ }
3534
36- # On errors - Always unwound
35+ # Stack is always unwound on errors and interrupts
36+ test.stackUnwindsOnErrors <- function () {
3737 unwound <- FALSE
38- out <- tryCatch(testEvalUnwind (quote(stop(" err" )), unwound ), error = identity )
38+ out <- tryCatch(EvalUnwind (quote(stop(" err" )), unwound ), error = identity )
3939 checkTrue(unwound )
4040 msg <- if (hasUnwind ) " err" else " Evaluation error: err."
4141 checkIdentical(out $ message , msg )
42+ }
4243
43- # On interrupts - Always unwound
44+ test.stackUnwindsOnInterrupts <- function () {
4445 unwound <- FALSE
4546 expr <- quote({
4647 repeat testSendInterrupt()
4748 " returned"
4849 })
49- out <- tryCatch(testEvalUnwind (expr , unwound ), interrupt = function (c ) " onintr" )
50+ out <- tryCatch(EvalUnwind (expr , unwound ), interrupt = function (c ) " onintr" )
5051 checkTrue(unwound )
5152 checkIdentical(out , " onintr" )
5253
53- # On caught conditions
54+ }
55+
56+ test.stackUnwindsOnCaughtConditions <- function () {
5457 unwound <- FALSE
5558 expr <- quote(signalCondition(simpleCondition(" cnd" )))
56- cnd <- tryCatch(testEvalUnwind (expr , unwound ), condition = identity )
59+ cnd <- tryCatch(EvalUnwind (expr , unwound ), condition = identity )
5760 checkTrue(inherits(cnd , " simpleCondition" ))
5861 checkUnwound(unwound )
5962
60- # On restart jumps
63+ }
64+
65+ test.stackUnwindsOnRestartJumps <- function () {
6166 unwound <- FALSE
6267 expr <- quote(invokeRestart(" rst" ))
63- out <- withRestarts(testEvalUnwind (expr , unwound ), rst = function (... ) " restarted" )
68+ out <- withRestarts(EvalUnwind (expr , unwound ), rst = function (... ) " restarted" )
6469 checkIdentical(out , " restarted" )
6570 checkUnwound(unwound )
6671
67- # On returns
72+ }
73+
74+ test.stackUnwindsOnReturns <- function () {
6875 unwound <- FALSE
6976 expr <- quote(signalCondition(simpleCondition(NULL )))
7077 out <- callCC(function (k ) {
71- withCallingHandlers(testEvalUnwind (expr , unwound ),
78+ withCallingHandlers(EvalUnwind (expr , unwound ),
7279 simpleCondition = function (e ) k(" jumped" )
7380 )
7481 })
7582 checkIdentical(out , " jumped" )
7683 checkUnwound(unwound )
7784
78- # On returned condition
85+ }
86+
87+ test.stackUnwindsOnReturnedConditions <- function () {
7988 unwound <- FALSE
8089 cnd <- simpleError(" foo" )
81- out <- tryCatch(testEvalUnwind (quote(cnd ), unwound ),
90+ out <- tryCatch(EvalUnwind (quote(cnd ), unwound ),
8291 error = function (c ) " abort"
8392 )
8493 checkTrue(unwound )
94+
95+ # The old mechanism cannot differentiate between a returned error and a
96+ # thrown error
8597 if (hasUnwind ) {
8698 checkIdentical(out , cnd )
8799 } else {
0 commit comments