File tree Expand file tree Collapse file tree 5 files changed +21
-7
lines changed Expand file tree Collapse file tree 5 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ inline SEXP Rcpp_fast_eval(SEXP expr, SEXP env) {
75
75
inline SEXP Rcpp_eval (SEXP expr, SEXP env) {
76
76
77
77
// 'identity' function used to capture errors, interrupts
78
- SEXP identity = Rf_findFun (::Rf_install (" identity" ), R_BaseNamespace);
78
+ Shield< SEXP> identity ( Rf_findFun (::Rf_install (" identity" ), R_BaseNamespace) );
79
79
80
80
if (identity == R_UnboundValue) {
81
81
stop (" Failed to find 'base::identity()'" );
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ namespace internal {
243
243
inline bool is_Rcpp_eval_call (SEXP expr) {
244
244
SEXP sys_calls_symbol = Rf_install (" sys.calls" );
245
245
SEXP identity_symbol = Rf_install (" identity" );
246
- SEXP identity_fun = Rf_findFun (identity_symbol, R_BaseEnv);
246
+ Shield< SEXP> identity_fun ( Rf_findFun (identity_symbol, R_BaseEnv) );
247
247
SEXP tryCatch_symbol = Rf_install (" tryCatch" );
248
248
SEXP evalq_symbol = Rf_install (" evalq" );
249
249
Original file line number Diff line number Diff line change @@ -27,11 +27,11 @@ namespace Rcpp {
27
27
28
28
inline SEXP operator ()(SEXP x){
29
29
nprotected++;
30
- return PROTECT (x) ;
30
+ return Rcpp_protect (x) ;
31
31
}
32
32
33
33
~Shelter (){
34
- UNPROTECT (nprotected) ;
34
+ Rcpp_unprotect (nprotected) ;
35
35
nprotected = 0 ;
36
36
}
37
37
Original file line number Diff line number Diff line change @@ -25,12 +25,18 @@ namespace Rcpp{
25
25
return x ;
26
26
}
27
27
28
+ inline void Rcpp_unprotect (int i){
29
+ // Prefer this function over UNPROTECT() in Rcpp so that all
30
+ // balance checks errors by rchk are contained at one location (#892)
31
+ UNPROTECT (i);
32
+ }
33
+
28
34
template <typename T>
29
35
class Shield {
30
36
public:
31
37
Shield ( SEXP t_) : t(Rcpp_protect(t_)){}
32
38
~Shield (){
33
- if ( t != R_NilValue ) UNPROTECT (1 ) ;
39
+ if ( t != R_NilValue ) Rcpp_unprotect (1 ) ;
34
40
}
35
41
36
42
operator SEXP () const { return t; }
Original file line number Diff line number Diff line change @@ -37,7 +37,11 @@ class no_init_vector {
37
37
38
38
template <int RTYPE, template <class > class StoragePolicy >
39
39
operator Vector<RTYPE, StoragePolicy>() const {
40
- return Rf_allocVector (RTYPE, size) ;
40
+ // Explicitly protect temporary vector to avoid false positive
41
+ // with rchk (#892)
42
+ Shield<SEXP> x (Rf_allocVector (RTYPE, size));
43
+ Vector<RTYPE, PreserveStorage> ret (x);
44
+ return ret;
41
45
}
42
46
43
47
private:
@@ -58,7 +62,11 @@ class no_init_matrix {
58
62
59
63
template <int RTYPE, template <class > class StoragePolicy >
60
64
operator Matrix<RTYPE, StoragePolicy>() const {
61
- return Rf_allocMatrix (RTYPE, nr, nc);
65
+ // Explicitly protect temporary matrix to avoid false positive
66
+ // with rchk (#892)
67
+ Shield<SEXP> x (Rf_allocMatrix (RTYPE, nr, nc));
68
+ Matrix<RTYPE, PreserveStorage> ret (x);
69
+ return ret;
62
70
}
63
71
64
72
private:
You can’t perform that action at this time.
0 commit comments