Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
* inst/include/Rcpp/hash/SelfHash.h: Idem
* inst/tinytest/test_sugar.R: Add test for signed zeroes

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

* inst/include/Rcpp/macros/mask.h: Mask Rf_error with Rcpp::stop with
a warning at compilation time, unless RCPP_NO_MASK_RF_ERROR is defined
* inst/include/RcppCommon.h: Include the previous file in the last place
* src/attributes.cpp: Use parentheses to protect call to Rf_error
* inst/tinytest/cpp/stack.cpp: Idem
* inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp: Idem

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

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

2025-10-13 Dirk Eddelbuettel <edd@debian.org>
Expand Down
31 changes: 31 additions & 0 deletions inst/include/Rcpp/macros/mask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// mask.h: Rcpp R/C++ interface class library -- masking macros
//
// Copyright (C) 2025 Iñaki Ucar
//
// This file is part of Rcpp.
//
// Rcpp is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Rcpp is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.

#ifndef Rcpp_macros_mask_h
#define Rcpp_macros_mask_h

#ifndef RCPP_NO_MASK_RF_ERROR
#define Rf_error(...) \
_Pragma("GCC warning \"Use of Rf_error() replaced with Rcpp::stop(). Calls \
to Rf_error() in C++ contexts are unsafe: consider using Rcpp::stop() instead, \
or define RCPP_NO_MASK_RF_ERROR if this is a false positive.\"") \
Rcpp::stop(__VA_ARGS__)
#endif

#endif
4 changes: 3 additions & 1 deletion inst/include/RcppCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
// Copyright (C) 2009 - 2020 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2021 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
// Copyright (C) 2021 - 2025 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
//
// This file is part of Rcpp.
//
Expand Down Expand Up @@ -191,4 +191,6 @@ namespace Rcpp {

#include <Rcpp/internal/wrap.h>

#include <Rcpp/macros/mask.h>

#endif
5 changes: 3 additions & 2 deletions inst/tinytest/cpp/stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
//
// misc.cpp: Rcpp R/C++ interface class library -- misc unit tests
//
// Copyright (C) 2013 - 2022 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2013 - 2024 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2025 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
//
// This file is part of Rcpp.
//
Expand Down Expand Up @@ -55,7 +56,7 @@ SEXP testSendInterrupt() {
SEXP maybeThrow(void* data) {
bool* fail = (bool*) data;
if (*fail)
Rf_error("throw!");
(Rf_error)("throw!"); // prevent masking
else
return NumericVector::create(42);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RcppExport SEXP _testRcppInterfaceExporter_test_cpp_interface(SEXP xSEXP, SEXP f
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error("%s", CHAR(rcpp_msgSEXP_gen));
(Rf_error)("%s", CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
Expand Down
3 changes: 2 additions & 1 deletion src/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2953,7 +2953,8 @@ namespace attributes {
<< " if (rcpp_isError_gen) {" << std::endl
<< " SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);" << std::endl
<< " UNPROTECT(1);" << std::endl
<< " Rf_error(\"%s\", CHAR(rcpp_msgSEXP_gen));" << std::endl
// Parentheses to prevent masking
<< " (Rf_error)(\"%s\", CHAR(rcpp_msgSEXP_gen));" << std::endl
<< " }" << std::endl
<< " UNPROTECT(1);" << std::endl
<< " return rcpp_result_gen;" << std::endl
Expand Down