[Rd] using C++ finalizers for external pointers

Romain Francois romain.francois at dbmail.com
Wed Jun 16 12:27:59 CEST 2010


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 ?


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

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

More information about the R-devel mailing list