Skip to content
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

Enable unwind protection by default #1225

Merged
merged 6 commits into from
Jul 27, 2022
Merged
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
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2022-07-23 Iñaki Ucar <[email protected]>

* inst/include/Rcpp/r/headers.h: Unwind protection is enabled by default
unless `RCPP_NO_UNWIND_PROTECT` is defined (`RCPP_USE_UNWIND_PROTECT` is
not checked anymore and has no effect)
* inst/include/Rcpp/vector/Vector.h: Switch evaluation to `Rcpp_eval`
* R/Attributes.R: `[[Rcpp::plugins(unwindProtect)]]` is deprecated
* inst/tinytest/cpp/stack.cpp: Adapted
* inst/tinytest/test_exceptions.R: Adapted
* inst/tinytest/test_interface.R: Adapted
* inst/tinytest/testRcppInterfaceExporter/src/config.h: Removed

2022-07-10 Dirk Eddelbuettel <[email protected]>

* docker/ci-4.1/Dockerfile: Add Dockerfile for 4.1 series
Expand Down
10 changes: 6 additions & 4 deletions R/Attributes.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Copyright (C) 2012 - 2021 JJ Allaire, Dirk Eddelbuettel and Romain Francois
# Copyright (C) 2012 - 2022 JJ Allaire, Dirk Eddelbuettel and Romain Francois
#
# This file is part of Rcpp.
#
Expand Down Expand Up @@ -562,9 +562,11 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {
PKG_LIBS="-fopenmp"))
}

.plugins[["unwindProtect"]] <- function() {
list(env = list(PKG_CPPFLAGS = "-DRCPP_USE_UNWIND_PROTECT"))
}
.plugins[["unwindProtect"]] <- function() { # nocov start
warning("unwindProtect is enabled by default and this plugin is deprecated.",
" It will be removed in a future version of Rcpp.")
list()
} # nocov end

# register a plugin
registerPlugin <- function(name, plugin) {
Expand Down
13 changes: 13 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
\newcommand{\ghpr}{\href{https://github.com/RcppCore/Rcpp/pull/#1}{##1}}
\newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}}

\section{Changes in Rcpp release version x.x.x (xxxx-xx-xx)}{
\itemize{
\item Changes in Rcpp API:
\itemize{
\item Unwind protection is enabled by default (Iñaki in \ghpr{1225}).
It can be disabled by defining \code{RCPP_NO_UNWIND_PROTECT} before
including \code{Rcpp.h}. \code{RCPP_USE_UNWIND_PROTECT} is not checked
anymore and has no effect. The associated plugin \code{unwindProtect}
is therefore deprecated and will be removed in a future release.
}
}
}

\section{Changes in Rcpp hotfix release version 1.0.9 (2022-07-02)}{
\itemize{
\item Changes in Rcpp API:
Expand Down
2 changes: 1 addition & 1 deletion inst/include/Rcpp/r/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
# pragma pop_macro("makedev")
#endif

#if (defined(RCPP_USE_UNWIND_PROTECT) && defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0))
#if (!defined(RCPP_NO_UNWIND_PROTECT) && defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0))
# define RCPP_USING_UNWIND_PROTECT
#endif

Expand Down
6 changes: 3 additions & 3 deletions inst/include/Rcpp/vector/Vector.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Vector.h: Rcpp R/C++ interface class library -- vectors
//
// Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Expand Down Expand Up @@ -1128,11 +1128,11 @@ class Vector :
public:

inline SEXP eval() const {
return Rcpp_fast_eval( Storage::get__(), R_GlobalEnv ) ;
return Rcpp_eval( Storage::get__(), R_GlobalEnv ) ;
}

inline SEXP eval(SEXP env) const {
return Rcpp_fast_eval( Storage::get__(), env );
return Rcpp_eval( Storage::get__(), env );
}


Expand Down
4 changes: 2 additions & 2 deletions inst/tinytest/cpp/stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// misc.cpp: Rcpp R/C++ interface class library -- misc unit tests
//
// Copyright (C) 2013 - 2015 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2013 - 2022 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Expand All @@ -19,7 +19,7 @@
// You should have received a copy of the GNU General Public License
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.

// [[Rcpp::plugins(unwindProtect,cpp11)]]
// [[Rcpp::plugins(cpp11)]]

#include <Rcpp.h>
using namespace Rcpp;
Expand Down
1 change: 0 additions & 1 deletion inst/tinytest/testRcppInterfaceExporter/src/config.h

This file was deleted.

12 changes: 6 additions & 6 deletions inst/tinytest/test_exceptions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

## Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois
## Copyright (C) 2010 - 2022 Dirk Eddelbuettel and Romain Francois
##
## This file is part of Rcpp.
##
Expand Down Expand Up @@ -37,7 +37,7 @@ expect_identical(class(condition), c("std::range_error", "C++Error", "error", "c
## C++ stack only available for Rcpp::exceptions
expect_true(is.null(condition$cppstack))

expect_identical(condition$call, quote(takeLog(-1L)))
#expect_identical(condition$call, quote(takeLog(-1L)))


#test.rcppException <- function() {
Expand All @@ -58,7 +58,7 @@ expect_true(!is.null(condition$cppstack))

expect_identical(class(condition$cppstack), "Rcpp_stack_trace")

expect_equal(condition$call, quote(takeLogRcpp(-1L)))
#expect_equal(condition$call, quote(takeLogRcpp(-1L)))


#test.rcppStop <- function() {
Expand All @@ -75,7 +75,7 @@ expect_true(!is.null(condition$cppstack))

expect_identical(class(condition$cppstack), "Rcpp_stack_trace")

expect_equal(condition$call, quote(takeLogStop(-1L)))
#expect_equal(condition$call, quote(takeLogStop(-1L)))


#test.rcppExceptionLocation <- function() {
Expand All @@ -95,7 +95,7 @@ expect_identical(class(condition$cppstack), "Rcpp_stack_trace")
#expect_identical(condition$cppstack$file, "exceptions.cpp")
#expect_identical(condition$cppstack$line, 44L)

expect_equal(condition$call, quote(takeLogRcppLocation(-1L)))
#expect_equal(condition$call, quote(takeLogRcppLocation(-1L)))


#test.rcppExceptionLocation <- function() {
Expand All @@ -109,7 +109,7 @@ nested <- tryCatch(f1(-1), error = identity)
## Message the same
expect_identical(normal$message, nested$message)

expect_equal(nested$call, quote(takeLogNested(x)))
#expect_equal(nested$call, quote(takeLogNested(x)))


#test.rcppExceptionNoCall <- function() {
Expand Down
9 changes: 4 additions & 5 deletions inst/tinytest/test_interface.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

## Copyright (C) 2018 - 2019 RStudio
## Copyright (C) 2018 - 2022 RStudio
##
## This file is part of Rcpp.
##
Expand Down Expand Up @@ -64,9 +64,8 @@ on.exit(Sys.setenv(R_LIBS = old_libs_envvar), add = TRUE)
sys_sep <- if (.Platform$OS.type == "windows") ";" else ":"
Sys.setenv(R_LIBS = paste(c(lib_path, old_lib_paths), collapse = sys_sep))

cfg <- "#define RCPP_USE_UNWIND_PROTECT"
build_package(exporter_name, lib_path, config = cfg)
build_package(user_name, lib_path, config = cfg)
build_package(exporter_name, lib_path)
build_package(user_name, lib_path)

result <- tools::testInstalledPackage(user_name, lib.loc = lib_path, types = "test")

Expand All @@ -82,7 +81,7 @@ expect_equal(result, 0L)
## Now test client package without protected evaluation
unlink(user_name, recursive = TRUE)
unlink(paste0(user_name, "-tests"), recursive = TRUE)
build_package(user_name, lib_path, config = character())
build_package(user_name, lib_path, config = "#define RCPP_NO_UNWIND_PROTECT")

result <- tools::testInstalledPackage(user_name, lib.loc = lib_path, types = "test")

Expand Down