Skip to content

Commit

Permalink
Merge pull request #1082 from RcppCore/bugfix/string-preserve-fixes
Browse files Browse the repository at this point in the history
remove erroneous PreserveObject call in String::wrap
  • Loading branch information
eddelbuettel authored May 18, 2020
2 parents 95d0854 + cd70231 commit 98fc9b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2020-05-17 Kevin Ushey <kevinushey@gmail.com>

* inst/include/Rcpp/String.h: don't preserve returned SEXP in wrap
* inst/include/RcppCommon.h: simplify

2020-04-30 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll minor version
Expand Down
1 change: 0 additions & 1 deletion inst/include/Rcpp/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ namespace Rcpp {
RCPP_STRING_DEBUG("wrap<String>()");
Shield<SEXP> res(Rf_allocVector(STRSXP, 1));
SEXP data = object.get_sexp();
Rcpp_PreserveObject(data);
SET_STRING_ELT(res, 0, data);
return res;
}
Expand Down
19 changes: 5 additions & 14 deletions inst/include/RcppCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,13 @@ namespace Rcpp {
}

inline SEXP Rcpp_ReplaceObject(SEXP x, SEXP y) {
if (Rf_isNull(x)) {
Rcpp_PreserveObject(y);
} else if (Rf_isNull(y)) {
Rcpp_ReleaseObject(x); // #nocov
} else {
// if we are setting to the same SEXP as we already have, do nothing
if (x != y) {

// the previous SEXP was not NULL, so release it
Rcpp_ReleaseObject(x);

// the new SEXP is not NULL, so preserve it
Rcpp_PreserveObject(y);

}
// if we are setting to the same SEXP as we already have, do nothing
if (x != y) {
Rcpp_ReleaseObject(x);
Rcpp_PreserveObject(y);
}

return y;
}

Expand Down

0 comments on commit 98fc9b5

Please sign in to comment.