Skip to content

Commit a23f6af

Browse files
committed
Be more conservative when protecting attribute setters
Was running into protect errors with gctorture() otherwise
1 parent 3e74cdd commit a23f6af

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

inst/include/cpp11/attribute_proxy.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ class attribute_proxy {
2626

2727
template <typename C>
2828
attribute_proxy& operator=(C rhs) {
29-
// NOPROTECT: Rf_setAttrib with a SYMSXP does not allocate
30-
Rf_setAttrib(parent_.data(), symbol_, as_sexp(rhs));
29+
SEXP value = PROTECT(as_sexp(rhs));
30+
Rf_setAttrib(parent_.data(), symbol_, value);
31+
UNPROTECT(1);
3132
return *this;
3233
}
3334

3435
template <typename C>
3536
attribute_proxy& operator=(std::initializer_list<C> rhs) {
36-
// NOPROTECT: Rf_setAttrib with a SYMSXP does not allocate
37-
Rf_setAttrib(parent_.data(), symbol_, as_sexp(rhs));
37+
SEXP value = PROTECT(as_sexp(rhs));
38+
Rf_setAttrib(parent_.data(), symbol_, value);
39+
UNPROTECT(1);
3840
return *this;
3941
}
4042

0 commit comments

Comments
 (0)