Skip to content

Commit 4b4d780

Browse files
authored
Drop support for R 3.6 and remove dead code (#411)
* Drop support for R 3.6 * NEWS bullet * Remove dead code from tests * Remove dead code from `environment.hpp` * Remove dead code from `protect.hpp` * Simplify `altrep.hpp` as much as possible Likely still need to keep it around for compatibility reasons * NEWS bullet about `altrep.hpp` * Bring back dummy `HAS_UNWIND_PROTECT` and remove all usage of it
1 parent dc93fb8 commit 4b4d780

File tree

15 files changed

+22
-103
lines changed

15 files changed

+22
-103
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ jobs:
2727
- {os: macos-latest, r: 'release'}
2828

2929
- {os: windows-latest, r: 'release'}
30-
# Use 3.6 to trigger usage of RTools35
31-
- {os: windows-latest, r: '3.6'}
3230
# use 4.1 to check with rtools40's older compiler
3331
- {os: windows-latest, r: '4.1'}
3432

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ License: MIT + file LICENSE
1818
URL: https://cpp11.r-lib.org, https://github.com/r-lib/cpp11
1919
BugReports: https://github.com/r-lib/cpp11/issues
2020
Depends:
21-
R (>= 3.6.0)
21+
R (>= 4.0.0)
2222
Suggests:
2323
bench,
2424
brio,

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
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+
7+
* Because cpp11 now requires R >=4.0.0 and ALTREP is always available, the
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).
10+
11+
* cpp11 now requires R >=4.0.0, in line with the
12+
[tidyverse version policy](https://www.tidyverse.org/blog/2019/04/r-version-support/) (#411).
13+
314
# cpp11 0.5.0
415

516
## R non-API related changes

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-doubles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ context("doubles-C++") {
233233
UNPROTECT(1);
234234
}
235235

236-
#if defined(__APPLE__) && defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0)
236+
#if defined(__APPLE__)
237237
test_that("writable::doubles(ALTREP_SEXP)") {
238238
// ALTREP compact-seq
239239
auto seq = cpp11::package("base")["seq"];

cpp11test/src/test-integers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "Rversion.h"
21
#include "cpp11/R.hpp"
32
#include "cpp11/doubles.hpp"
43
#include "cpp11/function.hpp"
@@ -218,7 +217,7 @@ context("integers-C++") {
218217
expect_true(x[2] == 3);
219218
}
220219

221-
#if defined(__APPLE__) && defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0)
220+
#if defined(__APPLE__)
222221
test_that("writable::integers(ALTREP_SEXP)") {
223222
// ALTREP compact-seq
224223
auto seq = cpp11::package("base")["seq"];

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

cpp11test/src/test-r_vector.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77

88
#include <algorithm> // for max_element
99

10-
#ifdef _WIN32
11-
#include "Rversion.h"
12-
#define CPP11_HAS_IS_UTILITIES R_VERSION >= R_Version(4, 0, 0)
13-
#else
14-
#define CPP11_HAS_IS_UTILITIES 1
15-
#endif
16-
17-
#if CPP11_HAS_IS_UTILITIES
1810
context("r_vector-capabilities-C++") {
1911
test_that("read only vector capabilities") {
2012
using cpp11::integers;
@@ -77,7 +69,6 @@ context("r_vector-capabilities-C++") {
7769
expect_true(std::is_move_assignable<integers::proxy>::value);
7870
}
7971
}
80-
#endif
8172

8273
context("r_vector-C++") {
8374
test_that("writable vector temporary isn't leaked (integer) (#338)") {

inst/include/cpp11/R.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
// clang-format on
2828

2929
#include <type_traits>
30-
#include "cpp11/altrep.hpp"
3130

3231
#if defined(R_VERSION) && R_VERSION >= R_Version(4, 4, 0)
3332
// Use R's new macro

inst/include/cpp11/altrep.hpp

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
11
#pragma once
22

3-
#include "Rversion.h"
4-
5-
#if defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0)
3+
// It would be nice to remove this since all supported versions of R have ALTREP, but
4+
// some groups rely on both this `#define` and `altrep.hpp` itself existing, like arrow:
5+
// https://github.com/apache/arrow/blob/50f2d6e04e8323119d4dd31506827ee398d6b8e4/r/src/altrep.cpp#L27-L29
66
#define HAS_ALTREP
7-
#endif
8-
9-
#ifndef HAS_ALTREP
10-
11-
#define ALTREP(x) false
12-
13-
#define REAL_ELT(x, i) REAL(x)[i]
14-
#define INTEGER_ELT(x, i) INTEGER(x)[i]
15-
#define LOGICAL_ELT(x, i) LOGICAL(x)[i]
16-
#define RAW_ELT(x, i) RAW(x)[i]
17-
18-
#define SET_REAL_ELT(x, i, val) REAL(x)[i] = val
19-
#define SET_INTEGER_ELT(x, i, val) INTEGER(x)[i] = val
20-
#define SET_LOGICAL_ELT(x, i, val) LOGICAL(x)[i] = val
21-
#define SET_RAW_ELT(x, i, val) RAW(x)[i] = val
22-
23-
#define REAL_GET_REGION(...) \
24-
do { \
25-
} while (false)
26-
27-
#define INTEGER_GET_REGION(...) \
28-
do { \
29-
} while (false)
30-
#endif
31-
32-
#if !defined HAS_ALTREP || (defined(R_VERSION) && R_VERSION < R_Version(3, 6, 0))
33-
34-
#define LOGICAL_GET_REGION(...) \
35-
do { \
36-
} while (false)
37-
38-
#define RAW_GET_REGION(...) \
39-
do { \
40-
} while (false)
41-
42-
#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/environment.hpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@
22

33
#include <string> // for string, basic_string
44

5-
#include "Rversion.h" // for R_VERSION, R_Version
65
#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_install, r_env_get...
76
#include "cpp11/as.hpp" // for as_sexp
87
#include "cpp11/protect.hpp" // for protect, protect::function, safe, unwin...
98
#include "cpp11/sexp.hpp" // for sexp
109

11-
#if R_VERSION >= R_Version(4, 0, 0)
12-
#define HAS_REMOVE_VAR_FROM_FRAME
13-
#endif
14-
15-
#ifndef HAS_REMOVE_VAR_FROM_FRAME
16-
#include "cpp11/function.hpp"
17-
#endif
18-
1910
namespace cpp11 {
2011

2112
class environment {
@@ -51,12 +42,7 @@ class environment {
5142

5243
void remove(SEXP name) {
5344
PROTECT(name);
54-
#ifdef HAS_REMOVE_VAR_FROM_FRAME
5545
R_removeVarFromFrame(name, env_);
56-
#else
57-
auto remove = package("base")["remove"];
58-
remove(name, "envir"_nm = env_);
59-
#endif
6046
UNPROTECT(1);
6147
}
6248

inst/include/cpp11/protect.hpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#include "R_ext/Error.h" // for Rf_error, Rf_warning
1414
#include "R_ext/Print.h" // for REprintf
1515
#include "R_ext/Utils.h" // for R_CheckUserInterrupt
16-
#include "Rversion.h" // for R_VERSION, R_Version
1716

18-
#if defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0)
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
1921
#define HAS_UNWIND_PROTECT
20-
#endif
2122

2223
#ifdef CPP11_USE_FMT
2324
#define FMT_HEADER_ONLY
@@ -31,8 +32,6 @@ class unwind_exception : public std::exception {
3132
unwind_exception(SEXP token_) : token(token_) {}
3233
};
3334

34-
#ifdef HAS_UNWIND_PROTECT
35-
3635
/// Unwind Protection from C longjmp's, like those used in R error handling
3736
///
3837
/// @param code The code to which needs to be protected, as a nullary callable
@@ -95,15 +94,6 @@ unwind_protect(Fun&& code) {
9594
return out;
9695
}
9796

98-
#else
99-
// Don't do anything if we don't have unwind protect. This will leak C++ resources,
100-
// including those held by cpp11 objects, but the other alternatives are also not great.
101-
template <typename Fun>
102-
decltype(std::declval<Fun&&>()()) unwind_protect(Fun&& code) {
103-
return std::forward<Fun>(code)();
104-
}
105-
#endif
106-
10797
namespace detail {
10898

10999
template <size_t...>

0 commit comments

Comments
 (0)