Skip to content

Commit b351798

Browse files
romainfrancoiseddelbuettel
authored andcommitted
Calls to UNPROTECT() to quiet rchk (#949)
* Calls to UNPROTECT() to quiet rchk * ++nprot is more idiomatic
1 parent 7203f32 commit b351798

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

inst/include/Rcpp/macros/macros.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
#ifndef BEGIN_RCPP
3030
#define BEGIN_RCPP \
3131
int rcpp_output_type = 0 ; \
32+
int nprot = 0; \
3233
(void)rcpp_output_type; \
3334
SEXP rcpp_output_condition = R_NilValue ; \
3435
(void)rcpp_output_condition; \
36+
static SEXP stop_sym = Rf_install("stop"); \
3537
try {
3638
#endif
3739

@@ -48,26 +50,30 @@
4850
catch(Rcpp::exception& __ex__) { \
4951
rcpp_output_type = 2 ; \
5052
rcpp_output_condition = PROTECT(rcpp_exception_to_r_condition(__ex__)) ; \
53+
++nprot; \
5154
} \
5255
catch( std::exception& __ex__ ){ \
5356
rcpp_output_type = 2 ; \
5457
rcpp_output_condition = PROTECT(exception_to_r_condition(__ex__)) ; \
58+
++nprot; \
5559
} \
5660
catch( ... ){ \
5761
rcpp_output_type = 2 ; \
5862
rcpp_output_condition = PROTECT(string_to_try_error("c++ exception (unknown reason)")) ; \
63+
++nprot; \
5964
} \
6065
if( rcpp_output_type == 1 ){ \
6166
Rf_onintr() ; \
6267
} \
6368
if( rcpp_output_type == 2 ){ \
64-
SEXP stop_sym = Rf_install( "stop" ) ; \
6569
SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; \
66-
Rf_eval( expr, R_GlobalEnv ) ; \
70+
++nprot; \
71+
Rf_eval( expr, R_BaseEnv ) ; \
6772
} \
6873
if (rcpp_output_type == 3) { \
6974
Rcpp::internal::resumeJump(rcpp_output_condition); \
70-
}
75+
} \
76+
UNPROTECT(nprot);
7177
#endif
7278

7379
#ifndef END_RCPP

0 commit comments

Comments
 (0)