[Rcpp-devel] Extract a function from a list and create a call

Dirk Eddelbuettel edd at debian.org
Mon Mar 22 14:30:30 CET 2010


On 22 March 2010 at 08:14, Douglas Bates wrote:
| > And when I run the code on OSX (gcc 4.2), I get :
| >
| >  *** caught segfault ***
| > address 0x0, cause 'memory not mapped'
| >
| > Traceback:
| >  1: .Call("file10d63af1", PACKAGE = f, l)
| >  2: fx(binomial())
| > aborting ...
| > Segmentation fault
| >
| > which is not good either.
| 
| It's likely the segfault occurs when trying to create the std::string
| from fpt.  A simpler test is
| 
| suppressWarnings(require(inline))
| suppressWarnings(require(Rcpp))
| 
| fx<- cfunction( signature( l = "list" ), '
|     List ll(l);
|     CharacterVector fam = ll["family"];
|     Rprintf("Assigned fam of length %d\\n", fam.size());
|     if (!fam.size()) return R_NilValue;
|     char *fpt = fam[0];
|     Rprintf("(char*)fam[0] points to \\"%s\\"\\n", fpt);
|     std::string fstr(fpt);
|     Rprintf("std::string fstr points to \\"%s\\"\\n", fstr.c_str());
|     return R_NilValue;
| ', Rcpp = TRUE, includes = "using namespace Rcpp;" )
| 
| fx(binomial())
| 
| I think the problem under Linux is extracting fam[0].  The error

Agreed. I tried a few quick variants as well last night without success.
However, no segfaults on my end.

Dirk

-- 
  Registration is open for the 2nd International conference R / Finance 2010
  See http://www.RinFinance.com for details, and see you in Chicago in April!


More information about the Rcpp-devel mailing list