[Rcpp-devel] Missing PROTECT()s in forward_exception_to_r()?

Dirk Eddelbuettel edd at debian.org
Tue Oct 9 13:46:05 CEST 2012

On 9 October 2012 at 08:35, North, Ben wrote:
| Hi Dirk, Douglas,
| Many thanks for your time in digging into this.  I did some further
| experiments yesterday and cut down the PROTECT()s a bit, but your
| version below is much tidier.  I confirm that your suggested code
|         SEXP cppExceptExpr = PROTECT(Rf_lang3(cppExceptSym,
|                                               Rf_mkString(exception_what.c_str()),
|                                               Rf_mkString(exception_class.c_str())));
|         Rf_eval(cppExceptExpr, R_FindNamespace(Rf_mkString("Rcpp"))); // Should not return.
|         // Do this in case somehow someone replaces the definition of
|         // "cpp_exception" such that it does return:
|         UNPROTECT(1);
| behaves correctly in my case.  For completeness, the full text of the
| forward_exception_to_r() function I now have is:

Thanks for reporting back, and confirming that it works. This is a useful

For completeness, the current version of exceptions.cpp is here

| I am now seeing another strange error under gctorture() which I might try
| to track down further, and will report back if it looks like Rcpp rather
| than my code.

Thanks for doing that. It is quite possible that other cases like this are
hiding where an explicit PROTECT may be called for.  We don't use gctorture()
much as it slows things down.  Maybe we should use it more...


Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com  

More information about the Rcpp-devel mailing list