[Rcpp-commits] r2889 - in pkg/Rcpp: . inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Feb 1 08:27:16 CET 2011
Author: romain
Date: 2011-02-01 08:27:13 +0100 (Tue, 01 Feb 2011)
New Revision: 2889
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
extra protection in push_back_impl
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2011-01-30 17:31:14 UTC (rev 2888)
+++ pkg/Rcpp/ChangeLog 2011-02-01 07:27:13 UTC (rev 2889)
@@ -1,3 +1,7 @@
+2011-02-01 Romain Francois <romain at r-enthusiasts.com>
+
+ * inst/include/Rcpp/vector/Vector.h: extra PROTECT'ion in push_back__impl
+
2011-01-25 Dirk Eddelbuettel <edd at debian.org>
* inst/include/Rcpp/DataFrame_generated.h: Assign Rf_install() result
Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h 2011-01-30 17:31:14 UTC (rev 2888)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h 2011-02-01 07:27:13 UTC (rev 2889)
@@ -437,7 +437,9 @@
template <typename T>
void push_back( const T& object){
- push_back__impl( converter_type::get(object) ) ;
+ push_back__impl( converter_type::get(object),
+ typename traits::same_type<stored_type,SEXP>()
+ ) ;
}
template <typename T>
@@ -532,31 +534,8 @@
}
private:
- void push_back__impl(const stored_type& object){
- int n = size() ;
- Vector target( n + 1 ) ;
- SEXP names = RCPP_GET_NAMES(RObject::m_sexp) ;
- iterator target_it( target.begin() ) ;
- iterator it(begin()) ;
- iterator this_end(end());
- if( names == R_NilValue ){
- for( ; it < this_end; ++it, ++target_it ){
- *target_it = *it ;
- }
- } else {
- SEXP newnames = PROTECT( ::Rf_allocVector( STRSXP, n + 1) ) ;
- int i = 0 ;
- for( ; it < this_end; ++it, ++target_it, i++ ){
- *target_it = *it ;
- SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
- }
- SET_STRING_ELT( newnames, i, Rf_mkChar("") ) ;
- target.attr("names") = newnames ;
- UNPROTECT(1) ; /* newnames */
- }
- *target_it = object;
- set_sexp( target.asSexp() ) ;
- }
+ void push_back__impl(const stored_type& object, traits::true_type ) ;
+ void push_back__impl(const stored_type& object, traits::false_type ) ;
void push_back_name__impl(const stored_type& object, const std::string& name ){
int n = size() ;
@@ -836,5 +815,60 @@
} ; /* Vector */
+ template <int RTYPE>
+ void Vector<RTYPE>::push_back__impl(const stored_type& object, traits::false_type){
+ int n = size() ;
+ Vector target( n + 1 ) ;
+ SEXP names = RCPP_GET_NAMES(RObject::m_sexp) ;
+ iterator target_it( target.begin() ) ;
+ iterator it(begin()) ;
+ iterator this_end(end());
+ if( names == R_NilValue ){
+ for( ; it < this_end; ++it, ++target_it ){
+ *target_it = *it ;
+ }
+ } else {
+ SEXP newnames = PROTECT( ::Rf_allocVector( STRSXP, n + 1) ) ;
+ int i = 0 ;
+ for( ; it < this_end; ++it, ++target_it, i++ ){
+ *target_it = *it ;
+ SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
+ }
+ SET_STRING_ELT( newnames, i, Rf_mkChar("") ) ;
+ target.attr("names") = newnames ;
+ UNPROTECT(1) ; /* newnames */
+ }
+ *target_it = object;
+ set_sexp( target.asSexp() ) ;
+ }
+ template <int RTYPE>
+ void Vector<RTYPE>::push_back__impl(const stored_type& object, traits::true_type){
+ SEXP object_sexp = PROTECT( object ) ;
+ int n = size() ;
+ Vector target( n + 1 ) ;
+ SEXP names = RCPP_GET_NAMES(RObject::m_sexp) ;
+ iterator target_it( target.begin() ) ;
+ iterator it(begin()) ;
+ iterator this_end(end());
+ if( names == R_NilValue ){
+ for( ; it < this_end; ++it, ++target_it ){
+ *target_it = *it ;
+ }
+ } else {
+ SEXP newnames = PROTECT( ::Rf_allocVector( STRSXP, n + 1) ) ;
+ int i = 0 ;
+ for( ; it < this_end; ++it, ++target_it, i++ ){
+ *target_it = *it ;
+ SET_STRING_ELT( newnames, i, STRING_ELT(names, i ) ) ;
+ }
+ SET_STRING_ELT( newnames, i, Rf_mkChar("") ) ;
+ target.attr("names") = newnames ;
+ UNPROTECT(1) ; /* newnames */
+ }
+ *target_it = object_sexp;
+ set_sexp( target.asSexp() ) ;
+ UNPROTECT(1) ;
+ }
+
#endif
More information about the Rcpp-commits
mailing list