[Rcpp-devel] RCPP_USE_UNWIND_PROTECT by default

Iñaki Ucar iucar at fedoraproject.org
Mon Jan 31 22:41:49 CET 2022


Hi Lionel,

I've been setting this for years in my own packages, and particularly
in a simulator that greatly benefits from this due to its heavy usage
of R calls from the C++ simulation loop. Now, we're looking into
setting this feature on by default in the next release of Rcpp to
improve the performance of other packages, such as httpuv [1], as
well.

Dirk has run a full revdep check that looks very promising, with just
one new failure (the V8 package), and it would be great if you could
take a look when you have time. It seems that the UNWIND_PROTECT
mechanism somehow collides with v8's exception handling:

> test_check("V8")
  terminate called after throwing an instance of 'Rcpp::LongjumpException'
  Aborted

V8 sees this exception, doesn't know what to do with it, and then the
program is aborted. This is kind of a Russian Doll, and probably an
extreme case, but we are wondering whether we can do something on the
Rcpp side to support v8's engine. V8 can always undefine
UNWIND_PROTECT if we ship this by default, but this is clearly one of
those packages that could benefit from the improved performance that
this feature enables.

So far, I found that Rcpp::LongjumpException is the only exception in
Rcpp that doesn't inherit from std::exception (which is what V8
expects). Is this intended/required? I checked that, if
LongjumpException inherits from std::exception, V8 doesn't crash there
(the exception is recognized), but then two errors are shown in the R
console, which is not ideal either:

> ctx <- V8::v8()
> ctx$eval("console.r.eval('doesnotexists')")
Error in eval(ei, envir) : object 'doesnotexists' not found
Error: std::exception
> x <- try(ctx$eval("console.r.eval('doesnotexists')"))
Error : std::exception
> x
[1] "Error : std::exception\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<std::runtime_error: std::exception>

Please let us know if you have some time for this. Any help would be
appreciated.

Cheers,
Iñaki

[1] https://github.com/rstudio/httpuv/issues/244

-- 
Iñaki Úcar


More information about the Rcpp-devel mailing list