Skip to content

Commit 3270efe

Browse files
committed
Bring back dummy HAS_UNWIND_PROTECT and remove all usage of it
1 parent bd297ff commit 3270efe

File tree

7 files changed

+13
-21
lines changed

7 files changed

+13
-21
lines changed

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# cpp11 (development version)
22

3+
* Because cpp11 now requires R >=4.0.0 and `R_UnwindProtect()` is always
4+
available, `HAS_UNWIND_PROTECT` is no longer useful. Please avoid using it,
5+
as we'd like to remove it in the future (#411).
6+
37
* Because cpp11 now requires R >=4.0.0 and ALTREP is always available, the
4-
`cpp11/altrep.hpp` file is no longer useful. Please avoid using `#include "cpp11/altrep.hpp"` as we'd like to remove this file in the future (#411).
8+
`cpp11/altrep.hpp` file is no longer useful. Please avoid using `#include "cpp11/altrep.hpp"` and `HAS_ALTREP` as we'd like to remove them in the
9+
future (#411).
510

611
* cpp11 now requires R >=4.0.0, in line with the
712
[tidyverse version policy](https://www.tidyverse.org/blog/2019/04/r-version-support/) (#411).

cpp11test/src/safe.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
if (buf[0] != '\0') {
2727
Rf_error("%s", buf);
2828
} else if (err != R_NilValue) {
29-
#ifdef HAS_UNWIND_PROTECT
3029
R_ContinueUnwind(err);
31-
#endif
3230
}
3331

3432
return R_NilValue;

cpp11test/src/test-as.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ context("as_cpp-C++") {
4949
auto x5 = cpp11::as_cpp<unsigned long>(r);
5050
expect_true(x5 == 42UL);
5151

52-
#ifdef HAS_UNWIND_PROTECT
5352
/* throws a runtime exception if the value is not a integerish one */
5453
REAL(r)[0] = 42.5;
5554
expect_error(cpp11::as_cpp<int>(r));
56-
#endif
5755

5856
UNPROTECT(1);
5957
}

cpp11test/src/test-protect-nested.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include "cpp11/protect.hpp"
33
#include "testthat.h"
44

5-
#ifdef HAS_UNWIND_PROTECT
6-
75
/*
86
* See https://github.com/r-lib/cpp11/pull/327 for full details.
97
*
@@ -77,5 +75,3 @@ context("unwind_protect-nested-C++") {
7775
destructed = false;
7876
}
7977
}
80-
81-
#endif

cpp11test/src/test-protect.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "cpp11/protect.hpp"
33
#include "testthat.h"
44

5-
#ifdef HAS_UNWIND_PROTECT
65
context("unwind_protect-C++") {
76
test_that("unwind_protect works if there is no error") {
87
SEXP out = PROTECT(cpp11::unwind_protect([&] {
@@ -49,5 +48,3 @@ context("unwind_protect-C++") {
4948
expect_error_as(cpp11::safe[Rf_allocVector](REALSXP, -1), cpp11::unwind_exception);
5049
}
5150
}
52-
53-
#endif

inst/include/cpp11/declarations.hpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ T& unmove(T&& t) {
3030
}
3131
} // namespace cpp11
3232

33-
#ifdef HAS_UNWIND_PROTECT
34-
#define CPP11_UNWIND R_ContinueUnwind(err);
35-
#else
36-
#define CPP11_UNWIND \
37-
do { \
38-
} while (false);
39-
#endif
40-
4133
#define CPP11_ERROR_BUFSIZE 8192
4234

4335
#define BEGIN_CPP11 \
@@ -58,6 +50,6 @@ T& unmove(T&& t) {
5850
if (buf[0] != '\0') { \
5951
Rf_errorcall(R_NilValue, "%s", buf); \
6052
} else if (err != R_NilValue) { \
61-
CPP11_UNWIND \
53+
R_ContinueUnwind(err); \
6254
} \
6355
return R_NilValue;

inst/include/cpp11/protect.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
#include "R_ext/Print.h" // for REprintf
1515
#include "R_ext/Utils.h" // for R_CheckUserInterrupt
1616

17+
// We would like to remove this, since all supported versions of R now support proper
18+
// unwind protect, but some groups rely on it existing, like arrow and systemfonts
19+
// https://github.com/r-lib/systemfonts/blob/02b567086379edaca1a9b3620ad6776e6bb876a7/src/utils.h#L11
20+
// https://github.com/apache/arrow/blob/50f2d6e04e8323119d4dd31506827ee398d6b8e4/r/src/safe-call-into-r-impl.cpp#L49
21+
#define HAS_UNWIND_PROTECT
22+
1723
#ifdef CPP11_USE_FMT
1824
#define FMT_HEADER_ONLY
1925
#include "fmt/core.h"

0 commit comments

Comments
 (0)