Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uptwo (short) new entries for Rcpp-FAQ vignette #1009
Conversation
|
|
||
| ## Can we use exceptions and stop() across shared libraries? | ||
|
|
||
| No, sadly. A known limitation coming from the operating system, Windows in |
jjallaire
Oct 28, 2019
Member
I think this might in it's present form be too cautionary. In all Rcpp attribute generated code (including the export of C++ interfaces to other packages) we handle this gracefully. The only place I'm aware of in Rcpp where this bites is specifically in Rcpp Module methods on Windows only. I think we might be better off just adding docs to modules saying you can't call stop() from within methods (they should always return something even if just an error object).
I think this might in it's present form be too cautionary. In all Rcpp attribute generated code (including the export of C++ interfaces to other packages) we handle this gracefully. The only place I'm aware of in Rcpp where this bites is specifically in Rcpp Module methods on Windows only. I think we might be better off just adding docs to modules saying you can't call stop() from within methods (they should always return something even if just an error object).
eddelbuettel
Oct 28, 2019
Author
Member
Hm, I thought we still bound by the general restriction of not being able to throw/catch across distinct DLLs? But maybe I am indeed to pessimistic in that view as it would blow up the use case of, eg, RQuantLib catching QuantLib errors.
Easy to rewrite as "Mostly. A known remaining limitation ..." I can take a stab at it later.
Hm, I thought we still bound by the general restriction of not being able to throw/catch across distinct DLLs? But maybe I am indeed to pessimistic in that view as it would blow up the use case of, eg, RQuantLib catching QuantLib errors.
Easy to rewrite as "Mostly. A known remaining limitation ..." I can take a stab at it later.
kevinushey
Oct 28, 2019
Contributor
Cross-DLL exceptions work as long as:
- You are linking to a non-static C++ standard library;
- You are using the same standard library in all compiled objects.
Unfortunately, 1. is not true on Windows as R opts to link to libstdc++ statically; there was some discussion about whether this could be changed for Rtools 4.0 but it sounds like that won't happen.
In some cases, 2. is also not true -- e.g. on macOS users might end up mixing the version of libc++ bundled with R in some dylibs, and the system version of libc++ in others. Usually this means that the exception type info isn't properly handled across module boundaries.
Cross-DLL exceptions work as long as:
- You are linking to a non-static C++ standard library;
- You are using the same standard library in all compiled objects.
Unfortunately, 1. is not true on Windows as R opts to link to libstdc++ statically; there was some discussion about whether this could be changed for Rtools 4.0 but it sounds like that won't happen.
In some cases, 2. is also not true -- e.g. on macOS users might end up mixing the version of libc++ bundled with R in some dylibs, and the system version of libc++ in others. Usually this means that the exception type info isn't properly handled across module boundaries.
kevinushey
Oct 28, 2019
Contributor
(and of course, Rcpp attributes help us as, if one calls an attributes-generated function, any C++ exceptions are effectively shielded by try-catch and so are not propagated into a separate DLL)
(and of course, Rcpp attributes help us as, if one calls an attributes-generated function, any C++ exceptions are effectively shielded by try-catch and so are not propagated into a separate DLL)
eddelbuettel
Nov 3, 2019
Author
Member
@jjallaire @kevinushey Thanks for the very helpful comments.
I just rebased and force-pushed this branch adding one refining commit. The diff in the commit now shows an expanded and refined answer to this new FAQ entry based on your comments.
@jjallaire @kevinushey Thanks for the very helpful comments.
I just rebased and force-pushed this branch adding one refining commit. The diff in the commit now shows an expanded and refined answer to this new FAQ entry based on your comments.
|
I'm not sure about the RQuantLib case but I'd say given we haven't really
heard about this save for modules that perhaps there is some other
mediation in place there?
…On Mon, Oct 28, 2019 at 7:38 AM Dirk Eddelbuettel ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In vignettes/rmd/Rcpp-FAQ.Rmd
<#1009 (comment)>:
> @@ -1720,3 +1737,11 @@ elsewhere.
So if your autogenerated file fails, and a `symbols not found` error is reported
by the linker, consider running `compileAttributes()` twice. Deleting
`R/RcppExports.R` and `src/RcppExports.cpp` may also work.
+
+## Can we use exceptions and stop() across shared libraries?
+
+No, sadly. A known limitation coming from the operating system, Windows in
Hm, I thought we still bound by the general restriction of not being able
to throw/catch across distinct DLLs? But maybe I am indeed to pessimistic
in that view as it would blow up the use case of, eg, RQuantLib catching
QuantLib errors.
Easy to rewrite as "Mostly. A known remaining limitation ..." I can take a
stab at it later.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1009?email_source=notifications&email_token=AAAZPRYG7ST25WCAF43AQ43QQ3FNDA5CNFSM4JFY4WA2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCJMHYYI#discussion_r339518406>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZPR5PQMRTEEXLWRS24QLQQ3FNDANCNFSM4JFY4WAQ>
.
|
|
Yes I meant that in general it just works (at least on not-on-Windows). I.e. at work we have a large-ish standard C++ codebase, exceptions are generally forbidden and it asserts and exits on error so for the calling-from-R-case I redefine these as Rcpp::stop() and it works just fine. Just not sure about Windows which I have the benefit of mostly not seeing anymore .... |
Codecov Report
@@ Coverage Diff @@
## master #1009 +/- ##
=======================================
Coverage 82.46% 82.46%
=======================================
Files 63 63
Lines 3166 3166
=======================================
Hits 2611 2611
Misses 555 555Continue to review full report at Codecov.
|
|
@kevinushey @jjallaire if/when you have a chance glance over the current state of the new paragraphs and especially the updated / rewritten second one reflecting your really useful feedback. Otherwise looks like we are good to go. May toss this at CRAN soon as 1.0.3. |
|
Ok, I will take "no further comment" in the generous sense of "no further complaints" Merging now and going to prepare a 1.0.3 release. |
Two simple additions which provide a start.
@kevinushey @jjallaire if you have comments / extensions maybe commit straight into branch?