[C++-sig] smart ptr

Sean Ross-Ross srossross at gmail.com
Fri Jun 1 03:01:24 CEST 2007


I have a class that is similar to a smart_ptr, called RefCountPtr
and I have a c++ class constructor

	X::X( RefCountPtr< foo >& f ) : thisfoo(f) ;

When I pass a Python 'foo' object into this constructor, I want to  
wrap it in a c++  RefCountPtr class before passing it to the c++  
constructor.

I have written an from_python extration method to do this


     static void* extract_rcp(PyObject* o)
     {
         object boostobj = object(handle<>(borrowed( o )) );
         foo *counted = extract<foo*>( boostobj );
         RefCountPtr< foo > *counter = new RefCountPtr< foo > 
( counted , true );
         return counter;
     }

When I extract the 'foo' object, I create a new RefCountPtr to pass  
to the constructor, once the constructor finishes, I am left with a  
reference count of 2: One for the new'd object and one for the data  
member of the X class.


My question is, how can I get rid of the extra reference count? Is  
there a call policy that will do this for me?

~Sean



More information about the Cplusplus-sig mailing list