@@ -19,43 +19,33 @@ class sexp {
19
19
public:
20
20
sexp () = default ;
21
21
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_)) {}
26
23
24
+ // We maintain our own new `preserve_token_`
27
25
sexp (const sexp& rhs) {
28
26
data_ = rhs.data_ ;
29
27
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_));
32
28
}
33
29
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.
34
32
sexp (sexp&& rhs) {
35
33
data_ = rhs.data_ ;
36
34
preserve_token_ = rhs.preserve_token_ ;
37
35
38
36
rhs.data_ = R_NilValue;
39
37
rhs.preserve_token_ = R_NilValue;
40
-
41
- // REprintf("moved %p\n", reinterpret_cast<void*>(rhs.data_));
42
38
}
43
39
44
40
sexp& operator =(const sexp& rhs) {
45
41
detail::store::release (preserve_token_);
46
42
47
43
data_ = rhs.data_ ;
48
44
preserve_token_ = detail::store::insert (data_);
49
- // REprintf("assigned %p\n", reinterpret_cast<void*>(rhs.data_));
45
+
50
46
return *this ;
51
47
}
52
48
53
- // void swap(sexp& rhs) {
54
- // sexp tmp(rhs);
55
- // rhs = *this;
56
- // *this = tmp;
57
- // }
58
-
59
49
~sexp () { detail::store::release (preserve_token_); }
60
50
61
51
attribute_proxy<sexp> attr (const char * name) const {
0 commit comments