Skip to content

Commit 518f6fe

Browse files
committed
add RCPP_NO_MASK macro to protect individual calls
1 parent c0db69f commit 518f6fe

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

ChangeLog

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
* inst/include/Rcpp/macros/mask.h: Mask Rf_error with Rcpp::stop with
44
a warning at compilation time, unless RCPP_NO_MASK_RF_ERROR is defined
55
* inst/include/RcppCommon.h: Include the previous file in the last place
6-
* inst/tinytest/cpp/stack.cpp: Define RCPP_NO_MASK_RF_ERROR to enable
7-
Rf_error for this test
8-
* src/attributes.cpp: Undef then re-include masking to allow generated
9-
interface call to Rf_error
6+
* src/attributes.cpp: Use RCPP_NO_MASK to protect call to Rf_error
7+
* inst/tinytest/cpp/stack.cpp: Idem
108
* inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp: Idem
119

1210
2025-10-21 Iñaki Ucar <iucar@fedoraproject.org>

inst/include/Rcpp/macros/mask.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@
1717
// You should have received a copy of the GNU General Public License
1818
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
1919

20+
#ifndef Rcpp_macros_mask_h
21+
#define Rcpp_macros_mask_h
22+
23+
#define RCPP_NO_MASK_EMPTY()
24+
#define RCPP_NO_MASK(id) id RCPP_NO_MASK_EMPTY()
25+
2026
#ifndef RCPP_NO_MASK_RF_ERROR
21-
#define Rf_error \
27+
#define Rf_error(...) \
2228
_Pragma("GCC warning \"Invalid use of Rf_error, use Rcpp::stop instead\"") \
23-
Rcpp::stop
29+
Rcpp::stop(__VA_ARGS__)
30+
#endif
31+
2432
#endif

inst/tinytest/cpp/stack.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
// [[Rcpp::plugins(cpp11)]]
2424

25-
#define RCPP_NO_MASK_RF_ERROR
2625
#include <Rcpp.h>
2726
using namespace Rcpp;
2827

@@ -57,7 +56,7 @@ SEXP testSendInterrupt() {
5756
SEXP maybeThrow(void* data) {
5857
bool* fail = (bool*) data;
5958
if (*fail)
60-
Rf_error("throw!");
59+
RCPP_NO_MASK(Rf_error)("throw!");
6160
else
6261
return NumericVector::create(42);
6362
}

inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ RcppExport SEXP _testRcppInterfaceExporter_test_cpp_interface(SEXP xSEXP, SEXP f
4343
if (rcpp_isError_gen) {
4444
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
4545
UNPROTECT(1);
46-
#undef Rf_error
47-
Rf_error("%s", CHAR(rcpp_msgSEXP_gen));
48-
#include <Rcpp/macros/mask.h>
46+
RCPP_NO_MASK(Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
4947
}
5048
UNPROTECT(1);
5149
return rcpp_result_gen;

src/attributes.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,9 +2953,7 @@ namespace attributes {
29532953
<< " if (rcpp_isError_gen) {" << std::endl
29542954
<< " SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);" << std::endl
29552955
<< " UNPROTECT(1);" << std::endl
2956-
<< " #undef Rf_error" << std::endl
2957-
<< " Rf_error(\"%s\", CHAR(rcpp_msgSEXP_gen));" << std::endl
2958-
<< " #include <Rcpp/macros/mask.h>" << std::endl
2956+
<< " RCPP_NO_MASK(Rf_error)(\"%s\", CHAR(rcpp_msgSEXP_gen));" << std::endl
29592957
<< " }" << std::endl
29602958
<< " UNPROTECT(1);" << std::endl
29612959
<< " return rcpp_result_gen;" << std::endl

0 commit comments

Comments
 (0)