Skip to content
Prev 755 / 10988 Next

[Rcpp-devel] Resolving NativeSymbolInfos from Rcpp

Le 09/06/10 07:14, Romain Francois a ?crit :
After some more coffee, I came up with this:

require( Rcpp )
require( inline )

# borrowed from R private headers
# not part of R API, but does not change all that much
include <- '

typedef union {void *p; DL_FUNC fn;} fn_ptr;

DL_FUNC R_ExternalPtrAddrFn(SEXP s){
     fn_ptr tmp;
     tmp.p =  EXTPTR_PTR(s);
     return tmp.fn;
}

'

code <- '
	// grab loess_raw
	DL_FUNC loess_raw = R_ExternalPtrAddrFn( xp ) ;
	Rprintf( "loess_raw : <%p>\\n", loess_raw ) ;
	
	// call it
	// (*loess_raw)( ... )
	
	return R_NilValue ;
'

fx <- cxxfunction( signature( xp = "externalptr" ),
	code, include = include, plugin = "Rcpp" )
fx( getNativeSymbolInfo( "loess_raw" )$address )


Please expand the part that is actually suppose to call loess_raw and 
let us know if something useful happens.

It might be worth formalize that sort of things in a nice Rcpp 
abstraction. For example, make a Rcpp::DynamicLibrary class with member 
functions to pull these things conveniently.

Romain