From cd7023199bde96b5f3185704116f497deb094051 Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Sun, 17 May 2020 19:48:13 -0700 Subject: [PATCH] remove erroneous PreserveObject call in String::wrap --- ChangeLog | 5 +++++ inst/include/Rcpp/String.h | 1 - inst/include/RcppCommon.h | 19 +++++-------------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index aabaa4b7e..34140fd51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-05-17 Kevin Ushey + + * inst/include/Rcpp/String.h: don't preserve returned SEXP in wrap + * inst/include/RcppCommon.h: simplify + 2020-04-30 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll minor version diff --git a/inst/include/Rcpp/String.h b/inst/include/Rcpp/String.h index 4d8efe20b..5a1401ffa 100644 --- a/inst/include/Rcpp/String.h +++ b/inst/include/Rcpp/String.h @@ -532,7 +532,6 @@ namespace Rcpp { RCPP_STRING_DEBUG("wrap()"); Shield res(Rf_allocVector(STRSXP, 1)); SEXP data = object.get_sexp(); - Rcpp_PreserveObject(data); SET_STRING_ELT(res, 0, data); return res; } diff --git a/inst/include/RcppCommon.h b/inst/include/RcppCommon.h index f3e5bb243..41ecce70d 100644 --- a/inst/include/RcppCommon.h +++ b/inst/include/RcppCommon.h @@ -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; }