Skip to content

Commit 98fc9b5

Browse files
authored
Merge pull request #1082 from RcppCore/bugfix/string-preserve-fixes
remove erroneous PreserveObject call in String::wrap
2 parents 95d0854 + cd70231 commit 98fc9b5

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-05-17 Kevin Ushey <[email protected]>
2+
3+
* inst/include/Rcpp/String.h: don't preserve returned SEXP in wrap
4+
* inst/include/RcppCommon.h: simplify
5+
16
2020-04-30 Dirk Eddelbuettel <[email protected]>
27

38
* DESCRIPTION (Version, Date): Roll minor version

inst/include/Rcpp/String.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ namespace Rcpp {
532532
RCPP_STRING_DEBUG("wrap<String>()");
533533
Shield<SEXP> res(Rf_allocVector(STRSXP, 1));
534534
SEXP data = object.get_sexp();
535-
Rcpp_PreserveObject(data);
536535
SET_STRING_ELT(res, 0, data);
537536
return res;
538537
}

inst/include/RcppCommon.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,13 @@ namespace Rcpp {
101101
}
102102

103103
inline SEXP Rcpp_ReplaceObject(SEXP x, SEXP y) {
104-
if (Rf_isNull(x)) {
105-
Rcpp_PreserveObject(y);
106-
} else if (Rf_isNull(y)) {
107-
Rcpp_ReleaseObject(x); // #nocov
108-
} else {
109-
// if we are setting to the same SEXP as we already have, do nothing
110-
if (x != y) {
111-
112-
// the previous SEXP was not NULL, so release it
113-
Rcpp_ReleaseObject(x);
114-
115-
// the new SEXP is not NULL, so preserve it
116-
Rcpp_PreserveObject(y);
117104

118-
}
105+
// if we are setting to the same SEXP as we already have, do nothing
106+
if (x != y) {
107+
Rcpp_ReleaseObject(x);
108+
Rcpp_PreserveObject(y);
119109
}
110+
120111
return y;
121112
}
122113

0 commit comments

Comments
 (0)