| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,3 +9,4 @@ cpp11test/src/*.so | |||
| 9 | 9 | compile_flags.txt | |
| 10 | 10 | inst/doc | |
| 11 | 11 | vignettes/*_cache | |
| 12 | + compile_commands.json | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,3 +67,5 @@ is_interactive <- function() { | |||
| 67 | 67 | } | |
| 68 | 68 | interactive() | |
| 69 | 69 | } | |
| 70 | + | ||
| 71 | + `.preserve_list` <- pairlist(NA, NA) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,8 +18,8 @@ | |||
| 18 | 18 | ||
| 19 | 19 | [[cpp11::register]] void protect_one_cpp11_(SEXP x, int n) { | |
| 20 | 20 | for (R_xlen_t i = 0; i < n; ++i) { | |
| 21 | - SEXP p = cpp11::protect_sexp(x); | ||
| 22 | - cpp11::release_protect(p); | ||
| 21 | + SEXP p = cpp11::preserved.insert(x); | ||
| 22 | + cpp11::preserved.release(p); | ||
| 23 | 23 | } | |
| 24 | 24 | } | |
| 25 | 25 | ||
@@ -63,12 +63,12 @@ | |||
| 63 | 63 | [[cpp11::register]] void protect_many_cpp11_(int n) { | |
| 64 | 64 | std::vector<SEXP> res; | |
| 65 | 65 | for (R_xlen_t i = 0; i < n; ++i) { | |
| 66 | - res.push_back(cpp11::protect_sexp(Rf_ScalarInteger(n))); | ||
| 66 | + res.push_back(cpp11::preserved.insert(Rf_ScalarInteger(n))); | ||
| 67 | 67 | } | |
| 68 | 68 | ||
| 69 | 69 | for (R_xlen_t i = n - 1; i >= 0; --i) { | |
| 70 | 70 | SEXP x = res[i]; | |
| 71 | - cpp11::release_protect(x); | ||
| 71 | + cpp11::preserved.release(x); | ||
| 72 | 72 | res.pop_back(); | |
| 73 | 73 | } | |
| 74 | 74 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ context("sexp-C++") { | |||
| 15 | 15 | ||
| 16 | 16 | expect_true(Rf_inherits(out, "data.frame")); | |
| 17 | 17 | } | |
| 18 | + | ||
| 18 | 19 | test_that("scalar constructors work") { | |
| 19 | 20 | using namespace cpp11::literals; | |
| 20 | 21 | cpp11::writable::list out({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,7 +79,7 @@ template <> | |||
| 79 | 79 | inline r_vector<double>::r_vector(std::initializer_list<named_arg> il) | |
| 80 | 80 | : cpp11::r_vector<double>(safe[Rf_allocVector](REALSXP, il.size())), | |
| 81 | 81 | capacity_(il.size()) { | |
| 82 | - protect_ = protect_sexp(data_); | ||
| 82 | + protect_ = preserved.insert(data_); | ||
| 83 | 83 | int n_protected = 0; | |
| 84 | 84 | ||
| 85 | 85 | try { | |
@@ -95,7 +95,7 @@ inline r_vector<double>::r_vector(std::initializer_list<named_arg> il) | |||
| 95 | 95 | UNPROTECT(n_protected); | |
| 96 | 96 | }); | |
| 97 | 97 | } catch (const unwind_exception& e) { | |
| 98 | - release_protect(protect_); | ||
| 98 | + preserved.release(protect_); | ||
| 99 | 99 | UNPROTECT(n_protected); | |
| 100 | 100 | throw e; | |
| 101 | 101 | } | |
@@ -106,8 +106,8 @@ inline void r_vector<double>::reserve(R_xlen_t new_capacity) { | |||
| 106 | 106 | data_ = data_ == R_NilValue ? safe[Rf_allocVector](REALSXP, new_capacity) | |
| 107 | 107 | : safe[Rf_xlengthgets](data_, new_capacity); | |
| 108 | 108 | SEXP old_protect = protect_; | |
| 109 | - protect_ = protect_sexp(data_); | ||
| 110 | - release_protect(old_protect); | ||
| 109 | + protect_ = preserved.insert(data_); | ||
| 110 | + preserved.release(old_protect); | ||
| 111 | 111 | ||
| 112 | 112 | data_p_ = REAL(data_); | |
| 113 | 113 | capacity_ = new_capacity; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | #include "cpp11/as.hpp" // for as_sexp | |
| 10 | 10 | #include "cpp11/attribute_proxy.hpp" // for attribute_proxy | |
| 11 | 11 | #include "cpp11/named_arg.hpp" // for named_arg | |
| 12 | - #include "cpp11/protect.hpp" // for protect_sexp, release_protect | ||
| 12 | + #include "cpp11/protect.hpp" // for preserved | ||
| 13 | 13 | #include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy | |
| 14 | 14 | #include "cpp11/sexp.hpp" // for sexp | |
| 15 | 15 | ||
@@ -83,10 +83,10 @@ inline void r_vector<int>::reserve(R_xlen_t new_capacity) { | |||
| 83 | 83 | SEXP old_protect = protect_; | |
| 84 | 84 | ||
| 85 | 85 | // Protect the new data | |
| 86 | - protect_ = protect_sexp(data_); | ||
| 86 | + protect_ = preserved.insert(data_); | ||
| 87 | 87 | ||
| 88 | 88 | // Release the old protection; | |
| 89 | - release_protect(old_protect); | ||
| 89 | + preserved.release(old_protect); | ||
| 90 | 90 | ||
| 91 | 91 | data_p_ = INTEGER(data_); | |
| 92 | 92 | capacity_ = new_capacity; | |
@@ -96,7 +96,7 @@ template <> | |||
| 96 | 96 | inline r_vector<int>::r_vector(std::initializer_list<named_arg> il) | |
| 97 | 97 | : cpp11::r_vector<int>(safe[Rf_allocVector](INTSXP, il.size())), | |
| 98 | 98 | capacity_(il.size()) { | |
| 99 | - protect_ = protect_sexp(data_); | ||
| 99 | + protect_ = preserved.insert(data_); | ||
| 100 | 100 | int n_protected = 0; | |
| 101 | 101 | ||
| 102 | 102 | try { | |
@@ -112,7 +112,7 @@ inline r_vector<int>::r_vector(std::initializer_list<named_arg> il) | |||
| 112 | 112 | UNPROTECT(n_protected); | |
| 113 | 113 | }); | |
| 114 | 114 | } catch (const unwind_exception& e) { | |
| 115 | - release_protect(protect_); | ||
| 115 | + preserved.release(protect_); | ||
| 116 | 116 | UNPROTECT(n_protected); | |
| 117 | 117 | throw e; | |
| 118 | 118 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | #include "cpp11/R.hpp" // for SEXP, SEXPREC, SET_VECTOR_ELT | |
| 6 | 6 | #include "cpp11/attribute_proxy.hpp" // for attribute_proxy | |
| 7 | 7 | #include "cpp11/named_arg.hpp" // for named_arg | |
| 8 | - #include "cpp11/protect.hpp" // for protect_sexp, release_protect | ||
| 8 | + #include "cpp11/protect.hpp" // for protect_sexp, preserved.release | ||
| 9 | 9 | #include "cpp11/r_string.hpp" // for r_string | |
| 10 | 10 | #include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy | |
| 11 | 11 | #include "cpp11/sexp.hpp" // for sexp | |
@@ -75,7 +75,7 @@ template <> | |||
| 75 | 75 | inline r_vector<SEXP>::r_vector(std::initializer_list<SEXP> il) | |
| 76 | 76 | : cpp11::r_vector<SEXP>(safe[Rf_allocVector](VECSXP, il.size())), | |
| 77 | 77 | capacity_(il.size()) { | |
| 78 | - protect_ = protect_sexp(data_); | ||
| 78 | + protect_ = preserved.insert(data_); | ||
| 79 | 79 | auto it = il.begin(); | |
| 80 | 80 | for (R_xlen_t i = 0; i < capacity_; ++i, ++it) { | |
| 81 | 81 | SET_VECTOR_ELT(data_, i, *it); | |
@@ -86,7 +86,7 @@ template <> | |||
| 86 | 86 | inline r_vector<SEXP>::r_vector(std::initializer_list<named_arg> il) | |
| 87 | 87 | : cpp11::r_vector<SEXP>(safe[Rf_allocVector](VECSXP, il.size())), | |
| 88 | 88 | capacity_(il.size()) { | |
| 89 | - protect_ = protect_sexp(data_); | ||
| 89 | + protect_ = preserved.insert(data_); | ||
| 90 | 90 | int n_protected = 0; | |
| 91 | 91 | ||
| 92 | 92 | try { | |
@@ -102,7 +102,7 @@ inline r_vector<SEXP>::r_vector(std::initializer_list<named_arg> il) | |||
| 102 | 102 | UNPROTECT(n_protected); | |
| 103 | 103 | }); | |
| 104 | 104 | } catch (const unwind_exception& e) { | |
| 105 | - release_protect(protect_); | ||
| 105 | + preserved.release(protect_); | ||
| 106 | 106 | UNPROTECT(n_protected); | |
| 107 | 107 | throw e; | |
| 108 | 108 | } | |
@@ -114,8 +114,8 @@ inline void r_vector<SEXP>::reserve(R_xlen_t new_capacity) { | |||
| 114 | 114 | : safe[Rf_xlengthgets](data_, new_capacity); | |
| 115 | 115 | ||
| 116 | 116 | SEXP old_protect = protect_; | |
| 117 | - protect_ = protect_sexp(data_); | ||
| 118 | - release_protect(old_protect); | ||
| 117 | + protect_ = preserved.insert(data_); | ||
| 118 | + preserved.release(old_protect); | ||
| 119 | 119 | ||
| 120 | 120 | capacity_ = new_capacity; | |
| 121 | 121 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | #include "cpp11/R.hpp" // for Rboolean, SEXP, SEXPREC, Rf_all... | |
| 8 | 8 | #include "cpp11/attribute_proxy.hpp" // for attribute_proxy | |
| 9 | 9 | #include "cpp11/named_arg.hpp" // for named_arg | |
| 10 | - #include "cpp11/protect.hpp" // for protect_sexp, release_protect | ||
| 10 | + #include "cpp11/protect.hpp" // for preserved | ||
| 11 | 11 | #include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy | |
| 12 | 12 | #include "cpp11/sexp.hpp" // for sexp | |
| 13 | 13 | ||
@@ -71,7 +71,7 @@ inline r_vector<Rboolean>::proxy::operator Rboolean() const { | |||
| 71 | 71 | template <> | |
| 72 | 72 | inline r_vector<Rboolean>::r_vector(std::initializer_list<Rboolean> il) | |
| 73 | 73 | : cpp11::r_vector<Rboolean>(Rf_allocVector(LGLSXP, il.size())), capacity_(il.size()) { | |
| 74 | - protect_ = protect_sexp(data_); | ||
| 74 | + protect_ = preserved.insert(data_); | ||
| 75 | 75 | auto it = il.begin(); | |
| 76 | 76 | for (R_xlen_t i = 0; i < capacity_; ++i, ++it) { | |
| 77 | 77 | SET_LOGICAL_ELT(data_, i, *it); | |
@@ -82,7 +82,7 @@ template <> | |||
| 82 | 82 | inline r_vector<Rboolean>::r_vector(std::initializer_list<named_arg> il) | |
| 83 | 83 | : cpp11::r_vector<Rboolean>(safe[Rf_allocVector](LGLSXP, il.size())), | |
| 84 | 84 | capacity_(il.size()) { | |
| 85 | - protect_ = protect_sexp(data_); | ||
| 85 | + protect_ = preserved.insert(data_); | ||
| 86 | 86 | int n_protected = 0; | |
| 87 | 87 | ||
| 88 | 88 | try { | |
@@ -98,7 +98,7 @@ inline r_vector<Rboolean>::r_vector(std::initializer_list<named_arg> il) | |||
| 98 | 98 | UNPROTECT(n_protected); | |
| 99 | 99 | }); | |
| 100 | 100 | } catch (const unwind_exception& e) { | |
| 101 | - release_protect(protect_); | ||
| 101 | + preserved.release(protect_); | ||
| 102 | 102 | UNPROTECT(n_protected); | |
| 103 | 103 | throw e; | |
| 104 | 104 | } | |
@@ -109,9 +109,9 @@ inline void r_vector<Rboolean>::reserve(R_xlen_t new_capacity) { | |||
| 109 | 109 | data_ = data_ == R_NilValue ? safe[Rf_allocVector](LGLSXP, new_capacity) | |
| 110 | 110 | : safe[Rf_xlengthgets](data_, new_capacity); | |
| 111 | 111 | SEXP old_protect = protect_; | |
| 112 | - protect_ = protect_sexp(data_); | ||
| 112 | + protect_ = preserved.insert(data_); | ||
| 113 | 113 | ||
| 114 | - release_protect(old_protect); | ||
| 114 | + preserved.release(old_protect); | ||
| 115 | 115 | ||
| 116 | 116 | data_p_ = reinterpret_cast<Rboolean*>(LOGICAL(data_)); | |
| 117 | 117 | capacity_ = new_capacity; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments