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 :
6363 *
6464 * @param xp external pointer to wrap
6565 */
66- explicit XPtr (SEXP x, SEXP tag = R_NilValue, SEXP prot = R_NilValue ) {
66+ explicit XPtr (SEXP x) {
6767 if (TYPEOF (x) != EXTPTRSXP) {
6868 const char * fmt = " Expecting an external pointer: [type=%s]." ;
6969 throw ::Rcpp::not_compatible (fmt, Rf_type2char (TYPEOF (x)));
7070 }
71-
7271 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) {
7382 R_SetExternalPtrTag ( x, tag);
7483 R_SetExternalPtrProtected (x, prot);
7584 };
Original file line number Diff line number Diff line change @@ -46,6 +46,17 @@ int xptr_2( XPtr< std::vector<int> > p){
4646 return p->front () ;
4747}
4848
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+
4960// [[Rcpp::export]]
5061bool xptr_release ( XPtr< std::vector<int > > p) {
5162 p.release ();
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ if (.runThisTest) {
3131 front <- xptr_2(xp )
3232 checkEquals( front , 1L , msg = " check usage of external pointer" )
3333
34+ xptr_self_tag(xp )
35+ checkEquals(xptr_has_self_tag(xp ), T , msg = " check external pointer tag preserved" )
36+
3437 checkTrue(xptr_release(xp ), msg = " check release of external pointer" )
3538
3639 checkTrue(xptr_access_released(xp ), msg = " check access of released external pointer" )
You can’t perform that action at this time.
0 commit comments