File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -63,13 +63,22 @@ class XPtr :
63
63
*
64
64
* @param xp external pointer to wrap
65
65
*/
66
- explicit XPtr (SEXP x, SEXP tag = R_NilValue, SEXP prot = R_NilValue ) {
66
+ explicit XPtr (SEXP x) {
67
67
if (TYPEOF (x) != EXTPTRSXP) {
68
68
const char * fmt = " Expecting an external pointer: [type=%s]." ;
69
69
throw ::Rcpp::not_compatible (fmt, Rf_type2char (TYPEOF (x)));
70
70
}
71
-
72
71
Storage::set__ (x);
72
+ };
73
+
74
+ /* *
75
+ * constructs a XPtr wrapping the external pointer (EXTPTRSXP SEXP)
76
+ *
77
+ * @param xp external pointer to wrap
78
+ * @param tag tag to assign to external pointer
79
+ * @param prot protected data to assign to external pointer
80
+ */
81
+ explicit XPtr (SEXP x, SEXP tag, SEXP prot) : XPtr (x) {
73
82
R_SetExternalPtrTag ( x, tag);
74
83
R_SetExternalPtrProtected (x, prot);
75
84
};
Original file line number Diff line number Diff line change @@ -46,6 +46,17 @@ int xptr_2( XPtr< std::vector<int> > p){
46
46
return p->front () ;
47
47
}
48
48
49
+ // [[Rcpp::export]]
50
+ void xptr_self_tag ( XPtr< std::vector<int > > p ){
51
+ XPtr< std::vector<int > > self_tag (wrap (p), wrap (p), R_NilValue) ;
52
+ }
53
+
54
+ // [[Rcpp::export]]
55
+ bool xptr_has_self_tag ( XPtr< std::vector<int > > p ){
56
+ return wrap (p) == R_ExternalPtrTag (p);
57
+ }
58
+
59
+
49
60
// [[Rcpp::export]]
50
61
bool xptr_release ( XPtr< std::vector<int > > p) {
51
62
p.release ();
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ if (.runThisTest) {
31
31
front <- xptr_2(xp )
32
32
checkEquals( front , 1L , msg = " check usage of external pointer" )
33
33
34
+ xptr_self_tag(xp )
35
+ checkEquals(xptr_has_self_tag(xp ), T , msg = " check external pointer tag preserved" )
36
+
34
37
checkTrue(xptr_release(xp ), msg = " check release of external pointer" )
35
38
36
39
checkTrue(xptr_access_released(xp ), msg = " check access of released external pointer" )
You can’t perform that action at this time.
0 commit comments