-
-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
Description
It seems that Shelter
may call UNPROTECT
with higher n
than the number of PROTECT
calls it issued because it increments the nprotected
member even for NILSXP
s, which are however ignored in Rcpp_protect
. This does not cause a crash on GNU-R for some reason, but if there are some preexisting SEXP
s on the protection stack, it may pop them out unintentionally.
Suggested patch:
--- a/inst/include/Rcpp/protection/Shelter.h
+++ b/inst/include/Rcpp/protection/Shelter.h
@@ -26,7 +26,7 @@ namespace Rcpp {
Shelter() : nprotected(0){}
inline SEXP operator()(SEXP x){
- nprotected++;
+ if ( x != R_NilValue ) nprotected++;
return Rcpp_protect(x) ;
}
the same measure is already taken in Shield
:
Shield( SEXP t_) : t(Rcpp_protect(t_)){}
~Shield(){
if( t != R_NilValue ) Rcpp_unprotect(1) ;
}
Some code snippets that trigger this issue were reported to FastR, but as noted above, they do not cause any observable issues on GNU-R
NRBPerdijk
Metadata
Metadata
Assignees
Labels
No labels