Skip to content

Commit f023d77

Browse files
authored
A little refactoring a clean up of sexp.hpp (#385)
1 parent c86ab3f commit f023d77

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

inst/include/cpp11/sexp.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,33 @@ class sexp {
1919
public:
2020
sexp() = default;
2121

22-
sexp(SEXP data) : data_(data), preserve_token_(detail::store::insert(data_)) {
23-
// REprintf("created %p %p\n", reinterpret_cast<void*>(data_),
24-
// reinterpret_cast<void*>(preserve_token_));
25-
}
22+
sexp(SEXP data) : data_(data), preserve_token_(detail::store::insert(data_)) {}
2623

24+
// We maintain our own new `preserve_token_`
2725
sexp(const sexp& rhs) {
2826
data_ = rhs.data_;
2927
preserve_token_ = detail::store::insert(data_);
30-
// REprintf("copied %p new protect %p\n", reinterpret_cast<void*>(rhs.data_),
31-
// reinterpret_cast<void*>(preserve_token_));
3228
}
3329

30+
// We take ownership over the `rhs.preserve_token_`.
31+
// Importantly we clear it in the `rhs` so it can't release the object upon destruction.
3432
sexp(sexp&& rhs) {
3533
data_ = rhs.data_;
3634
preserve_token_ = rhs.preserve_token_;
3735

3836
rhs.data_ = R_NilValue;
3937
rhs.preserve_token_ = R_NilValue;
40-
41-
// REprintf("moved %p\n", reinterpret_cast<void*>(rhs.data_));
4238
}
4339

4440
sexp& operator=(const sexp& rhs) {
4541
detail::store::release(preserve_token_);
4642

4743
data_ = rhs.data_;
4844
preserve_token_ = detail::store::insert(data_);
49-
// REprintf("assigned %p\n", reinterpret_cast<void*>(rhs.data_));
45+
5046
return *this;
5147
}
5248

53-
// void swap(sexp& rhs) {
54-
// sexp tmp(rhs);
55-
// rhs = *this;
56-
//*this = tmp;
57-
//}
58-
5949
~sexp() { detail::store::release(preserve_token_); }
6050

6151
attribute_proxy<sexp> attr(const char* name) const {

0 commit comments

Comments
 (0)