diff --git a/inst/include/Rcpp/api/meat/proxy.h b/inst/include/Rcpp/api/meat/proxy.h index c00fa1249..e7dffde68 100644 --- a/inst/include/Rcpp/api/meat/proxy.h +++ b/inst/include/Rcpp/api/meat/proxy.h @@ -30,7 +30,7 @@ template template typename AttributeProxyPolicy::AttributeProxy& AttributeProxyPolicy::AttributeProxy::operator=(const T& rhs) { - set(Shield(wrap(rhs))); + set(wrap(rhs)); return *this; } diff --git a/inst/include/Rcpp/clone.h b/inst/include/Rcpp/clone.h index a9a133e1a..f2a1e911f 100644 --- a/inst/include/Rcpp/clone.h +++ b/inst/include/Rcpp/clone.h @@ -31,8 +31,9 @@ namespace Rcpp{ - T has a SEXP constructor */ template T clone(const T& object) { - SEXP x = const_cast(object) ; - return T( Rf_duplicate( x ) ) ; + Shield x(const_cast(object)); + Shield copy(Rf_duplicate(x)); + return T((SEXP)copy); } } // namespace Rcpp diff --git a/inst/include/Rcpp/proxy/AttributeProxy.h b/inst/include/Rcpp/proxy/AttributeProxy.h index 158a0e02e..a84043d72 100644 --- a/inst/include/Rcpp/proxy/AttributeProxy.h +++ b/inst/include/Rcpp/proxy/AttributeProxy.h @@ -49,7 +49,7 @@ class AttributeProxyPolicy { return Rf_getAttrib( parent, attr_name ) ; } void set(SEXP x ){ - Rf_setAttrib( parent, attr_name, x ) ; + Rf_setAttrib( parent, attr_name, Shield(x) ) ; } } ; diff --git a/inst/include/Rcpp/proxy/NamesProxy.h b/inst/include/Rcpp/proxy/NamesProxy.h index 78c68a692..694dda9b3 100644 --- a/inst/include/Rcpp/proxy/NamesProxy.h +++ b/inst/include/Rcpp/proxy/NamesProxy.h @@ -47,14 +47,16 @@ class NamesProxyPolicy{ } void set(SEXP x) { + Shield safe_x(x); + /* check if we can use a fast version */ if( TYPEOF(x) == STRSXP && parent.size() == Rf_length(x) ){ - SEXP y = parent.get__() ; - Rf_setAttrib( y, R_NamesSymbol, x ) ; + Rf_namesgets(parent, x); } else { /* use the slower and more flexible version (callback to R) */ SEXP namesSym = Rf_install( "names<-" ); - Shield new_vec(Rcpp_fast_eval(Rf_lang3(namesSym, parent, x), R_GlobalEnv)); + Shield call(Rf_lang3(namesSym, parent, x)); + Shield new_vec(Rcpp_fast_eval(call, R_GlobalEnv)); parent.set__(new_vec); } diff --git a/inst/include/Rcpp/vector/Matrix.h b/inst/include/Rcpp/vector/Matrix.h index 2eb857fb3..1e141565a 100644 --- a/inst/include/Rcpp/vector/Matrix.h +++ b/inst/include/Rcpp/vector/Matrix.h @@ -50,7 +50,7 @@ class Matrix : public Vector, public MatrixBase( x ) ), nrows( VECTOR::dims()[0] ) {} + Matrix(SEXP x) : VECTOR(x), nrows( VECTOR::dims()[0] ) {} Matrix( const Dimension& dims) : VECTOR( Rf_allocMatrix( RTYPE, dims[0], dims[1] ) ), nrows(dims[0]) { if( dims.size() != 2 ) throw not_a_matrix(); diff --git a/inst/include/Rcpp/vector/Vector.h b/inst/include/Rcpp/vector/Vector.h index e2fe96772..f91b6c651 100644 --- a/inst/include/Rcpp/vector/Vector.h +++ b/inst/include/Rcpp/vector/Vector.h @@ -71,12 +71,14 @@ class Vector : } Vector( SEXP x ) { - Storage::set__( r_cast(x) ) ; + Rcpp::Shield safe(x); + Storage::set__( r_cast(safe) ) ; } template Vector( const GenericProxy& proxy ){ - Storage::set__( r_cast(proxy.get()) ) ; + Rcpp::Shield safe(proxy.get()); + Storage::set__( r_cast(safe) ) ; } explicit Vector( const no_init_vector& obj) { @@ -174,7 +176,8 @@ class Vector : template Vector( const sugar::SingleLogicalResult& obj ) { - Storage::set__( r_cast( const_cast&>(obj).get_sexp() ) ) ; + Rcpp::Shield safe(const_cast&>(obj).get_sexp() ); + Storage::set__( r_cast(safe) ) ; RCPP_DEBUG_2( "Vector<%d>( const sugar::SingleLogicalResult& ) [T = %s]", RTYPE, DEMANGLE(T) ) }