Skip to content

Commit 5eff766

Browse files
authored
Merge branch 'main' into roxygen
2 parents c91f4ef + 1487985 commit 5eff766

31 files changed

+1857
-1503
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
config:
27+
- {os: macos-13, r: 'oldrel'}
2728
- {os: macos-latest, r: 'release'}
2829

2930
- {os: windows-latest, r: 'release'}
3031
# use 4.1 to check with rtools40's older compiler
3132
- {os: windows-latest, r: '4.1'}
3233

3334
# Use older ubuntu to maximise backward compatibility
34-
- {os: ubuntu-20.04, r: 'devel', http-user-agent: 'release'}
35-
- {os: ubuntu-20.04, r: 'release'}
36-
- {os: ubuntu-20.04, r: 'release', custom: 'no-cpp11test'}
37-
- {os: ubuntu-20.04, r: 'oldrel-1'}
38-
- {os: ubuntu-20.04, r: 'oldrel-2'}
39-
- {os: ubuntu-20.04, r: 'oldrel-3'}
40-
- {os: ubuntu-20.04, r: 'oldrel-4'}
35+
- {os: ubuntu-22.04, r: 'devel', http-user-agent: 'release'}
36+
- {os: ubuntu-22.04, r: 'release'}
37+
- {os: ubuntu-22.04, r: 'release', custom: 'no-cpp11test'}
38+
- {os: ubuntu-22.04, r: 'oldrel-1'}
39+
- {os: ubuntu-22.04, r: 'oldrel-2'}
40+
- {os: ubuntu-22.04, r: 'oldrel-3'}
41+
- {os: ubuntu-22.04, r: 'oldrel-4'}
4142

4243
env:
4344
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/format.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ name: format_check
99

1010
jobs:
1111
format_check:
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1313
steps:
1414
- uses: actions/checkout@v2
1515

1616
- name: Install ClangFormat
17-
run: sudo apt-get install -y clang-format-10
17+
run: sudo apt-get install -y clang-format-12
1818

1919
- name: Run ClangFormat
20-
run: make format clang_format=clang-format-10
20+
run: make format clang_format=clang-format-12
2121

2222
- name: Check for a non-empty diff
2323
run: git diff-files -U --exit-code

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: cpp11
22
Title: A C++11 Interface for R's C Interface
3-
Version: 0.5.1.9000
3+
Version: 0.5.2.9000
44
Authors@R:
55
c(
66
person("Davis", "Vaughan", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4777-038X")),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# cpp11 (development version)
22

3+
# cpp11 0.5.2
4+
5+
* Fixed an issue related to `-Wdeprecated-literal-operator` (#447, @andrjohns).
6+
37
# cpp11 0.5.1
48

59
* cpp11 now requires R >=4.0.0, in line with the

R/source.R

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
#' uses 'CXX11' if unset.
1919
#' @param dir The directory to store the generated source files. `tempfile()` is
2020
#' used by default. The directory will be removed if `clean` is `TRUE`.
21+
#' @param local Passed to [dyn.load()]. If `TRUE` (the default) the shared
22+
#' library is loaded with local symbols; if `FALSE` symbols are made global
23+
#' (equivalent to `dyn.load(..., local = FALSE)`), which can be required when
24+
#' other shared objects need to see RTTI/vtable symbols from this library.
25+
#' @note See the unit test that demonstrates this usage at
26+
#' \code{tests/testthat/test-source-local.R} (shows how `local = FALSE` exports
27+
#' the necessary symbols so separate shared objects can link against them).
2128
#' @return For [cpp_source()] and `[cpp_function()]` the results of
2229
#' [dyn.load()] (invisibly). For `[cpp_eval()]` the results of the evaluated
2330
#' expression.
@@ -65,7 +72,7 @@
6572
#' }
6673
#'
6774
#' @export
68-
cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), dir = tempfile()) {
75+
cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), dir = tempfile(), local = TRUE) {
6976
stop_unless_installed(c("brio", "callr", "cli", "decor", "desc", "glue", "tibble", "vctrs"))
7077
if (!missing(file) && !file.exists(file)) {
7178
stop("Can't find `file` at this path:\n", file, "\n", call. = FALSE)
@@ -145,7 +152,7 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
145152
brio::write_lines(r_functions, r_path)
146153
source(r_path, local = env)
147154

148-
dyn.load(shared_lib, local = TRUE, now = TRUE)
155+
dyn.load(shared_lib, local = local, now = TRUE)
149156
}
150157

151158
the <- new.env(parent = emptyenv())
@@ -183,7 +190,7 @@ generate_makevars <- function(includes, cxx_std) {
183190

184191
#' @rdname cpp_source
185192
#' @export
186-
cpp_function <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11")) {
193+
cpp_function <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), local = TRUE) {
187194
cpp_source(code = paste(c('#include "cpp11.hpp"',
188195
"using namespace ::cpp11;",
189196
"namespace writable = ::cpp11::writable;",
@@ -193,15 +200,16 @@ cpp_function <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE,
193200
env = env,
194201
clean = clean,
195202
quiet = quiet,
196-
cxx_std = cxx_std
203+
cxx_std = cxx_std,
204+
local = local
197205
)
198206
}
199207

200208
utils::globalVariables("f")
201209

202210
#' @rdname cpp_source
203211
#' @export
204-
cpp_eval <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11")) {
212+
cpp_eval <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), local = TRUE) {
205213
cpp_source(code = paste(c('#include "cpp11.hpp"',
206214
"using namespace ::cpp11;",
207215
"namespace writable = ::cpp11::writable;",
@@ -214,7 +222,8 @@ cpp_eval <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx
214222
env = env,
215223
clean = clean,
216224
quiet = quiet,
217-
cxx_std = cxx_std
225+
cxx_std = cxx_std,
226+
local = local
218227
)
219228
f()
220229
}

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,13 @@ Please note that the cpp11 project is released with a [Contributor Code of Condu
7878

7979
cpp11 would not exist without Rcpp.
8080
Thanks to the Rcpp authors, Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou, Nathan Russell, Douglas Bates and John Chambers for their work writing and maintaining Rcpp.
81+
82+
## Clang format
83+
84+
To match GHA, use clang-format-12 to format C++ code. With systems that provide clang-format-14 or newer, you can use Docker:
85+
86+
```bash
87+
docker run --rm -v "$PWD":/work -w /work ubuntu:22.04 bash -lc "\
88+
apt-get update && apt-get install -y clang-format-12 && \
89+
find . -name '*.cpp' -o -name '*.hpp' -o -name '*.h' | xargs -r clang-format-12 -i"
90+
```

cpp11test/R/cpp11.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,26 @@ string_push_back_ <- function() {
225225
.Call(`_cpp11test_string_push_back_`)
226226
}
227227

228+
grow_strings_cpp11_ <- function(n, seed) {
229+
.Call(`_cpp11test_grow_strings_cpp11_`, n, seed)
230+
}
231+
232+
grow_strings_rcpp_ <- function(n, seed) {
233+
.Call(`_cpp11test_grow_strings_rcpp_`, n, seed)
234+
}
235+
236+
grow_strings_manual_ <- function(n, seed) {
237+
.Call(`_cpp11test_grow_strings_manual_`, n, seed)
238+
}
239+
240+
assign_cpp11_ <- function(n, seed) {
241+
.Call(`_cpp11test_assign_cpp11_`, n, seed)
242+
}
243+
244+
assign_rcpp_ <- function(n, seed) {
245+
.Call(`_cpp11test_assign_rcpp_`, n, seed)
246+
}
247+
228248
sum_dbl_for_ <- function(x) {
229249
.Call(`_cpp11test_sum_dbl_for_`, x)
230250
}
@@ -293,6 +313,14 @@ rcpp_push_and_truncate_ <- function(size_sxp) {
293313
.Call(`_cpp11test_rcpp_push_and_truncate_`, size_sxp)
294314
}
295315

316+
nullable_extptr_1 <- function() {
317+
.Call(`_cpp11test_nullable_extptr_1`)
318+
}
319+
320+
nullable_extptr_2 <- function() {
321+
.Call(`_cpp11test_nullable_extptr_2`)
322+
}
323+
296324
test_destruction_inner <- function() {
297325
invisible(.Call(`_cpp11test_test_destruction_inner`))
298326
}

cpp11test/bench/strings.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
pkgload::load_all("cpp11test")
2+
3+
bench::press(len = as.integer(10^(0:6)), {
4+
bench::mark(
5+
assign_cpp11_(n = len, 123L),
6+
assign_rcpp_(n = len, 123L),
7+
iterations = 20
8+
)
9+
})[c("expression", "len", "min", "mem_alloc", "n_itr", "n_gc")]
10+
11+
# Longer benchmark, lots of gc
12+
len <- as.integer(10^7)
13+
bench::mark(
14+
cpp11 = cpp11_push_and_truncate_(len),
15+
rcpp = rcpp_push_and_truncate_(len),
16+
min_iterations = 200
17+
)[c("expression", "min", "mem_alloc", "n_itr", "n_gc")]
18+
19+
bench::press(len = as.integer(10^(0:6)), {
20+
bench::mark(
21+
grow_strings_cpp11_(len, 123L),
22+
grow_strings_rcpp_(len, 123L),
23+
grow_strings_manual_(len, 123L),
24+
iterations = 20
25+
)
26+
})[c("expression", "len", "min", "mem_alloc", "n_itr", "n_gc")]
27+
28+
# Longer benchmark, lots of gc
29+
len <- as.integer(10^7)
30+
bench::mark(
31+
cpp11 = cpp11_grow_strings_(len),
32+
rcpp = rcpp_grow_strings_(len),
33+
manual = manual_grow_strings_(len),
34+
min_iterations = 200
35+
)[c("expression", "min", "mem_alloc", "n_itr", "n_gc")]

cpp11test/src/cpp11.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,41 @@ extern "C" SEXP _cpp11test_string_push_back_() {
373373
return cpp11::as_sexp(string_push_back_());
374374
END_CPP11
375375
}
376+
// strings.cpp
377+
cpp11::strings grow_strings_cpp11_(size_t n, int seed);
378+
extern "C" SEXP _cpp11test_grow_strings_cpp11_(SEXP n, SEXP seed) {
379+
BEGIN_CPP11
380+
return cpp11::as_sexp(grow_strings_cpp11_(cpp11::as_cpp<cpp11::decay_t<size_t>>(n), cpp11::as_cpp<cpp11::decay_t<int>>(seed)));
381+
END_CPP11
382+
}
383+
// strings.cpp
384+
Rcpp::CharacterVector grow_strings_rcpp_(size_t n, int seed);
385+
extern "C" SEXP _cpp11test_grow_strings_rcpp_(SEXP n, SEXP seed) {
386+
BEGIN_CPP11
387+
return cpp11::as_sexp(grow_strings_rcpp_(cpp11::as_cpp<cpp11::decay_t<size_t>>(n), cpp11::as_cpp<cpp11::decay_t<int>>(seed)));
388+
END_CPP11
389+
}
390+
// strings.cpp
391+
SEXP grow_strings_manual_(size_t n, int seed);
392+
extern "C" SEXP _cpp11test_grow_strings_manual_(SEXP n, SEXP seed) {
393+
BEGIN_CPP11
394+
return cpp11::as_sexp(grow_strings_manual_(cpp11::as_cpp<cpp11::decay_t<size_t>>(n), cpp11::as_cpp<cpp11::decay_t<int>>(seed)));
395+
END_CPP11
396+
}
397+
// strings.cpp
398+
cpp11::strings assign_cpp11_(size_t n, int seed);
399+
extern "C" SEXP _cpp11test_assign_cpp11_(SEXP n, SEXP seed) {
400+
BEGIN_CPP11
401+
return cpp11::as_sexp(assign_cpp11_(cpp11::as_cpp<cpp11::decay_t<size_t>>(n), cpp11::as_cpp<cpp11::decay_t<int>>(seed)));
402+
END_CPP11
403+
}
404+
// strings.cpp
405+
Rcpp::CharacterVector assign_rcpp_(size_t n, int seed);
406+
extern "C" SEXP _cpp11test_assign_rcpp_(SEXP n, SEXP seed) {
407+
BEGIN_CPP11
408+
return cpp11::as_sexp(assign_rcpp_(cpp11::as_cpp<cpp11::decay_t<size_t>>(n), cpp11::as_cpp<cpp11::decay_t<int>>(seed)));
409+
END_CPP11
410+
}
376411
// sum.cpp
377412
double sum_dbl_for_(cpp11::doubles x);
378413
extern "C" SEXP _cpp11test_sum_dbl_for_(SEXP x) {
@@ -492,6 +527,20 @@ extern "C" SEXP _cpp11test_rcpp_push_and_truncate_(SEXP size_sxp) {
492527
return cpp11::as_sexp(rcpp_push_and_truncate_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(size_sxp)));
493528
END_CPP11
494529
}
530+
// test-external_pointer.cpp
531+
cpp11::external_pointer<int> nullable_extptr_1();
532+
extern "C" SEXP _cpp11test_nullable_extptr_1() {
533+
BEGIN_CPP11
534+
return cpp11::as_sexp(nullable_extptr_1());
535+
END_CPP11
536+
}
537+
// test-external_pointer.cpp
538+
cpp11::external_pointer<int> nullable_extptr_2();
539+
extern "C" SEXP _cpp11test_nullable_extptr_2() {
540+
BEGIN_CPP11
541+
return cpp11::as_sexp(nullable_extptr_2());
542+
END_CPP11
543+
}
495544
// test-protect-nested.cpp
496545
void test_destruction_inner();
497546
extern "C" SEXP _cpp11test_test_destruction_inner() {
@@ -521,6 +570,8 @@ extern "C" {
521570
extern SEXP run_testthat_tests(SEXP);
522571

523572
static const R_CallMethodDef CallEntries[] = {
573+
{"_cpp11test_assign_cpp11_", (DL_FUNC) &_cpp11test_assign_cpp11_, 2},
574+
{"_cpp11test_assign_rcpp_", (DL_FUNC) &_cpp11test_assign_rcpp_, 2},
524575
{"_cpp11test_col_sums", (DL_FUNC) &_cpp11test_col_sums, 1},
525576
{"_cpp11test_cpp11_add_vec_for_", (DL_FUNC) &_cpp11test_cpp11_add_vec_for_, 2},
526577
{"_cpp11test_cpp11_insert_", (DL_FUNC) &_cpp11test_cpp11_insert_, 1},
@@ -537,6 +588,9 @@ static const R_CallMethodDef CallEntries[] = {
537588
{"_cpp11test_gibbs_rcpp", (DL_FUNC) &_cpp11test_gibbs_rcpp, 2},
538589
{"_cpp11test_gibbs_rcpp2", (DL_FUNC) &_cpp11test_gibbs_rcpp2, 2},
539590
{"_cpp11test_grow_", (DL_FUNC) &_cpp11test_grow_, 1},
591+
{"_cpp11test_grow_strings_cpp11_", (DL_FUNC) &_cpp11test_grow_strings_cpp11_, 2},
592+
{"_cpp11test_grow_strings_manual_", (DL_FUNC) &_cpp11test_grow_strings_manual_, 2},
593+
{"_cpp11test_grow_strings_rcpp_", (DL_FUNC) &_cpp11test_grow_strings_rcpp_, 2},
540594
{"_cpp11test_my_message", (DL_FUNC) &_cpp11test_my_message, 2},
541595
{"_cpp11test_my_message_n1", (DL_FUNC) &_cpp11test_my_message_n1, 1},
542596
{"_cpp11test_my_message_n1fmt", (DL_FUNC) &_cpp11test_my_message_n1fmt, 1},
@@ -549,8 +603,8 @@ static const R_CallMethodDef CallEntries[] = {
549603
{"_cpp11test_my_warning_n1", (DL_FUNC) &_cpp11test_my_warning_n1, 1},
550604
{"_cpp11test_my_warning_n1fmt", (DL_FUNC) &_cpp11test_my_warning_n1fmt, 1},
551605
{"_cpp11test_my_warning_n2fmt", (DL_FUNC) &_cpp11test_my_warning_n2fmt, 2},
552-
{"_cpp11test_notroxcpp1_", (DL_FUNC) &_cpp11test_notroxcpp1_, 1},
553-
{"_cpp11test_notroxcpp6_", (DL_FUNC) &_cpp11test_notroxcpp6_, 1},
606+
{"_cpp11test_nullable_extptr_1", (DL_FUNC) &_cpp11test_nullable_extptr_1, 0},
607+
{"_cpp11test_nullable_extptr_2", (DL_FUNC) &_cpp11test_nullable_extptr_2, 0},
554608
{"_cpp11test_protect_many_", (DL_FUNC) &_cpp11test_protect_many_, 1},
555609
{"_cpp11test_protect_many_cpp11_", (DL_FUNC) &_cpp11test_protect_many_cpp11_, 1},
556610
{"_cpp11test_protect_many_preserve_", (DL_FUNC) &_cpp11test_protect_many_preserve_, 1},

0 commit comments

Comments
 (0)