Skip to content

Commit 642f1bd

Browse files
authored
Merge pull request #1135 from RcppCore/feature/preserve_interface
maintain existing interface and offer new one
2 parents 4ed72aa + 0dedb16 commit 642f1bd

File tree

7 files changed

+92
-62
lines changed

7 files changed

+92
-62
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2021-01-19 Dirk Eddelbuettel <[email protected]>
2+
3+
* DESCRIPTION (Version, Date): Roll minor version
4+
* inst/include/Rcpp/config.h: Idem
5+
6+
* inst/include/RcppCommon.h: Preverse existing API and offer new
7+
token-based API alongside via Rcpp_Precious{Preserve,Release}
8+
* inst/include/Rcpp/String.h: Use Rcpp_Precious{Preserve,Release}
9+
* inst/include/Rcpp/storage/PreserveStorage.h: Ditto
10+
111
2021-01-17 Iñaki Ucar <[email protected]>
212

313
* inst/include/Rcpp/String.h: Use Rcpp_{Preserve,Release}Object

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 1.0.6.2
4-
Date: 2021-01-17
3+
Version: 1.0.6.3
4+
Date: 2021-01-19
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
66
Nathan Russell, Douglas Bates and John Chambers
77
Maintainer: Dirk Eddelbuettel <[email protected]>

inst/include/Rcpp/String.h

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ namespace Rcpp {
5353

5454
/** default constructor */
5555
String(): data(Rf_mkCharCE("", CE_UTF8)), token(R_NilValue), buffer(), valid(true), buffer_ready(true), enc(CE_UTF8) {
56-
token = Rcpp_PreserveObject(data);
56+
token = Rcpp_PreciousPreserve(data);
5757
RCPP_STRING_DEBUG("String()");
5858
}
5959

6060
/** copy constructor */
6161
String(const String& other) : data(other.get_sexp()), token(R_NilValue), valid(true), buffer_ready(false), enc(Rf_getCharCE(other.get_sexp())) {
62-
token = Rcpp_PreserveObject(data);
62+
token = Rcpp_PreciousPreserve(data);
6363
RCPP_STRING_DEBUG("String(const String&)");
6464
}
6565

@@ -82,30 +82,30 @@ namespace Rcpp {
8282
valid = true;
8383
buffer_ready = false;
8484
enc = Rf_getCharCE(data);
85-
token = Rcpp_PreserveObject(data);
85+
token = Rcpp_PreciousPreserve(data);
8686
RCPP_STRING_DEBUG("String(SEXP)");
8787
}
8888

8989
/** from string proxy */
9090
String(const StringProxy& proxy): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())) {
91-
token = Rcpp_PreserveObject(data);
91+
token = Rcpp_PreciousPreserve(data);
9292
RCPP_STRING_DEBUG("String(const StringProxy&)");
9393
}
9494

9595
String(const StringProxy& proxy, cetype_t enc): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false) {
96-
token = Rcpp_PreserveObject(data);
96+
token = Rcpp_PreciousPreserve(data);
9797
set_encoding(enc);
9898
RCPP_STRING_DEBUG("String(const StringProxy&, cetype_t)");
9999
}
100100

101101
/** from string proxy */
102102
String(const const_StringProxy& proxy): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())) {
103-
token = Rcpp_PreserveObject(data);
103+
token = Rcpp_PreciousPreserve(data);
104104
RCPP_STRING_DEBUG("String(const const_StringProxy&)");
105105
}
106106

107107
String(const const_StringProxy& proxy, cetype_t enc): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false) {
108-
token = Rcpp_PreserveObject(data);
108+
token = Rcpp_PreciousPreserve(data);
109109
set_encoding(enc);
110110
RCPP_STRING_DEBUG("String(const const_StringProxy&, cetype_t)");
111111
}
@@ -118,7 +118,7 @@ namespace Rcpp {
118118
}
119119

120120
String(const std::wstring& s, cetype_t enc = CE_UTF8) : data(internal::make_charsexp(s)), token(R_NilValue), valid(true), buffer_ready(false), enc(enc) {
121-
token = Rcpp_PreserveObject(data);
121+
token = Rcpp_PreciousPreserve(data);
122122
RCPP_STRING_DEBUG("String(const std::wstring&, cetype_t)");
123123
}
124124

@@ -130,79 +130,79 @@ namespace Rcpp {
130130
}
131131

132132
String(const wchar_t* s, cetype_t enc = CE_UTF8) : data(internal::make_charsexp(s)), token(R_NilValue), valid(true), buffer_ready(false), enc(enc) {
133-
token = Rcpp_PreserveObject(data);
133+
token = Rcpp_PreciousPreserve(data);
134134
RCPP_STRING_DEBUG("String(const wchar_t* s, cetype_t)");
135135
}
136136

137137
/** constructors from R primitives */
138138
String(int x) : data(internal::r_coerce<INTSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
139-
token = Rcpp_PreserveObject(data);
139+
token = Rcpp_PreciousPreserve(data);
140140
}
141141
String(double x) : data(internal::r_coerce<REALSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
142-
token = Rcpp_PreserveObject(data);
142+
token = Rcpp_PreciousPreserve(data);
143143
}
144144
String(bool x) : data(internal::r_coerce<LGLSXP,STRSXP>(x)), token(R_NilValue), valid(true) , buffer_ready(false), enc(CE_UTF8) {
145-
token = Rcpp_PreserveObject(data);
145+
token = Rcpp_PreciousPreserve(data);
146146
}
147147
String(Rcomplex x) : data(internal::r_coerce<CPLXSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
148-
token = Rcpp_PreserveObject(data);
148+
token = Rcpp_PreciousPreserve(data);
149149
}
150150
String(Rbyte x) : data(internal::r_coerce<RAWSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
151-
token = Rcpp_PreserveObject(data);
151+
token = Rcpp_PreciousPreserve(data);
152152
}
153153

154154
~String() {
155-
Rcpp_ReleaseObject(token);
155+
Rcpp_PreciousRelease(token);
156156
data = R_NilValue;
157157
token = R_NilValue;
158158
}
159159

160160

161161
inline String& operator=(int x) {
162162
data = internal::r_coerce<INTSXP, STRSXP>(x);
163-
Rcpp_ReleaseObject(token);
164-
token = Rcpp_PreserveObject(data);
163+
Rcpp_PreciousRelease(token);
164+
token = Rcpp_PreciousPreserve(data);
165165
valid = true;
166166
buffer_ready = false;
167167
return *this;
168168
}
169169
inline String& operator=(double x) {
170170
data = internal::r_coerce<REALSXP, STRSXP>(x);
171-
Rcpp_ReleaseObject(token);
172-
token = Rcpp_PreserveObject(data);
171+
Rcpp_PreciousRelease(token);
172+
token = Rcpp_PreciousPreserve(data);
173173
valid = true;
174174
buffer_ready = false;
175175
return *this;
176176
}
177177
inline String& operator=(Rbyte x) {
178178
data = internal::r_coerce<RAWSXP, STRSXP>(x);
179-
Rcpp_ReleaseObject(token);
180-
token = Rcpp_PreserveObject(data);
179+
Rcpp_PreciousRelease(token);
180+
token = Rcpp_PreciousPreserve(data);
181181
valid = true;
182182
buffer_ready = false;
183183
return *this;
184184
}
185185
inline String& operator=(bool x) {
186186
data = internal::r_coerce<LGLSXP, STRSXP>(x);
187-
Rcpp_ReleaseObject(token);
188-
token = Rcpp_PreserveObject(data);
187+
Rcpp_PreciousRelease(token);
188+
token = Rcpp_PreciousPreserve(data);
189189
valid = true;
190190
buffer_ready = false;
191191
return *this;
192192
}
193193
inline String& operator=(Rcomplex x) {
194194
data = internal::r_coerce<CPLXSXP, STRSXP>(x);
195-
Rcpp_ReleaseObject(token);
196-
token = Rcpp_PreserveObject(data);
195+
Rcpp_PreciousRelease(token);
196+
token = Rcpp_PreciousPreserve(data);
197197
valid = true;
198198
buffer_ready = false;
199199
return *this;
200200
}
201201
inline String& operator=(SEXP x) {
202202
if (data != x) {
203203
data = x;
204-
Rcpp_ReleaseObject(token);
205-
token = Rcpp_PreserveObject(data);
204+
Rcpp_PreciousRelease(token);
205+
token = Rcpp_PreciousPreserve(data);
206206
}
207207
valid = true;
208208
buffer_ready = false;
@@ -212,8 +212,8 @@ namespace Rcpp {
212212
SEXP x = proxy.get();
213213
if (data != x) {
214214
data = x;
215-
Rcpp_ReleaseObject(token);
216-
token = Rcpp_PreserveObject(x);
215+
Rcpp_PreciousRelease(token);
216+
token = Rcpp_PreciousPreserve(x);
217217
}
218218
valid = true;
219219
buffer_ready = false;
@@ -223,8 +223,8 @@ namespace Rcpp {
223223
SEXP x = other.get_sexp();
224224
if (data != x) {
225225
data = x;
226-
Rcpp_ReleaseObject(token);
227-
token = Rcpp_PreserveObject(x);
226+
Rcpp_PreciousRelease(token);
227+
token = Rcpp_PreciousPreserve(x);
228228
}
229229
valid = true;
230230
buffer_ready = false;
@@ -247,8 +247,8 @@ namespace Rcpp {
247247
template <typename T>
248248
inline String& assign_wide_string(const T& s) {
249249
data = internal::make_charsexp(s);
250-
Rcpp_ReleaseObject(token);
251-
token = Rcpp_PreserveObject(data);
250+
Rcpp_PreciousRelease(token);
251+
token = Rcpp_PreciousPreserve(data);
252252
valid = true;
253253
buffer_ready = false;
254254
return *this;
@@ -281,8 +281,8 @@ namespace Rcpp {
281281
std::wstring tmp(buf, buf + strlen(buf));
282282
tmp += s;
283283
data = internal::make_charsexp(tmp);
284-
Rcpp_ReleaseObject(token);
285-
token = Rcpp_PreserveObject(data);
284+
Rcpp_PreciousRelease(token);
285+
token = Rcpp_PreciousPreserve(data);
286286
valid = true;
287287
buffer_ready = false;
288288
return *this;
@@ -298,8 +298,8 @@ namespace Rcpp {
298298
if (is_na()) return *this;
299299
if (other.is_na()) {
300300
data = NA_STRING;
301-
Rcpp_ReleaseObject(token);
302-
token = Rcpp_PreserveObject(data);
301+
Rcpp_PreciousRelease(token);
302+
token = Rcpp_PreciousPreserve(data);
303303
valid = true;
304304
buffer_ready = false;
305305
return *this;
@@ -313,8 +313,8 @@ namespace Rcpp {
313313
SEXP proxy_sexp = proxy;
314314
if (proxy_sexp == NA_STRING) {
315315
data = NA_STRING;
316-
Rcpp_ReleaseObject(token);
317-
token = Rcpp_PreserveObject(data);
316+
Rcpp_PreciousRelease(token);
317+
token = Rcpp_PreciousPreserve(data);
318318
valid = true;
319319
buffer_ready = false;
320320
return *this;
@@ -328,8 +328,8 @@ namespace Rcpp {
328328
SEXP proxy_sexp = proxy;
329329
if (proxy_sexp == NA_STRING) {
330330
data = NA_STRING;
331-
Rcpp_ReleaseObject(token);
332-
token = Rcpp_PreserveObject(data);
331+
Rcpp_PreciousRelease(token);
332+
token = Rcpp_PreciousPreserve(data);
333333
valid = true;
334334
buffer_ready = false;
335335
return *this;
@@ -342,8 +342,8 @@ namespace Rcpp {
342342
if (is_na()) return *this;
343343
if (x == NA_STRING) {
344344
data = NA_STRING;
345-
Rcpp_ReleaseObject(token);
346-
token = Rcpp_PreserveObject(data);
345+
Rcpp_PreciousRelease(token);
346+
token = Rcpp_PreciousPreserve(data);
347347
valid = true;
348348
buffer_ready = false;
349349
return *this;
@@ -479,8 +479,8 @@ namespace Rcpp {
479479

480480
inline void set_na() {
481481
data = NA_STRING;
482-
Rcpp_ReleaseObject(token);
483-
token = Rcpp_PreserveObject(data);
482+
Rcpp_PreciousRelease(token);
483+
token = Rcpp_PreciousPreserve(data);
484484
valid = true;
485485
buffer_ready = false;
486486
}
@@ -533,11 +533,11 @@ namespace Rcpp {
533533
// TODO: may longjmp on failure to translate?
534534
const char* translated = Rf_translateCharUTF8(data);
535535
data = Rf_mkCharCE(translated, encoding);
536-
Rcpp_ReleaseObject(token);
537-
token = Rcpp_PreserveObject(data);
536+
Rcpp_PreciousRelease(token);
537+
token = Rcpp_PreciousPreserve(data);
538538
} else {
539539
data = get_sexp_impl();
540-
token = Rcpp_PreserveObject(data);
540+
token = Rcpp_PreciousPreserve(data);
541541
valid = true;
542542
}
543543
}
@@ -610,7 +610,7 @@ namespace Rcpp {
610610
RCPP_STRING_DEBUG("setData");
611611
if (!valid) {
612612
data = get_sexp_impl();
613-
token = Rcpp_PreserveObject(data);
613+
token = Rcpp_PreciousPreserve(data);
614614
valid = true;
615615
}
616616
}

inst/include/Rcpp/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define RCPP_VERSION_STRING "1.0.6"
3131

3232
// the current source snapshot
33-
#define RCPP_DEV_VERSION RcppDevVersion(1,0,6,2)
34-
#define RCPP_DEV_VERSION_STRING "1.0.6.2"
33+
#define RCPP_DEV_VERSION RcppDevVersion(1,0,6,3)
34+
#define RCPP_DEV_VERSION_STRING "1.0.6.3"
3535

3636
#endif

inst/include/Rcpp/storage/PreserveStorage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ namespace Rcpp{
3131
PreserveStorage() : data(R_NilValue), token(R_NilValue){}
3232

3333
~PreserveStorage(){
34-
Rcpp_ReleaseObject(token) ;
34+
Rcpp_PreciousRelease(token) ;
3535
data = R_NilValue;
3636
token = R_NilValue;
3737
}
3838

3939
inline void set__(SEXP x){
4040
if (data != x) {
4141
data = x;
42-
Rcpp_ReleaseObject(token);
43-
token = Rcpp_PreserveObject(data);
42+
Rcpp_PreciousRelease(token);
43+
token = Rcpp_PreciousPreserve(data);
4444
}
4545

4646
// calls the update method of CLASS
@@ -54,7 +54,7 @@ namespace Rcpp{
5454

5555
inline SEXP invalidate__(){
5656
SEXP out = data ;
57-
Rcpp_ReleaseObject(token);
57+
Rcpp_PreciousRelease(token);
5858
data = R_NilValue ;
5959
token = R_NilValue ;
6060
return out ;

inst/include/Rcpp/traits/named_object.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ template <> class named_object<SEXP> {
4141
public: // #nocov start
4242
named_object( const std::string& name_, const SEXP& o_):
4343
name(name_), object(o_), token(R_NilValue) {
44-
token = Rcpp_precious_preserve(object);
44+
token = Rcpp_PreciousPreserve(object);
4545
}
4646

4747
named_object( const named_object<SEXP>& other ) :
4848
name(other.name), object(other.object), token(other.token) {
49-
token = Rcpp_precious_preserve(object);
49+
token = Rcpp_PreciousPreserve(object);
5050
}
5151
~named_object() {
52-
Rcpp_precious_remove(token);
52+
Rcpp_PreciousRelease(token);
5353

5454
} // #nocov end
5555
const std::string& name;

inst/include/RcppCommon.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,31 @@ namespace Rcpp {
9191
template <typename T> class named_object;
9292
}
9393

94-
inline SEXP Rcpp_PreserveObject(SEXP object) {
94+
// begin deprecated interface not using precious list
95+
// use Rcpp_PreciousPreserve + Rcpp_PreciousRelease below it
96+
inline SEXP Rcpp_PreserveObject(SEXP x) {
97+
if (x != R_NilValue) R_PreserveObject(x);
98+
return x;
99+
}
100+
inline void Rcpp_ReleaseObject(SEXP x) {
101+
if (x != R_NilValue) R_ReleaseObject(x);
102+
}
103+
inline SEXP Rcpp_ReplaceObject(SEXP x, SEXP y) {
104+
// if we are setting to the same SEXP as we already have, do nothing
105+
if (x != y) {
106+
Rcpp_ReleaseObject(x);
107+
Rcpp_PreserveObject(y);
108+
}
109+
return y;
110+
}
111+
// end deprecated interface not using precious list
112+
113+
// new preferred interface using token-based precious list
114+
inline SEXP Rcpp_PreciousPreserve(SEXP object) {
95115
return Rcpp_precious_preserve(object);
96116
}
97117

98-
inline void Rcpp_ReleaseObject(SEXP token) {
118+
inline void Rcpp_PreciousRelease(SEXP token) {
99119
Rcpp_precious_remove(token);
100120
}
101121

0 commit comments

Comments
 (0)