[Rd] using C++ finalizers for external pointers

From: Romain Francois <romain.francois_at_dbmail.com>
Date: Wed, 16 Jun 2010 12:27:59 +0200

Hello,

In Rcpp, we use a C++ template to finalizers for external pointers:

template <typename T>
void delete_finalizer(SEXP p){

     if( TYPEOF(p) == EXTPTRSXP ){
	T* ptr = (T*) EXTPTR_PTR(p) ;
	delete ptr ;
     }

}

This works fine. Or at least it has appeared to work fine for some time.

However, when compiled with suncc, this generates warnings [1] because the generated function is of C++ linkage and the finalizer type is declared to have C linkage in Rinternals.h

extern "C" {

  	...
	typedef void (*R_CFinalizer_t)(SEXP);
	void R_RegisterFinalizer(SEXP s, SEXP fun);
	void R_RegisterCFinalizer(SEXP s, R_CFinalizer_t fun);
	void R_RegisterFinalizerEx(SEXP s, SEXP fun, Rboolean onexit);
	void R_RegisterCFinalizerEx(SEXP s, R_CFinalizer_t fun, Rboolean onexit);
	...

}

Does anyone know a workaround ?

Would using an R finalizer (with R_RegisterFinalizer) using another external pointer to some class be appropriate ?

Romain

[1] : http://article.gmane.org/gmane.comp.lang.r.rcpp/433

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/98Uf7u : Rcpp 0.8.1
|- http://bit.ly/c6YnCi : graph gallery collage
`- http://bit.ly/bZ7ltC : inline 0.3.5

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 16 Jun 2010 - 10:33:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jun 2010 - 14:11:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive