From 3d60c31d822ae402b9d77d7c7e0107499b1dbd28 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Wed, 13 Mar 2019 16:11:16 +0100 Subject: [PATCH 1/2] Calls to UNPROTECT() to quiet rchk --- inst/include/Rcpp/macros/macros.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/inst/include/Rcpp/macros/macros.h b/inst/include/Rcpp/macros/macros.h index edc50b2e8..7cb05f289 100644 --- a/inst/include/Rcpp/macros/macros.h +++ b/inst/include/Rcpp/macros/macros.h @@ -29,9 +29,11 @@ #ifndef BEGIN_RCPP #define BEGIN_RCPP \ int rcpp_output_type = 0 ; \ + int nprot = 0; \ (void)rcpp_output_type; \ SEXP rcpp_output_condition = R_NilValue ; \ (void)rcpp_output_condition; \ + static SEXP stop_sym = Rf_install("stop"); \ try { #endif @@ -48,26 +50,30 @@ catch(Rcpp::exception& __ex__) { \ rcpp_output_type = 2 ; \ rcpp_output_condition = PROTECT(rcpp_exception_to_r_condition(__ex__)) ; \ + nprot++; \ } \ catch( std::exception& __ex__ ){ \ rcpp_output_type = 2 ; \ rcpp_output_condition = PROTECT(exception_to_r_condition(__ex__)) ; \ + nprot++; \ } \ catch( ... ){ \ rcpp_output_type = 2 ; \ rcpp_output_condition = PROTECT(string_to_try_error("c++ exception (unknown reason)")) ; \ + nprot++; \ } \ if( rcpp_output_type == 1 ){ \ Rf_onintr() ; \ } \ if( rcpp_output_type == 2 ){ \ - SEXP stop_sym = Rf_install( "stop" ) ; \ SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; \ - Rf_eval( expr, R_GlobalEnv ) ; \ + nprot++; \ + Rf_eval( expr, R_BaseEnv ) ; \ } \ if (rcpp_output_type == 3) { \ Rcpp::internal::resumeJump(rcpp_output_condition); \ - } + } \ + UNPROTECT(nprot); #endif #ifndef END_RCPP From d76ff05567982dead07007a7adbc8ec47525efe0 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Wed, 13 Mar 2019 16:29:10 +0100 Subject: [PATCH 2/2] ++nprot is more idiomatic --- inst/include/Rcpp/macros/macros.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/include/Rcpp/macros/macros.h b/inst/include/Rcpp/macros/macros.h index 7cb05f289..76fd5be54 100644 --- a/inst/include/Rcpp/macros/macros.h +++ b/inst/include/Rcpp/macros/macros.h @@ -50,24 +50,24 @@ catch(Rcpp::exception& __ex__) { \ rcpp_output_type = 2 ; \ rcpp_output_condition = PROTECT(rcpp_exception_to_r_condition(__ex__)) ; \ - nprot++; \ + ++nprot; \ } \ catch( std::exception& __ex__ ){ \ rcpp_output_type = 2 ; \ rcpp_output_condition = PROTECT(exception_to_r_condition(__ex__)) ; \ - nprot++; \ + ++nprot; \ } \ catch( ... ){ \ rcpp_output_type = 2 ; \ rcpp_output_condition = PROTECT(string_to_try_error("c++ exception (unknown reason)")) ; \ - nprot++; \ + ++nprot; \ } \ if( rcpp_output_type == 1 ){ \ Rf_onintr() ; \ } \ if( rcpp_output_type == 2 ){ \ SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; \ - nprot++; \ + ++nprot; \ Rf_eval( expr, R_BaseEnv ) ; \ } \ if (rcpp_output_type == 3) { \