Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b2b02d

Browse files
committed
Lay the ground for Rf_error masking (#1402)
* Add a message at compilation time* Protect the valid Rf_error calls generated by Rcpp
1 parenta407ee6 commit9b2b02d

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

‎ChangeLog‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@
6767
* inst/include/Rcpp/r/check_r_headers.h: New header to check if R.h
6868
or related R headers were installed first
6969
* inst/include/RcppCommon.h: Call new header as first thing
70+
2025-11-12 Iñaki Ucar <iucar@fedoraproject.org>
71+
72+
* inst/include/Rcpp/macros/mask.h: Lay the ground for Rf_error masking,
73+
unless RCPP_NO_MASK_RF_ERROR is defined; the new define just generates a
74+
compilation note, which will become a warning + masking in a future release
75+
* inst/include/RcppCommon.h: Include the previous file in the last place
76+
* src/attributes.cpp: Use parentheses to protect call to Rf_error
77+
* inst/tinytest/cpp/stack.cpp: Idem
78+
* inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp: Idem
7079

7180
2025-11-04 Dirk Eddelbuettel <edd@debian.org>
7281

@@ -80,7 +89,7 @@
8089

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

83-
* inst/include/Rcpp/exceptions_impl.h:use __has_include to simplify checks
92+
* inst/include/Rcpp/exceptions_impl.h:Use __has_include to simplify checks
8493
to enable demangling, making them robust for more platforms
8594

8695
2025-10-13 Dirk Eddelbuettel <edd@debian.org>

‎inst/include/Rcpp/macros/mask.h‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// mask.h: Rcpp R/C++ interface class library -- masking macros
2+
//
3+
// Copyright (C) 2025 Iñaki Ucar
4+
//
5+
// This file is part of Rcpp.
6+
//
7+
// Rcpp is free software: you can redistribute it and/or modify it
8+
// under the terms of the GNU General Public License as published by
9+
// the Free Software Foundation, either version 2 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// Rcpp is distributed in the hope that it will be useful, but
13+
// WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU General Public License
18+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
19+
20+
#ifndefRcpp_macros_mask_h
21+
#defineRcpp_macros_mask_h
22+
23+
#ifndefRCPP_NO_MASK_RF_ERROR
24+
#defineRf_error(...) \
25+
_Pragma("message \"Use of Rf_error() instead of Rcpp::stop(). Calls \
26+
to Rf_error() in C++ contexts are unsafe: consider using Rcpp::stop() instead, \
27+
or define RCPP_NO_MASK_RF_ERROR if this is a false positive. More info:\n\
28+
- https://github.com/RcppCore/Rcpp/issues/1247\n\
29+
- https://github.com/RcppCore/Rcpp/pull/1402\"") \
30+
Rf_error(__VA_ARGS__)
31+
#endif
32+
33+
#endif

‎inst/include/RcppCommon.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,6 @@ namespace Rcpp {
190190

191191
#include<Rcpp/internal/wrap.h>
192192

193+
#include<Rcpp/macros/mask.h>
194+
193195
#endif

‎inst/tinytest/cpp/stack.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//
33
// misc.cpp: Rcpp R/C++ interface class library -- misc unit tests
44
//
5-
// Copyright (C) 2013 - 2022 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2013 - 2024 Dirk Eddelbuettel and Romain Francois
6+
// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
67
//
78
// This file is part of Rcpp.
89
//
@@ -55,7 +56,7 @@ SEXP testSendInterrupt() {
5556
SEXPmaybeThrow(void* data) {
5657
bool* fail = (bool*) data;
5758
if (*fail)
58-
Rf_error("throw!");
59+
(Rf_error)("throw!");// prevent masking
5960
else
6061
returnNumericVector::create(42);
6162
}

‎inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +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-
Rf_error("%s",CHAR(rcpp_msgSEXP_gen));
46+
(Rf_error)("%s",CHAR(rcpp_msgSEXP_gen));
4747
}
4848
UNPROTECT(1);
4949
return rcpp_result_gen;

‎src/attributes.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,8 @@ 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-
<<" Rf_error(\"%s\", CHAR(rcpp_msgSEXP_gen));" << std::endl
2956+
// Parentheses to prevent masking
2957+
<<" (Rf_error)(\"%s\", CHAR(rcpp_msgSEXP_gen));" << std::endl
29572958
<<" }" << std::endl
29582959
<<" UNPROTECT(1);" << std::endl
29592960
<<" return rcpp_result_gen;" << std::endl

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp