-
-
Notifications
You must be signed in to change notification settings - Fork 218
Lay the ground for Rf_error masking (#1402) #1407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
* Add a message at compilation time * Protect the valid Rf_error calls generated by Rcpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR lays the groundwork for masking unsafe Rf_error() calls by introducing a macro that generates compilation messages warning users to use Rcpp::stop() instead. This is the first step toward addressing issue #1247.
- Adds a new macro header file that redefines
Rf_error()to emit a compilation warning message - Protects legitimate
Rf_error()calls in Rcpp-generated code using parentheses(Rf_error)()to bypass the macro - Provides an opt-out mechanism via
RCPP_NO_MASK_RF_ERRORfor false positives
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| inst/include/Rcpp/macros/mask.h | New file introducing the Rf_error macro that shows a compilation message directing users to Rcpp::stop() |
| inst/include/RcppCommon.h | Includes the new mask.h header file at the end of the common includes |
| src/attributes.cpp | Protects auto-generated Rf_error call with parentheses to prevent macro expansion |
| inst/tinytest/cpp/stack.cpp | Protects test code's Rf_error call with parentheses and updates copyright |
| inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp | Protects auto-generated Rf_error call with parentheses |
| ChangeLog | Documents all changes made in this PR |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Also better than my PR where @copilot always finds a typo to nag about.
…switching to a warning
|
So, as discussed, and the revdep machine made it clear, we cannot generate a note. Pragma messages are considered statements by gcc (see e.g. here and bugs linked there). Options are: be silent, or generate a warning without replacing. In order to ask CRAN about what they think, we need to calculate how many packages would generate this warning. An upper bound was provided here by just grepping the sources of all reverse dependencies: 263 packages. From these, only 24 would also fail compilation or checks as documented in #1406. To further refine this list, we could collect the install logs and grep for the pragma (are they in the revdep machine from the previous run?). |
| #ifndef RCPP_NO_MASK_RF_ERROR | ||
| #define Rf_error(...) \ | ||
| _Pragma("message \"Use of Rf_error() instead of Rcpp::stop(). Calls \ | ||
| _Pragma("GCC warning \"Use of Rf_error() instead of Rcpp::stop(). Calls \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it matters either way but in RcppArmadillo I used #pragma message. Kurt was able to filter these with a heads-up. That would be one softer than a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same. _Pragma expands into #pragma. It's the way to insert pragmas with preprocessor macros, because # has another meaning there.
First step to #1247
Rf_errorcalls generated by RcppChecklist
R CMD checkstill passes all tests