Skip to content

Commit 7a72ec9

Browse files
committed
implement fix for #445
1 parent 05c888b commit 7a72ec9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

inst/include/cpp11/list.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ inline r_vector<SEXP>::r_vector(std::initializer_list<named_arg> il)
7979
: cpp11::r_vector<SEXP>(safe[Rf_allocVector](VECSXP, il.size())),
8080
capacity_(il.size()) {
8181
unwind_protect([&] {
82-
SEXP names = Rf_allocVector(STRSXP, capacity_);
82+
SEXP names;
83+
PROTECT(names = Rf_allocVector(STRSXP, capacity_));
8384
Rf_setAttrib(data_, R_NamesSymbol, names);
8485

8586
auto it = il.begin();
@@ -91,6 +92,8 @@ inline r_vector<SEXP>::r_vector(std::initializer_list<named_arg> il)
9192
SEXP name = Rf_mkCharCE(it->name(), CE_UTF8);
9293
SET_STRING_ELT(names, i, name);
9394
}
95+
96+
UNPROTECT(1);
9497
});
9598
}
9699

inst/include/cpp11/r_vector.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ inline r_vector<T>::r_vector(std::initializer_list<named_arg> il)
865865
}
866866

867867
unwind_protect([&] {
868-
SEXP names = Rf_allocVector(STRSXP, capacity_);
868+
SEXP names;
869+
PROTECT(names = Rf_allocVector(STRSXP, capacity_));
869870
Rf_setAttrib(data_, R_NamesSymbol, names);
870871

871872
auto it = il.begin();
@@ -890,6 +891,8 @@ inline r_vector<T>::r_vector(std::initializer_list<named_arg> il)
890891
SEXP name = Rf_mkCharCE(it->name(), CE_UTF8);
891892
SET_STRING_ELT(names, i, name);
892893
}
894+
895+
UNPROTECT(1);
893896
});
894897
}
895898

0 commit comments

Comments
 (0)