Skip to content

Commit ed68d86

Browse files
committed
Merge pull request #313 from RcppCore/bugfix/reset-error-after-eval
Reset errors after evaluation (closes #312)
2 parents 7a4fadc + d4cbbcc commit ed68d86

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

ChangeLog

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
2015-06-25 Kevin Ushey <[email protected]>
1+
2015-06-25 Kevin Ushey <[email protected]>
22

3+
* inst/include/Rcpp/api/meat/Rcpp_eval.h: reset error after Rcpp_eval
4+
* inst/unitTests/cpp/Function.cpp: unit tests
5+
* inst/unitTests/runit.Function.R: unit tests
36
* inst/include/Rcpp/Function.h: catch empty error messages
47
* inst/include/Rcpp/api/meat/Rcpp_eval.h: protect call
58

inst/include/Rcpp/api/meat/Rcpp_eval.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ namespace Rcpp{
3838

3939
Shield<SEXP> expr(evalCall->expr) ;
4040

41-
reset_current_error() ;
42-
4341
Environment RCPP = Environment::Rcpp_namespace();
4442
SEXP withCallingHandlersSym = ::Rf_install("withCallingHandlers");
4543
SEXP tryCatchSym = ::Rf_install("tryCatch");
@@ -87,6 +85,9 @@ namespace Rcpp{
8785
evalCall->error_occurred = false;
8886
evalCall->result = res;
8987
}
88+
89+
reset_current_error() ;
90+
9091
}
9192

9293
inline SEXP Rcpp_eval(SEXP expr_, SEXP env) {

inst/unitTests/cpp/Function.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,7 @@ Function function_namespace_env(){
7676
Function fun = ns[".asSparse"] ; // accesses a non-exported function
7777
return fun;
7878
}
79+
80+
// [[Rcpp::export]]
81+
void exec(Function f) { f(); }
82+

inst/unitTests/runit.Function.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ if (.runThisTest) {
8484
checkException(function_cons_ns("sourceCpp", "Rcppp"), msg = "namespace-lookup constructor: fail when ns does not exist")
8585
checkException(function_cons_ns("sourceCppp", "Rcpp"), msg = "namespace-lookup constructor: fail when function not found")
8686
}
87+
88+
test.Function.eval <- function() {
89+
checkException(exec(stop))
90+
# should not throw exception
91+
exec(function() try(silent = TRUE, exec(stop)))
92+
}
8793

8894
# also check function is found in parent env
8995

0 commit comments

Comments
 (0)