Skip to content

Commit c3b26f6

Browse files
authored
Merge pull request #784 from RcppCore/bugfix/proxy-sexp-protection
protect the temporary SEXPs produced by wrap
2 parents 2645fce + 8670bb6 commit c3b26f6

File tree

9 files changed

+28
-17
lines changed

9 files changed

+28
-17
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2017-12-04 Kevin Ushey <[email protected]>
2+
3+
* inst/include/Rcpp/RObject.h: Protect temporary wrapped SEXPs
4+
* inst/include/Rcpp/api/meat/DataFrame.h: Idem
5+
* inst/include/Rcpp/api/meat/Environment.h: Idem
6+
* inst/include/Rcpp/api/meat/proxy.h: Idem
7+
* inst/include/Rcpp/proxy/ProtectedProxy.h: Idem
8+
* inst/include/Rcpp/vector/generic_proxy.h: Idem
9+
110
2017-12-03 Dirk Eddelbuettel <[email protected]>
211

312
* DESCRIPTION (Version, Date): New minor version

inst/include/Rcpp/Environment.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ namespace Rcpp{
215215
return true ;
216216
}
217217

218+
bool assign(const std::string& name, const Shield<SEXP>& x) const {
219+
return assign(name, (SEXP) x);
220+
}
221+
218222
/**
219223
* wrap and assign. If there is a wrap method taking an object
220224
* of WRAPPABLE type, then it is wrapped and the corresponding SEXP

inst/include/Rcpp/RObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace Rcpp{
4848
*/
4949
template <typename T>
5050
RObject_Impl& operator=(const T& other) {
51-
Storage::set__( wrap(other) ) ;
51+
Storage::set__(Shield<SEXP>(wrap(other)));
5252
return *this;
5353
}
5454

inst/include/Rcpp/api/meat/DataFrame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Rcpp{
2323
template <template <class> class StoragePolicy>
2424
template <class T>
2525
DataFrame_Impl<StoragePolicy>::DataFrame_Impl( const T& obj){
26-
set__( wrap(obj) ) ;
26+
set__(Shield<SEXP>(wrap(obj)));
2727
}
2828

2929
}

inst/include/Rcpp/api/meat/Environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Rcpp{
2727
template <template <class> class StoragePolicy>
2828
template <typename WRAPPABLE>
2929
bool Environment_Impl<StoragePolicy>::assign( const std::string& name, const WRAPPABLE& x) const {
30-
return assign( name, wrap( x ) ) ;
30+
return assign(name, Shield<SEXP>(wrap(x)));
3131
}
3232

3333
template <template <class> class StoragePolicy>

inst/include/Rcpp/api/meat/proxy.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ template <typename CLASS>
3030
template <typename T>
3131
typename AttributeProxyPolicy<CLASS>::AttributeProxy&
3232
AttributeProxyPolicy<CLASS>::AttributeProxy::operator=(const T& rhs) {
33-
set( wrap(rhs) );
33+
set(Shield<SEXP>(wrap(rhs)));
3434
return *this;
3535
}
3636

@@ -61,7 +61,7 @@ template <typename CLASS>
6161
template <typename T>
6262
typename NamesProxyPolicy<CLASS>::NamesProxy&
6363
NamesProxyPolicy<CLASS>::NamesProxy::operator=(const T& rhs) {
64-
set( wrap(rhs) );
64+
set(Shield<SEXP>(wrap(rhs)));
6565
return *this;
6666
}
6767

@@ -82,7 +82,7 @@ template <typename CLASS>
8282
template <typename T>
8383
typename SlotProxyPolicy<CLASS>::SlotProxy&
8484
SlotProxyPolicy<CLASS>::SlotProxy::operator=(const T& rhs) {
85-
set(wrap(rhs));
85+
set(Shield<SEXP>(wrap(rhs)));
8686
return *this;
8787
}
8888

@@ -97,7 +97,7 @@ template <typename CLASS>
9797
template <typename T>
9898
typename TagProxyPolicy<CLASS>::TagProxy&
9999
TagProxyPolicy<CLASS>::TagProxy::operator=(const T& rhs) {
100-
set( wrap(rhs) );
100+
set(Shield<SEXP>(wrap(rhs)));
101101
return *this;
102102
}
103103

@@ -128,7 +128,7 @@ template <typename CLASS>
128128
template <typename T>
129129
typename BindingPolicy<CLASS>::Binding&
130130
BindingPolicy<CLASS>::Binding::operator=(const T& rhs) {
131-
set(wrap(rhs));
131+
set(Shield<SEXP>(wrap(rhs)));
132132
return *this;
133133
}
134134

@@ -149,15 +149,15 @@ template <typename CLASS>
149149
template <typename T>
150150
typename DottedPairProxyPolicy<CLASS>::DottedPairProxy&
151151
DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator=(const T& rhs) {
152-
set(wrap(rhs));
152+
set(Shield<SEXP>(wrap(rhs)));
153153
return *this;
154154
}
155155

156156
template <typename CLASS>
157157
template <typename T>
158158
typename DottedPairProxyPolicy<CLASS>::DottedPairProxy&
159159
DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator=(const traits::named_object<T>& rhs) {
160-
return set(wrap(rhs.object), rhs.name);
160+
return set(Shield<SEXP>(wrap(rhs.object)), rhs.name);
161161
}
162162

163163
template <typename CLASS>
@@ -184,9 +184,7 @@ template <typename CLASS>
184184
template <typename T>
185185
typename FieldProxyPolicy<CLASS>::FieldProxy&
186186
FieldProxyPolicy<CLASS>::FieldProxy::operator=(const T& rhs) {
187-
SEXP tmp = PROTECT(wrap(rhs));
188-
set(tmp);
189-
UNPROTECT(1);
187+
set(Shield<SEXP>(wrap(rhs)));
190188
return *this;
191189
}
192190

inst/include/Rcpp/proxy/ProtectedProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Rcpp{
3232

3333
template <typename U>
3434
ProtectedProxy& operator=( const U& u) {
35-
set( wrap( u ) );
35+
set(Shield<SEXP>(wrap(u)));
3636
return *this;
3737
}
3838

inst/include/Rcpp/vector/generic_proxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace internal{
4747

4848
template <typename T>
4949
generic_proxy& operator=( const T& rhs){
50-
set(wrap(rhs)) ;
50+
set(Shield<SEXP>(wrap(rhs))) ;
5151
return *this;
5252
}
5353

inst/include/Rcpp/vector/proxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace internal{
151151

152152
template <typename T>
153153
generic_name_proxy& operator=( const T& rhs ){
154-
set( ::Rcpp::wrap(rhs) ) ;
154+
set(Shield<SEXP>(wrap(rhs)));
155155
return *this ;
156156
}
157157

@@ -249,7 +249,7 @@ namespace traits {
249249
template<> struct r_vector_iterator<VECSXP> : proxy_based_iterator<VECSXP>{} ;
250250
template<> struct r_vector_iterator<EXPRSXP> : proxy_based_iterator<EXPRSXP>{} ;
251251
template<> struct r_vector_iterator<STRSXP> : proxy_based_iterator<STRSXP>{} ;
252-
252+
253253
template <int RTYPE> struct proxy_based_const_iterator{
254254
typedef ::Rcpp::internal::Proxy_Iterator< typename r_vector_const_proxy<RTYPE>::type > type ;
255255
} ;

0 commit comments

Comments
 (0)