From 6f320f32998b226f8fb53618e6cad3764b30e8df Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Wed, 6 Nov 2019 19:01:15 -0600 Subject: [PATCH] small updates incl hide away parts of #1003 if C++11 not available --- ChangeLog | 9 +++++++++ DESCRIPTION | 4 ++-- inst/NEWS.Rd | 4 +++- inst/include/Rcpp/XPtr.h | 24 +++++++++++++++++++++++- inst/unitTests/runit.XPTr.R | 12 ++++++++---- tests/doRUnit.R | 5 +++-- 6 files changed, 48 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index ce34522c7..4a12cffa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2019-11-06 Dirk Eddelbuettel + * DESCRIPTION (Version, Date): Roll minor version + + * inst/include/Rcpp/XPtr.h: Provided fallback for old constructor + when C++11 is not available (follow-up to #1003) + * inst/unitTests/runit.XPTr.R (test.XPtr): On Windows (as a proxy for + old compilers) do not test new feature + + * tests/doRUnit.R: Protect printing to /tmp from Windows use + * vignettes/rmd/Rcpp.bib: Updated * inst/bib/Rcpp.bib: Idem diff --git a/DESCRIPTION b/DESCRIPTION index 7f53fd857..447399124 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: Rcpp Title: Seamless R and C++ Integration -Version: 1.0.2.5 -Date: 2019-11-02 +Version: 1.0.2.6 +Date: 2019-11-06 Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou, Nathan Russell, Douglas Bates and John Chambers Maintainer: Dirk Eddelbuettel diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 3f5f00a2b..88747c43d 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -14,7 +14,7 @@ \item \code{XPtr} tags are now preserved in \code{as<>} (Stephen Wade in \ghpr{1003} fixing \ghit{986}) \item A few more temporary allocations are now protected from garbage - collection (Romain Francois in \ghpr{1010}). + collection (Romain Francois in \ghpr{1010}, and Dirk in \ghpr{1011}). } \item Changes in Rcpp Modules: \itemize{ @@ -36,6 +36,8 @@ have been added to README.md (Dirk). \item Vignettes are now included pre-made (Dirk in \ghpr{1005} addressing \ghit{1004})). + \item The Rcpp FAQ has two new entries on 'no modules / no rtti' and + exceptions across shared libraries (Dirk in \ghpr{1009}). } } } diff --git a/inst/include/Rcpp/XPtr.h b/inst/include/Rcpp/XPtr.h index 70f44b784..4578cc3f1 100644 --- a/inst/include/Rcpp/XPtr.h +++ b/inst/include/Rcpp/XPtr.h @@ -58,6 +58,8 @@ class XPtr : typedef StoragePolicy Storage; +#if defined(RCPP_USING_CXX11) + /** * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP) * @@ -75,7 +77,7 @@ class XPtr : * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP) * * @param xp external pointer to wrap - * @param tag tag to assign to external pointer + * @param tag tag to assign to external pointer * @param prot protected data to assign to external pointer */ explicit XPtr(SEXP x, SEXP tag, SEXP prot) : XPtr(x) { @@ -83,6 +85,26 @@ class XPtr : R_SetExternalPtrProtected(x, prot); }; +#else + + /** + * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP) + * + * @param xp external pointer to wrap + */ + explicit XPtr(SEXP x, SEXP tag = R_NilValue, SEXP prot = R_NilValue) { + if (TYPEOF(x) != EXTPTRSXP) { + const char* fmt = "Expecting an external pointer: [type=%s]."; + throw ::Rcpp::not_compatible(fmt, Rf_type2char(TYPEOF(x))); + } + + Storage::set__(x); + R_SetExternalPtrTag( x, tag); + R_SetExternalPtrProtected(x, prot); + }; + +#endif + /** * creates a new external pointer wrapping the dumb pointer p. * diff --git a/inst/unitTests/runit.XPTr.R b/inst/unitTests/runit.XPTr.R index 9c3c833bb..a2f01f715 100644 --- a/inst/unitTests/runit.XPTr.R +++ b/inst/unitTests/runit.XPTr.R @@ -20,19 +20,23 @@ .runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" +isWindows <- Sys.info()[["sysname"]] == "Windows" + if (.runThisTest) { .setUp <- Rcpp:::unitTestSetup("XPtr.cpp") - + test.XPtr <- function(){ xp <- xptr_1() checkEquals(typeof( xp ), "externalptr", msg = "checking external pointer creation" ) - + front <- xptr_2(xp) checkEquals( front, 1L, msg = "check usage of external pointer" ) - xptr_self_tag(xp) - checkEquals(xptr_has_self_tag(xp), T, msg = "check external pointer tag preserved") + if (!isWindows) { + xptr_self_tag(xp) + checkEquals(xptr_has_self_tag(xp), T, msg = "check external pointer tag preserved") + } checkTrue(xptr_release(xp), msg = "check release of external pointer") diff --git a/tests/doRUnit.R b/tests/doRUnit.R index ce7a58726..d1f00699c 100644 --- a/tests/doRUnit.R +++ b/tests/doRUnit.R @@ -60,10 +60,11 @@ if (requireNamespace("RUnit", quietly=TRUE) && Sys.setenv("RunAllRcppTests"="yes") } - tests <- runTestSuite(testSuite) # Run tests + tests <- runTestSuite(testSuite) # Run tests printTextProtocol(tests) # Print results - printTextProtocol(tests, file="/tmp/RcppTestLog.txt") + if (Sys.info()[["sysname"]] != "Windows") + printTextProtocol(tests, file="/tmp/RcppTestLog.txt") ## Return success or failure to R CMD CHECK if (getErrors(tests)$nFail > 0) stop("TEST FAILED!")