Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protect the temporary SEXPs produced by wrap #784

Merged
merged 3 commits into from Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions ChangeLog
@@ -1,3 +1,12 @@
2017-12-04 Kevin Ushey <kevinushey@gmail.com>

* inst/include/Rcpp/RObject.h: Protect temporary wrapped SEXPs
* inst/include/Rcpp/api/meat/DataFrame.h: Idem
* inst/include/Rcpp/api/meat/Environment.h: Idem
* inst/include/Rcpp/api/meat/proxy.h: Idem
* inst/include/Rcpp/proxy/ProtectedProxy.h: Idem
* inst/include/Rcpp/vector/generic_proxy.h: Idem

2017-12-03 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): New minor version
Expand Down
4 changes: 4 additions & 0 deletions inst/include/Rcpp/Environment.h
Expand Up @@ -215,6 +215,10 @@ namespace Rcpp{
return true ;
}

bool assign(const std::string& name, const Shield<SEXP>& x) const {
return assign(name, (SEXP) x);
}

/**
* wrap and assign. If there is a wrap method taking an object
* of WRAPPABLE type, then it is wrapped and the corresponding SEXP
Expand Down
2 changes: 1 addition & 1 deletion inst/include/Rcpp/RObject.h
Expand Up @@ -48,7 +48,7 @@ namespace Rcpp{
*/
template <typename T>
RObject_Impl& operator=(const T& other) {
Storage::set__( wrap(other) ) ;
Storage::set__(Shield<SEXP>(wrap(other)));
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion inst/include/Rcpp/api/meat/DataFrame.h
Expand Up @@ -23,7 +23,7 @@ namespace Rcpp{
template <template <class> class StoragePolicy>
template <class T>
DataFrame_Impl<StoragePolicy>::DataFrame_Impl( const T& obj){
set__( wrap(obj) ) ;
set__(Shield<SEXP>(wrap(obj)));
}

}
Expand Down
2 changes: 1 addition & 1 deletion inst/include/Rcpp/api/meat/Environment.h
Expand Up @@ -27,7 +27,7 @@ namespace Rcpp{
template <template <class> class StoragePolicy>
template <typename WRAPPABLE>
bool Environment_Impl<StoragePolicy>::assign( const std::string& name, const WRAPPABLE& x) const {
return assign( name, wrap( x ) ) ;
return assign(name, Shield<SEXP>(wrap(x)));
}

template <template <class> class StoragePolicy>
Expand Down
18 changes: 8 additions & 10 deletions inst/include/Rcpp/api/meat/proxy.h
Expand Up @@ -30,7 +30,7 @@ template <typename CLASS>
template <typename T>
typename AttributeProxyPolicy<CLASS>::AttributeProxy&
AttributeProxyPolicy<CLASS>::AttributeProxy::operator=(const T& rhs) {
set( wrap(rhs) );
set(Shield<SEXP>(wrap(rhs)));
return *this;
}

Expand Down Expand Up @@ -61,7 +61,7 @@ template <typename CLASS>
template <typename T>
typename NamesProxyPolicy<CLASS>::NamesProxy&
NamesProxyPolicy<CLASS>::NamesProxy::operator=(const T& rhs) {
set( wrap(rhs) );
set(Shield<SEXP>(wrap(rhs)));
return *this;
}

Expand All @@ -82,7 +82,7 @@ template <typename CLASS>
template <typename T>
typename SlotProxyPolicy<CLASS>::SlotProxy&
SlotProxyPolicy<CLASS>::SlotProxy::operator=(const T& rhs) {
set(wrap(rhs));
set(Shield<SEXP>(wrap(rhs)));
return *this;
}

Expand All @@ -97,7 +97,7 @@ template <typename CLASS>
template <typename T>
typename TagProxyPolicy<CLASS>::TagProxy&
TagProxyPolicy<CLASS>::TagProxy::operator=(const T& rhs) {
set( wrap(rhs) );
set(Shield<SEXP>(wrap(rhs)));
return *this;
}

Expand Down Expand Up @@ -128,7 +128,7 @@ template <typename CLASS>
template <typename T>
typename BindingPolicy<CLASS>::Binding&
BindingPolicy<CLASS>::Binding::operator=(const T& rhs) {
set(wrap(rhs));
set(Shield<SEXP>(wrap(rhs)));
return *this;
}

Expand All @@ -149,15 +149,15 @@ template <typename CLASS>
template <typename T>
typename DottedPairProxyPolicy<CLASS>::DottedPairProxy&
DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator=(const T& rhs) {
set(wrap(rhs));
set(Shield<SEXP>(wrap(rhs)));
return *this;
}

template <typename CLASS>
template <typename T>
typename DottedPairProxyPolicy<CLASS>::DottedPairProxy&
DottedPairProxyPolicy<CLASS>::DottedPairProxy::operator=(const traits::named_object<T>& rhs) {
return set(wrap(rhs.object), rhs.name);
return set(Shield<SEXP>(wrap(rhs.object)), rhs.name);
}

template <typename CLASS>
Expand All @@ -184,9 +184,7 @@ template <typename CLASS>
template <typename T>
typename FieldProxyPolicy<CLASS>::FieldProxy&
FieldProxyPolicy<CLASS>::FieldProxy::operator=(const T& rhs) {
SEXP tmp = PROTECT(wrap(rhs));
set(tmp);
UNPROTECT(1);
set(Shield<SEXP>(wrap(rhs)));
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion inst/include/Rcpp/proxy/ProtectedProxy.h
Expand Up @@ -32,7 +32,7 @@ namespace Rcpp{

template <typename U>
ProtectedProxy& operator=( const U& u) {
set( wrap( u ) );
set(Shield<SEXP>(wrap(u)));
return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion inst/include/Rcpp/vector/generic_proxy.h
Expand Up @@ -47,7 +47,7 @@ namespace internal{

template <typename T>
generic_proxy& operator=( const T& rhs){
set(wrap(rhs)) ;
set(Shield<SEXP>(wrap(rhs))) ;
return *this;
}

Expand Down
4 changes: 2 additions & 2 deletions inst/include/Rcpp/vector/proxy.h
Expand Up @@ -151,7 +151,7 @@ namespace internal{

template <typename T>
generic_name_proxy& operator=( const T& rhs ){
set( ::Rcpp::wrap(rhs) ) ;
set(Shield<SEXP>(wrap(rhs)));
return *this ;
}

Expand Down Expand Up @@ -249,7 +249,7 @@ namespace traits {
template<> struct r_vector_iterator<VECSXP> : proxy_based_iterator<VECSXP>{} ;
template<> struct r_vector_iterator<EXPRSXP> : proxy_based_iterator<EXPRSXP>{} ;
template<> struct r_vector_iterator<STRSXP> : proxy_based_iterator<STRSXP>{} ;

template <int RTYPE> struct proxy_based_const_iterator{
typedef ::Rcpp::internal::Proxy_Iterator< typename r_vector_const_proxy<RTYPE>::type > type ;
} ;
Expand Down