Skip to content

Commit

Permalink
HACK: just define preserve_list in the global env
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Aug 16, 2020
1 parent e3aa704 commit 7a266de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions inst/include/cpp11/protect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,18 @@ static struct {
// The .preserve_list singleton is a member of cpp11::: and is managed by the R
// runtime. It cannot be constructed a header since many translation units may be
// compiled, resulting in unrelated instances of each static variable.
SEXP ns = safe[Rf_findVarInFrame](R_NamespaceRegistry, safe[Rf_install]("cpp11"));
list_singleton = safe[Rf_findVar](safe[Rf_install](".preserve_list"), ns);

// FIXME how can we create the cpp11 namespace when it doesn't already exist?
SEXP list_singleton_sym = safe[Rf_install](".cpp11_preserve_list");

list_singleton = safe[Rf_findVarInFrame](R_GlobalEnv, list_singleton_sym);

if (list_singleton == R_UnboundValue) {
list_singleton = PROTECT(Rf_cons(R_NilValue, R_NilValue));
R_PreserveObject(list_singleton);
UNPROTECT(1);
safe[Rf_defineVar](list_singleton_sym, list_singleton, R_GlobalEnv);
}
}

return list_singleton;
Expand Down
4 changes: 3 additions & 1 deletion inst/include/cpp11/r_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,9 @@ inline r_vector<T>::r_vector(const r_vector<T>& rhs)

template <typename T>
inline r_vector<T>::r_vector(r_vector<T>&& rhs)
: cpp11::r_vector<T>(rhs), protect_(preserved.insert(data_)), capacity_(rhs.capacity_) {
: cpp11::r_vector<T>(rhs),
protect_(preserved.insert(data_)),
capacity_(rhs.capacity_) {
rhs.data_ = R_NilValue;
rhs.protect_ = R_NilValue;
}
Expand Down

0 comments on commit 7a266de

Please sign in to comment.