Skip to content

Commit a05a33d

Browse files
committed
feat: Update vendored cpp11 to 0.5.1 (#636)
* Revert "ifndef" This reverts commit 9afb676. * Revert "Reapply 782630b minus the whitespace changes" This reverts commit f05d56c. * Reapply "Revert a011d42" This reverts commit fe615c4. * Reapply "Revert fb18a2d" This reverts commit 6f4979d. * Vendor cpp11 0.5.1 * Add `prot` argument to `external_pointer()` constructor r-lib/cpp11#420 This reverts commit abcae40e2aff8b1664098294959b8df743605737. * END_CPP11_EX() r-lib/cpp11#421 * Protection r-lib/cpp11#422 This reverts commit 1e181e5e5c2cf0a21906b49dafe80364c8ca3f2b. * External pointer premature release r-lib/cpp11#423 This reverts commit 1b698e533ea7c7003cb610a5f5f7e5a47966c59d.
1 parent 8696004 commit a05a33d

24 files changed

+73
-134
lines changed

inst/include/cpp11.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include "cpp11/R.hpp"

inst/include/cpp11/R.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#ifdef R_INTERNALS_H_
@@ -13,9 +13,11 @@
1313
#ifndef R_NO_REMAP
1414
#define R_NO_REMAP
1515
#endif
16+
1617
#ifndef STRICT_R_HEADERS
1718
#define STRICT_R_HEADERS
1819
#endif
20+
1921
#include "R_ext/Boolean.h"
2022
#include "Rinternals.h"
2123
#include "Rversion.h"
@@ -33,7 +35,6 @@
3335
// clang-format on
3436

3537
#include <type_traits>
36-
#include "cpp11/altrep.hpp"
3738

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

inst/include/cpp11/altrep.hpp

+5-41
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,8 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

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

inst/include/cpp11/as.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <cmath> // for modf

inst/include/cpp11/attribute_proxy.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <initializer_list> // for initializer_list

inst/include/cpp11/data_frame.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <cstdlib> // for abs

inst/include/cpp11/declarations.hpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <cstring>
@@ -32,13 +32,10 @@ T& unmove(T&& t) {
3232
}
3333
} // namespace cpp11
3434

35-
#ifdef HAS_UNWIND_PROTECT
35+
// We would like to remove this, since all supported versions of R now support proper
36+
// unwind protect, but some groups rely on it existing, like textshaping:
37+
// https://github.com/r-lib/cpp11/issues/414
3638
#define CPP11_UNWIND R_ContinueUnwind(err);
37-
#else
38-
#define CPP11_UNWIND \
39-
do { \
40-
} while (false);
41-
#endif
4239

4340
#define CPP11_ERROR_BUFSIZE 8192
4441

@@ -60,7 +57,7 @@ T& unmove(T&& t) {
6057
if (buf[0] != '\0') { \
6158
Rf_errorcall(R_NilValue, "%s", buf); \
6259
} else if (err != R_NilValue) { \
63-
CPP11_UNWIND \
60+
R_ContinueUnwind(err); \
6461
} \
6562
return RET;
6663
#define END_CPP11 END_CPP11_EX(R_NilValue)

inst/include/cpp11/doubles.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <algorithm> // for min, tranform
@@ -50,7 +50,7 @@ inline void r_vector<double>::get_region(SEXP x, R_xlen_t i, R_xlen_t n,
5050
typename r_vector::underlying_type* buf) {
5151
// NOPROTECT: likely too costly to unwind protect here
5252
REAL_GET_REGION(x, i, n, buf);
53-
};
53+
}
5454

5555
template <>
5656
inline bool r_vector<double>::const_iterator::use_buf(bool is_altrep) {

inst/include/cpp11/environment.hpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <string> // for string, basic_string
66

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

13-
#if R_VERSION >= R_Version(4, 0, 0)
14-
#define HAS_REMOVE_VAR_FROM_FRAME
15-
#endif
16-
17-
#ifndef HAS_REMOVE_VAR_FROM_FRAME
18-
#include "cpp11/function.hpp"
19-
#endif
20-
2112
namespace cpp11 {
2213

2314
class environment {
@@ -53,12 +44,7 @@ class environment {
5344

5445
void remove(SEXP name) {
5546
PROTECT(name);
56-
#ifdef HAS_REMOVE_VAR_FROM_FRAME
5747
R_removeVarFromFrame(name, env_);
58-
#else
59-
auto remove = package("base")["remove"];
60-
remove(name, "envir"_nm = env_);
61-
#endif
6248
UNPROTECT(1);
6349
}
6450

inst/include/cpp11/external_pointer.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <cstddef> // for nullptr_t, NULL
@@ -57,7 +57,8 @@ class external_pointer {
5757

5858
external_pointer(SEXP data) : data_(valid_type(data)) {}
5959

60-
external_pointer(pointer p, bool use_deleter = true, bool finalize_on_exit = true, SEXP prot = R_NilValue)
60+
external_pointer(pointer p, bool use_deleter = true, bool finalize_on_exit = true,
61+
SEXP prot = R_NilValue)
6162
: data_(safe[R_MakeExternalPtr]((void*)p, R_NilValue, prot)) {
6263
if (use_deleter) {
6364
R_RegisterCFinalizerEx(data_, r_deleter, static_cast<r_bool>(finalize_on_exit));

inst/include/cpp11/function.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <string.h> // for strcmp

inst/include/cpp11/integers.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <algorithm> // for min
@@ -51,7 +51,7 @@ inline void r_vector<int>::get_region(SEXP x, R_xlen_t i, R_xlen_t n,
5151
typename r_vector::underlying_type* buf) {
5252
// NOPROTECT: likely too costly to unwind protect here
5353
INTEGER_GET_REGION(x, i, n, buf);
54-
};
54+
}
5555

5656
template <>
5757
inline bool r_vector<int>::const_iterator::use_buf(bool is_altrep) {

inst/include/cpp11/list.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <initializer_list> // for initializer_list
@@ -54,7 +54,7 @@ template <>
5454
inline void r_vector<SEXP>::get_region(SEXP x, R_xlen_t i, R_xlen_t n,
5555
typename r_vector::underlying_type* buf) {
5656
cpp11::stop("Unreachable!");
57-
};
57+
}
5858

5959
template <>
6060
inline bool r_vector<SEXP>::const_iterator::use_buf(bool is_altrep) {

inst/include/cpp11/list_of.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <string> // for string, basic_string

inst/include/cpp11/logicals.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <algorithm> // for min
@@ -50,7 +50,7 @@ inline void r_vector<r_bool>::get_region(SEXP x, R_xlen_t i, R_xlen_t n,
5050
typename r_vector::underlying_type* buf) {
5151
// NOPROTECT: likely too costly to unwind protect here
5252
LOGICAL_GET_REGION(x, i, n, buf);
53-
};
53+
}
5454

5555
template <>
5656
inline bool r_vector<r_bool>::const_iterator::use_buf(bool is_altrep) {

inst/include/cpp11/matrix.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <iterator>

inst/include/cpp11/named_arg.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <stddef.h> // for size_t

inst/include/cpp11/protect.hpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <csetjmp> // for longjmp, setjmp, jmp_buf
@@ -15,11 +15,11 @@
1515
#include "R_ext/Error.h" // for Rf_error, Rf_warning
1616
#include "R_ext/Print.h" // for REprintf
1717
#include "R_ext/Utils.h" // for R_CheckUserInterrupt
18-
#include "Rversion.h" // for R_VERSION, R_Version
1918

20-
#if defined(R_VERSION) && R_VERSION >= R_Version(3, 5, 0)
19+
// We would like to remove this, since all supported versions of R now support proper
20+
// unwind protect, but some groups rely on it existing, like arrow and systemfonts
21+
// https://github.com/r-lib/cpp11/issues/412
2122
#define HAS_UNWIND_PROTECT
22-
#endif
2323

2424
#ifdef CPP11_USE_FMT
2525
#define FMT_HEADER_ONLY
@@ -33,8 +33,6 @@ class unwind_exception : public std::exception {
3333
unwind_exception(SEXP token_) : token(token_) {}
3434
};
3535

36-
#ifdef HAS_UNWIND_PROTECT
37-
3836
/// Unwind Protection from C longjmp's, like those used in R error handling
3937
///
4038
/// @param code The code to which needs to be protected, as a nullary callable
@@ -97,15 +95,6 @@ unwind_protect(Fun&& code) {
9795
return out;
9896
}
9997

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

111100
template <size_t...>

inst/include/cpp11/r_bool.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <limits> // for numeric_limits

inst/include/cpp11/r_string.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cpp11 version: 0.5.0
2-
// vendored on: 2024-09-24
1+
// cpp11 version: 0.5.1
2+
// vendored on: 2024-12-07
33
#pragma once
44

55
#include <string> // for string, basic_string, operator==

0 commit comments

Comments
 (0)