Skip to content

Commit f76c473

Browse files
refine use of Shield
1 parent 048ee1e commit f76c473

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

inst/include/Rcpp/lang.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#define Rcpp_list1 Rf_list1
2626
#define Rcpp_lang1 Rf_lang1
2727

28-
inline SEXP Rcpp_lcons(SEXP car_, SEXP cdr){
28+
namespace Rcpp {
29+
30+
inline SEXP Rcpp_lcons(SEXP car, SEXP cdr){
2931
Shield<SEXP> out( Rf_lcons( car, cdr ) );
3032
return out ;
3133
}
@@ -362,8 +364,7 @@ inline SEXP Rcpp_lang20( SEXP x0, SEXP x1, SEXP x2, SEXP x3, SEXP x4, SEXP x5, S
362364
return out;
363365
}
364366

365-
366-
367+
}
367368

368369
#endif
369370

inst/include/Rcpp/protection/Shield.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ namespace Rcpp {
3131
template <typename U>
3232
inline operator U() const ;
3333

34+
inline operator SEXP() const {
35+
return t ;
36+
}
37+
3438
private:
3539
// not defined on purpose
3640
Shield( const Shield& ) ;

src/barrier.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "internal.h"
2828
#include <Rcpp/cache.h>
2929
#include <algorithm>
30+
#include <Rcpp/protection/Shield.h>
31+
3032

3133
SEXP get_string_elt(SEXP x, int i){
3234
return STRING_ELT(x, i ) ;
@@ -77,7 +79,7 @@ SEXP get_rcpp_cache() {
7779
if( ! Rcpp_cache_know ){
7880

7981
SEXP getNamespaceSym = Rf_install("getNamespace"); // cannot be gc()'ed once in symbol table
80-
Shield<SEXP> RCPP( Rf_eval(Rf_lang2( getNamespaceSym, Rf_mkString("Rcpp") ), R_GlobalEnv) ) ;
82+
Rcpp::Shield<SEXP> RCPP( Rf_eval(Rf_lang2( getNamespaceSym, Rf_mkString("Rcpp") ), R_GlobalEnv) ) ;
8183

8284
Rcpp_cache = Rf_findVarInFrame( RCPP, Rf_install(".rcpp_cache") ) ;
8385
Rcpp_cache_know = true ;
@@ -117,8 +119,8 @@ SEXP set_current_error(SEXP cache, SEXP e){
117119

118120
SEXP init_Rcpp_cache(){
119121
SEXP getNamespaceSym = Rf_install("getNamespace"); // cannot be gc()'ed once in symbol table
120-
Shield<SEXP> RCPP( Rf_eval(Rf_lang2( getNamespaceSym, Rf_mkString("Rcpp") ), R_GlobalEnv) ) ;
121-
Shield<SEXP> cache( Rf_allocVector( VECSXP, RCPP_CACHE_SIZE ) );
122+
Rcpp::Shield<SEXP> RCPP( Rf_eval(Rf_lang2( getNamespaceSym, Rf_mkString("Rcpp") ), R_GlobalEnv) ) ;
123+
Rcpp::Shield<SEXP> cache( Rf_allocVector( VECSXP, RCPP_CACHE_SIZE ) );
122124

123125
// the Rcpp namespace
124126
SET_VECTOR_ELT( cache, 0, RCPP ) ;
@@ -172,7 +174,7 @@ int* get_cache( int m){
172174
SEXP hash_cache = VECTOR_ELT( cache, RCPP_HASH_CACHE_INDEX) ;
173175
int n = Rf_length(hash_cache) ;
174176
if( m > n ){
175-
Shield<SEXP> new_hash_cache( Rf_allocVector( INTSXP, m) ) ;
177+
Rcpp::Shield<SEXP> new_hash_cache( Rf_allocVector( INTSXP, m) ) ;
176178
hash_cache = new_hash_cache ;
177179
SET_VECTOR_ELT(cache,RCPP_HASH_CACHE_INDEX, hash_cache);
178180
}

0 commit comments

Comments
 (0)