[Rcpp-devel] Rcpp::stop crashes RGui and RStudio under Windows
JJ Allaire
jj.allaire at gmail.com
Fri Nov 30 17:48:04 CET 2012
> // [[Rcpp::export]]
> int throwCpp(int nb) {
> BEGIN_RCPP
> if (nb == 10)
> Rcpp::stop("Unexpected condition occurred");
> return nb*2; // Just for testing the normal case }
> END_RCPP
> }
This doesn't quite work for a couple of reasons (one small one larger):
(1) END_RCPP assumes an SEXP return type so you'd actually need to code it
like this:
// [[Rcpp::export]]
SEXP throwCpp(int nb) {
BEGIN_RCPP
if (nb == 10)
Rcpp::stop("Unexpected condition occurred");
return Rcpp::wrap(nb*2);
END_RCPP
}
Or we could introduce a new variation of END_RCPP something like this:
// [[Rcpp::export]]
int throwCpp(int nb) {
BEGIN_RCPP
if (nb == 10)
Rcpp::stop("Unexpected condition occurred");
return nb*2;
END_RCPP_(0)
}
(2) The more serious issue is that locating the END_RCPP inside the
function will result in an Rf_error that does a longjmp over internal Rcpp
code (bypassing C++ destructors in the process). The END_CPP construct
really needs to sit right at the extern "C" boundary to be fully safe.
As Romain said, our aspiration is to make it possible to write C++ code for
R without boilerplate scaffolding. We've got a couple of alternatives under
discussion and I'm sure we'll be able to get this to work one way or
another.
J.J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20121130/11363c86/attachment.html>
More information about the Rcpp-devel
mailing list