Skip to content

Commit 7a266de

Browse files
committed
HACK: just define preserve_list in the global env
1 parent e3aa704 commit 7a266de

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

inst/include/cpp11/protect.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,18 @@ static struct {
288288
// The .preserve_list singleton is a member of cpp11::: and is managed by the R
289289
// runtime. It cannot be constructed a header since many translation units may be
290290
// compiled, resulting in unrelated instances of each static variable.
291-
SEXP ns = safe[Rf_findVarInFrame](R_NamespaceRegistry, safe[Rf_install]("cpp11"));
292-
list_singleton = safe[Rf_findVar](safe[Rf_install](".preserve_list"), ns);
291+
292+
// FIXME how can we create the cpp11 namespace when it doesn't already exist?
293+
SEXP list_singleton_sym = safe[Rf_install](".cpp11_preserve_list");
294+
295+
list_singleton = safe[Rf_findVarInFrame](R_GlobalEnv, list_singleton_sym);
296+
297+
if (list_singleton == R_UnboundValue) {
298+
list_singleton = PROTECT(Rf_cons(R_NilValue, R_NilValue));
299+
R_PreserveObject(list_singleton);
300+
UNPROTECT(1);
301+
safe[Rf_defineVar](list_singleton_sym, list_singleton, R_GlobalEnv);
302+
}
293303
}
294304

295305
return list_singleton;

inst/include/cpp11/r_vector.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,9 @@ inline r_vector<T>::r_vector(const r_vector<T>& rhs)
766766

767767
template <typename T>
768768
inline r_vector<T>::r_vector(r_vector<T>&& rhs)
769-
: cpp11::r_vector<T>(rhs), protect_(preserved.insert(data_)), capacity_(rhs.capacity_) {
769+
: cpp11::r_vector<T>(rhs),
770+
protect_(preserved.insert(data_)),
771+
capacity_(rhs.capacity_) {
770772
rhs.data_ = R_NilValue;
771773
rhs.protect_ = R_NilValue;
772774
}

0 commit comments

Comments
 (0)