Skip to content

Commit d1de49f

Browse files
Enchufa2eddelbuettel
authored andcommitted
Mask definition of Rf_error to avoid longjmp issues
1 parent 8b6d97c commit d1de49f

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

ChangeLog

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
* inst/include/Rcpp/hash/IndexHash.h: Normalize values for all comparisons
44
* inst/include/Rcpp/hash/SelfHash.h: Idem
55
* inst/tinytest/test_sugar.R: Add test for signed zeroes
6+
2025-10-28 Iñaki Ucar <iucar@fedoraproject.org>
7+
8+
* inst/include/Rcpp/macros/mask.h: Mask Rf_error with Rcpp::stop with
9+
a warning at compilation time, unless RCPP_NO_MASK_RF_ERROR is defined
10+
* inst/include/RcppCommon.h: Include the previous file in the last place
11+
* inst/tinytest/cpp/stack.cpp: Define RCPP_NO_MASK_RF_ERROR to enable
12+
Rf_error for this test
13+
* src/attributes.cpp: Undef then re-include masking to allow generated
14+
interface call to Rf_error
15+
* inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp: Idem
616

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

9-
* inst/include/Rcpp/exceptions_impl.h: use __has_include to simplify checks
19+
* inst/include/Rcpp/exceptions_impl.h: Use __has_include to simplify checks
1020
to enable demangling, making them robust for more platforms
1121

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

inst/include/Rcpp/macros/mask.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
#ifndef RCPP_NO_MASK_RF_ERROR
21+
#define Rf_error \
22+
_Pragma("GCC warning \"Invalid use of Rf_error, use Rcpp::stop instead\"") \
23+
Rcpp::stop
24+
#endif

inst/include/RcppCommon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
66
// Copyright (C) 2009 - 2020 Dirk Eddelbuettel and Romain Francois
7-
// Copyright (C) 2021 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
7+
// Copyright (C) 2021 - 2025 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
88
//
99
// This file is part of Rcpp.
1010
//
@@ -191,4 +191,6 @@ namespace Rcpp {
191191

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

194+
#include <Rcpp/macros/mask.h>
195+
194196
#endif

inst/tinytest/cpp/stack.cpp

Lines changed: 3 additions & 1 deletion
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
//
@@ -21,6 +22,7 @@
2122

2223
// [[Rcpp::plugins(cpp11)]]
2324

25+
#define RCPP_NO_MASK_RF_ERROR
2426
#include <Rcpp.h>
2527
using namespace Rcpp;
2628

inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ 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
4647
Rf_error("%s", CHAR(rcpp_msgSEXP_gen));
48+
#include <Rcpp/macros/mask.h>
4749
}
4850
UNPROTECT(1);
4951
return rcpp_result_gen;

src/attributes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,9 @@ 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
29562957
<< " Rf_error(\"%s\", CHAR(rcpp_msgSEXP_gen));" << std::endl
2958+
<< " #include <Rcpp/macros/mask.h>" << std::endl
29572959
<< " }" << std::endl
29582960
<< " UNPROTECT(1);" << std::endl
29592961
<< " return rcpp_result_gen;" << std::endl

0 commit comments

Comments
 (0)