[Rcpp-devel] Segfaults

Darren Cook darren at dcook.org
Thu Jan 5 08:05:45 CET 2012


Steve Lianoglou wrote:
> When I use inline for anything semi-permanent (the last step before
> turning it into a package, let's say), I typically have a thin R
> wrapper function that calls down to my inline function and I never
> call the inline function directly anywhere else. The job of the thin R
> wrapper function is to sanity check and/or coerce the vars to the
> correct type before they are past to the inline'd function to avoid
> the segfault.
(I've pasted in below an example, from you, from another thread to show
what you mean.)

Why do you do this in R, instead of in the C++ function?
(The advantage of doing it in the C++ function is that there is no way
to accidentally skip the validation.)

Darren


my_f <- function(x) {
  if (!(is.integer(x) && length(x) == 1L)) stop("Illegal value for `x`)
  f(x_=x)
}

f <- cxxfunction(signature(x_="integer"), plugin = "Rcpp", '
  int x = as<int>(x_);
  // ...
')


More information about the Rcpp-devel mailing list