[Rcpp-commits] r1209 - in pkg/RcppGSL: inst/include src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 12 14:34:01 CEST 2010


Author: romain
Date: 2010-05-12 14:34:01 +0200 (Wed, 12 May 2010)
New Revision: 1209

Modified:
   pkg/RcppGSL/inst/include/RcppGSLForward.h
   pkg/RcppGSL/src/RcppGSL.cpp
Log:
RcppGSL::vector does not clean after itself anymore, but the user does, by calling the free member function

Modified: pkg/RcppGSL/inst/include/RcppGSLForward.h
===================================================================
--- pkg/RcppGSL/inst/include/RcppGSLForward.h	2010-05-12 12:17:27 UTC (rev 1208)
+++ pkg/RcppGSL/inst/include/RcppGSLForward.h	2010-05-12 12:34:01 UTC (rev 1209)
@@ -75,24 +75,28 @@
 	typedef gsl_vector##__SUFFIX__ gsltype ; 	                                   \
 	gsltype* data ;                          	                                   \
 	const static int RTYPE = ::Rcpp::traits::r_sexptype_traits<type>::rtype ;    \
-	vector( SEXP x) throw(::Rcpp::not_compatible) : data(0), owner(true) {       \
+	vector( SEXP x) throw(::Rcpp::not_compatible) : data(0) {                    \
 		SEXP y = ::Rcpp::r_cast<RTYPE>(x) ;                                      \
 		int size = ::Rf_length( y ) ;                                            \
 		data = gsl_vector##__SUFFIX__##_calloc( size ) ;                         \
 		::Rcpp::internal::export_range<__CAST__*>( y,                            \
 			reinterpret_cast<__CAST__*>( data->data ) ) ;                        \
 	}                                                                            \
-	vector( gsltype* x, bool owner_=true) : data(x), owner(owner_) {}            \
-	vector( int size , bool owner_ = true ) :                                    \
-		data( gsl_vector##__SUFFIX__##_calloc( size ) ), owner(owner_){}         \
-	~vector(){ if(owner) gsl_vector##__SUFFIX__##_free(data) ; }                 \
+	vector( gsltype* x) : data(x) {}                                             \
+	vector( int size) :                                                          \
+		data( gsl_vector##__SUFFIX__##_calloc( size ) ){}                        \
+	~vector(){ }                                                                 \
 	operator gsltype*(){ return data ; }                                         \
 	gsltype* operator->() const { return data; }                                 \
 	gsltype& operator*() const { return *data; }                                 \
-private:                                                                         \
-	bool owner ;                                                                 \
-	vector( const vector& x) ;                                                   \
-	vector& operator=(const vector& other) ;                                     \
+	vector( const vector& x) : data(x.data)  {}                                  \
+	vector& operator=(const vector& other) {                                     \
+		data = other.data ;                                                      \
+		return *this ;                                                           \
+	}                                                                            \
+	void free(){                                                                 \
+		gsl_vector##__SUFFIX__##_free(data) ;                                    \
+	}                                                                            \
 } ;                                                                              \
 template <> class vector_view<__T__>  {           	                            \
 public:                                      	                                   \

Modified: pkg/RcppGSL/src/RcppGSL.cpp
===================================================================
--- pkg/RcppGSL/src/RcppGSL.cpp	2010-05-12 12:17:27 UTC (rev 1208)
+++ pkg/RcppGSL/src/RcppGSL.cpp	2010-05-12 12:34:01 UTC (rev 1209)
@@ -34,6 +34,22 @@
 		_["gsl_vector_ushort"] = x_ushort, 
 		_["gsl_vector_ulong"] = x_ulong
 		) ;
+	
+	x_double.free();
+	x_float.free();
+	x_int.free() ; 
+	x_long.free() ; 
+	x_char.free() ; 
+	x_long_double.free() ;
+	x_short.free() ; 
+	x_uchar.free() ;
+	x_uint.free() ; 
+	x_ushort.free() ;
+	x_ulong.free() ;
+	x_complex.free() ; 
+	x_complex_float.free() ;
+	x_complex_long_double.free() ;
+	
 	return res ;
 }
 
@@ -180,13 +196,13 @@
 	return res ;
 }
 
-RCPP_FUNCTION_1( double, test_gsl_vector_input, SEXP x){
-	RcppGSL::vector<double> vec(x) ;
+RCPP_FUNCTION_1( double, test_gsl_vector_input, RcppGSL::vector<double> vec){
 	int n = vec->size ;
 	double res = 0.0 ;
 	for( int i=0; i<n; i++){
 		res += gsl_vector_get( vec, i ) ;
 	}
+	vec.free() ;
 	return res ;
 }
 



More information about the Rcpp-commits mailing list