[Rcpp-devel] RCPP_USE_UNWIND_PROTECT by default
Kevin Ushey
kevinushey at gmail.com
Sun Feb 6 18:35:41 CET 2022
And I'm seeing you pointed that out at the end of the README... so yes, we
should probably just have our exception inherit from std::exception.
On Sun, Feb 6, 2022 at 9:31 AM Dirk Eddelbuettel <edd at debian.org> wrote:
>
> On 6 February 2022 at 18:18, Jeroen Ooms wrote:
> | Well not really, this kind of misses my point that it the
> | unwind-protect makes it impossible to meaningfully catch the R error
> | in C++, handle it, and continue running the C++ code, without aborting
> | the entire mission and throwing the user back in the console.
>
> I see. Well if we wanted to catch an R error on the R side, adding tryCatch
> still works. Here are your initial R function, renamed, and a new one:
>
> callbackWithoutTry <- function() {
> stop("Ouch from R")
> }
>
> callback <- function() {
> tryCatch(stop("Ouch from R"),
> error = function(e) { cat("Well that went south\n") },
> finally = function(e) { cat("Normal end\n") } )
> }
>
> This (under UNWIND_PROTECT) behaves:
>
> edd at rob:/tmp/uptest(master)$ install.r .
> * installing *source* package ‘uptest’ ...
> ** using staged installation
> ** libs
> rm -f uptest.so RcppExports.o callback.o
> ccache g++-11 -I"/usr/share/R/include" -DNDEBUG
> -DRCPP_USE_UNWIND_PROTECT -I'/usr/local/lib/R/site-library/Rcpp/include'
> -fpic -g -O3 -Wall -pipe -pedantic -c RcppExports.cpp -o RcppExports.o
> ccache g++-11 -I"/usr/share/R/include" -DNDEBUG
> -DRCPP_USE_UNWIND_PROTECT -I'/usr/local/lib/R/site-library/Rcpp/include'
> -fpic -g -O3 -Wall -pipe -pedantic -c callback.cpp -o callback.o
> ccache g++-11 -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions
> -flto=auto -Wl,-z,relro -o uptest.so RcppExports.o callback.o
> -L/usr/lib/R/lib -lR
> installing to
> /usr/local/lib/R/site-library/00LOCK-uptest/00new/uptest/libs
> ** R
> ** byte-compile and prepare package for lazy loading
> ** help
> *** installing help indices
> ** building package indices
> ** testing if installed package can be loaded from temporary location
> ** checking absolute paths in shared objects and dynamic libraries
> ** testing if installed package can be loaded from final location
> ** testing if installed package keeps a record of temporary installation
> path
> * DONE (uptest)
> edd at rob:/tmp/uptest(master)$ R -q
> > uptest::uptest()
> Well that went south
> [1] 42
> >
>
> So this catches the stop(), enters a designates block and resumes in the
> C++
> function that called it all still returning the 42 we desired as The
> Answer.
>
> Dirk
>
> --
> https://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20220206/d9b320a2/attachment.html>
More information about the Rcpp-devel
mailing list