Skip to content

Commit cac2095

Browse files
authored
Merge pull request #1023 from stephematician/master
Small update to XPtr removing C++11 syntax following PR #1012
2 parents 8580d28 + 9e6b2e7 commit cac2095

File tree

3 files changed

+21
-37
lines changed

3 files changed

+21
-37
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-11-13 Stephen Wade <stephematician@gmail.com>
2+
3+
* inst/include/Rcpp/XPtr.h: Delete delegating constructor (follow-up #1012)
4+
* inst/unitTests/runit.XPTr.R (test.XPtr): Reinsert self-tag test on Windows
5+
16
2019-11-11 Dirk Eddelbuettel <edd@debian.org>
27

38
* inst/unitTests/runit.packageversion.R: New test

inst/include/Rcpp/XPtr.h

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,12 @@ class XPtr :
5858

5959
typedef StoragePolicy<XPtr> Storage;
6060

61-
#if defined(RCPP_USING_CXX11)
62-
6361
/**
6462
* constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
6563
*
6664
* @param xp external pointer to wrap
6765
*/
68-
explicit XPtr(SEXP x) {
69-
if (TYPEOF(x) != EXTPTRSXP) {
70-
const char* fmt = "Expecting an external pointer: [type=%s].";
71-
throw ::Rcpp::not_compatible(fmt, Rf_type2char(TYPEOF(x)));
72-
}
73-
Storage::set__(x);
74-
};
66+
explicit XPtr(SEXP x) { checked_set(x); };
7567

7668
/**
7769
* constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
@@ -80,31 +72,12 @@ class XPtr :
8072
* @param tag tag to assign to external pointer
8173
* @param prot protected data to assign to external pointer
8274
*/
83-
explicit XPtr(SEXP x, SEXP tag, SEXP prot) : XPtr(x) {
84-
R_SetExternalPtrTag( x, tag);
85-
R_SetExternalPtrProtected(x, prot);
86-
};
87-
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);
75+
explicit XPtr(SEXP x, SEXP tag, SEXP prot) {
76+
checked_set(x);
77+
R_SetExternalPtrTag(x, tag);
10378
R_SetExternalPtrProtected(x, prot);
10479
};
10580

106-
#endif
107-
10881
/**
10982
* creates a new external pointer wrapping the dumb pointer p.
11083
*
@@ -213,6 +186,16 @@ class XPtr :
213186
}
214187

215188
void update(SEXP) {}
189+
190+
private:
191+
inline void checked_set(SEXP x) {
192+
if (TYPEOF(x) != EXTPTRSXP) {
193+
const char* fmt = "Expecting an external pointer: [type=%s].";
194+
throw ::Rcpp::not_compatible(fmt, Rf_type2char(TYPEOF(x)));
195+
}
196+
Storage::set__(x);
197+
}
198+
216199
};
217200

218201
} // namespace Rcpp

inst/unitTests/runit.XPTr.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

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

23-
isWindows <- Sys.info()[["sysname"]] == "Windows"
24-
2523
if (.runThisTest) {
2624

2725
.setUp <- Rcpp:::unitTestSetup("XPtr.cpp")
@@ -33,10 +31,8 @@ if (.runThisTest) {
3331
front <- xptr_2(xp)
3432
checkEquals( front, 1L, msg = "check usage of external pointer" )
3533

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

4137
checkTrue(xptr_release(xp), msg = "check release of external pointer")
4238

0 commit comments

Comments
 (0)