[Rcpp-devel] Pointer troubles
Steve Lianoglou
mailinglist.honeypot at gmail.com
Wed Aug 3 16:58:14 CEST 2011
Hi Romain (and all),
Just one question about a point you made ... from my previous postings
on the list, we now by know that I'm no c++ expert, so ... sorry if
this is a dumb question.
I use XPtr often in my current Rcpp endeavor to wrap an external c++
lib, and when you say:
> We have the Rcpp::XPtr template class that is parameterized by the class of
> the pointer, the XPtr object acts as a smart pointer, so can be passed down
> to whatever C++ function that needs a pointer.
I think I've run into peculiars in the library I'm wrapping that
suggests otherwise.
The library I'm wrapping has a macro defined that you pass points to
object into to handle some basic reference counting/gc it has
implemented.
Part of the macro checks to see if there are any other objects
"holding on to" the pointer to the object that was sent in, and if not
it sets the pointer to NULL. A brief approximation of this macro looks
like so:
UNREF(x) {
if (x) {
if ((x)->unref()==0) {
(x)=NULL;
}
}
}
The assignment of x to NULL trips up when I pass an XPtr down into
this function.
I've gotten around this by just not passing an XPtr down to this part
of the code, so it's no big deal, but is this the one example where
the XPtr can't be passed around another c++ library as ...
"promiscuously" (for lack of a better word) ... as we would hope?
Just thought I'd but that out there since this just popped up.
Thanks,
-steve
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the Rcpp-devel
mailing list