Skip to content

Commit c1960c3

Browse files
authored
Merge pull request #1012 from RcppCore/bugfix/xptr_ctor
small updates incl hide away parts of #1003 if C++11 not available
2 parents 62be047 + 6f320f3 commit c1960c3

File tree

6 files changed

+48
-10
lines changed

6 files changed

+48
-10
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
2019-11-06 Dirk Eddelbuettel <[email protected]>
22

3+
* DESCRIPTION (Version, Date): Roll minor version
4+
5+
* inst/include/Rcpp/XPtr.h: Provided fallback for old constructor
6+
when C++11 is not available (follow-up to #1003)
7+
* inst/unitTests/runit.XPTr.R (test.XPtr): On Windows (as a proxy for
8+
old compilers) do not test new feature
9+
10+
* tests/doRUnit.R: Protect printing to /tmp from Windows use
11+
312
* vignettes/rmd/Rcpp.bib: Updated
413
* inst/bib/Rcpp.bib: Idem
514

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.2.5
4-
Date: 2019-11-02
3+
Version: 1.0.2.6
4+
Date: 2019-11-06
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/NEWS.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
\item \code{XPtr} tags are now preserved in \code{as<>} (Stephen Wade
1515
in \ghpr{1003} fixing \ghit{986})
1616
\item A few more temporary allocations are now protected from garbage
17-
collection (Romain Francois in \ghpr{1010}).
17+
collection (Romain Francois in \ghpr{1010}, and Dirk in \ghpr{1011}).
1818
}
1919
\item Changes in Rcpp Modules:
2020
\itemize{
@@ -36,6 +36,8 @@
3636
have been added to README.md (Dirk).
3737
\item Vignettes are now included pre-made (Dirk in \ghpr{1005}
3838
addressing \ghit{1004})).
39+
\item The Rcpp FAQ has two new entries on 'no modules / no rtti' and
40+
exceptions across shared libraries (Dirk in \ghpr{1009}).
3941
}
4042
}
4143
}

inst/include/Rcpp/XPtr.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class XPtr :
5858

5959
typedef StoragePolicy<XPtr> Storage;
6060

61+
#if defined(RCPP_USING_CXX11)
62+
6163
/**
6264
* constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
6365
*
@@ -75,14 +77,34 @@ class XPtr :
7577
* constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
7678
*
7779
* @param xp external pointer to wrap
78-
* @param tag tag to assign to external pointer
80+
* @param tag tag to assign to external pointer
7981
* @param prot protected data to assign to external pointer
8082
*/
8183
explicit XPtr(SEXP x, SEXP tag, SEXP prot) : XPtr(x) {
8284
R_SetExternalPtrTag( x, tag);
8385
R_SetExternalPtrProtected(x, prot);
8486
};
8587

88+
#else
89+
90+
/**
91+
* constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
92+
*
93+
* @param xp external pointer to wrap
94+
*/
95+
explicit XPtr(SEXP x, SEXP tag = R_NilValue, SEXP prot = R_NilValue) {
96+
if (TYPEOF(x) != EXTPTRSXP) {
97+
const char* fmt = "Expecting an external pointer: [type=%s].";
98+
throw ::Rcpp::not_compatible(fmt, Rf_type2char(TYPEOF(x)));
99+
}
100+
101+
Storage::set__(x);
102+
R_SetExternalPtrTag( x, tag);
103+
R_SetExternalPtrProtected(x, prot);
104+
};
105+
106+
#endif
107+
86108
/**
87109
* creates a new external pointer wrapping the dumb pointer p.
88110
*

inst/unitTests/runit.XPTr.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@
2020

2121
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
2222

23+
isWindows <- Sys.info()[["sysname"]] == "Windows"
24+
2325
if (.runThisTest) {
2426

2527
.setUp <- Rcpp:::unitTestSetup("XPtr.cpp")
26-
28+
2729
test.XPtr <- function(){
2830
xp <- xptr_1()
2931
checkEquals(typeof( xp ), "externalptr", msg = "checking external pointer creation" )
30-
32+
3133
front <- xptr_2(xp)
3234
checkEquals( front, 1L, msg = "check usage of external pointer" )
3335

34-
xptr_self_tag(xp)
35-
checkEquals(xptr_has_self_tag(xp), T, msg = "check external pointer tag preserved")
36+
if (!isWindows) {
37+
xptr_self_tag(xp)
38+
checkEquals(xptr_has_self_tag(xp), T, msg = "check external pointer tag preserved")
39+
}
3640

3741
checkTrue(xptr_release(xp), msg = "check release of external pointer")
3842

tests/doRUnit.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ if (requireNamespace("RUnit", quietly=TRUE) &&
6060
Sys.setenv("RunAllRcppTests"="yes")
6161
}
6262

63-
tests <- runTestSuite(testSuite) # Run tests
63+
tests <- runTestSuite(testSuite) # Run tests
6464

6565
printTextProtocol(tests) # Print results
66-
printTextProtocol(tests, file="/tmp/RcppTestLog.txt")
66+
if (Sys.info()[["sysname"]] != "Windows")
67+
printTextProtocol(tests, file="/tmp/RcppTestLog.txt")
6768

6869
## Return success or failure to R CMD CHECK
6970
if (getErrors(tests)$nFail > 0) stop("TEST FAILED!")

0 commit comments

Comments
 (0)